From 004a33526316c7fd54be631ae8a0133944bf20b2 Mon Sep 17 00:00:00 2001 From: Yi-Cheng Teng - NOAA GFDL <143743249+yichengt900@users.noreply.github.com> Date: Wed, 3 Apr 2024 16:27:20 -0400 Subject: [PATCH] fix angle rotation bug (#13) --- tools/boundary/boundary.py | 12 +++++++++--- tools/boundary/write_glorys_boundary.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/boundary/boundary.py b/tools/boundary/boundary.py index efc1b1eff..296d0c361 100644 --- a/tools/boundary/boundary.py +++ b/tools/boundary/boundary.py @@ -298,11 +298,17 @@ class Segment(): ny (int): Number of data points in the y direction. """ - def __init__(self, num, border, hgrid, in_degrees=True, output_dir='.', regrid_dir=None): + def __init__(self, num, border, hgrid, in_degrees=False, output_dir='.', regrid_dir=None): self.num = num self.border = border - self.hgrid = hgrid - if in_degrees: + # Need to make a copy of hgrid so that the original is not modified multiple times + # when creating multiple segments + self.hgrid = hgrid.copy(deep=True) + # Check if the angle_dx variable in ocean_hgrid has a 'units' attribute + angle_units = hgrid['angle_dx'].attrs.get('units', None) + # If the units attribute is degrees, or degrees were manually specified, convert to radians + if angle_units == 'degrees' or in_degrees: + print('Converting grid angle from degrees to radians') self.hgrid['angle_dx'] = np.radians(self.hgrid['angle_dx']) check_angle_range(self.hgrid['angle_dx']) self.segstr = f'segment_{self.num:03d}' diff --git a/tools/boundary/write_glorys_boundary.py b/tools/boundary/write_glorys_boundary.py index e9b5c6187..647c36fa0 100755 --- a/tools/boundary/write_glorys_boundary.py +++ b/tools/boundary/write_glorys_boundary.py @@ -100,7 +100,7 @@ def main(config_file): # Parse command-line arguments parser = argparse.ArgumentParser(description='Generate obc from Glorys') - parser.add_argument('--config', type=str, default=glorys_obc.yaml, + parser.add_argument('--config', type=str, default='glorys_obc.yaml', help='Specify the YAML configuration file name') args = parser.parse_args()