From f3a220d83ea0cc01283b6b6a76d988f81f06dee2 Mon Sep 17 00:00:00 2001 From: ashjbarnes Date: Wed, 28 Aug 2024 14:00:43 -0600 Subject: [PATCH 1/2] included a min_depth parameter and overwite this in MOM_input --- regional_mom6/regional_mom6.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/regional_mom6/regional_mom6.py b/regional_mom6/regional_mom6.py index 55d6120b..e86a78d4 100644 --- a/regional_mom6/regional_mom6.py +++ b/regional_mom6/regional_mom6.py @@ -485,6 +485,7 @@ def __init__( self.repeat_year_forcing = repeat_year_forcing self.ocean_mask = None self.layout = None # This should be a tuple. Leaving in a dummy 'None' makes it easy to remind the user to provide a value later on. + self.min_depth = 0.0 # Minimum depth. Shallower water will be masked out. This value is overwritten when running "setup_bathymetry" method. if read_existing_grids: try: self.hgrid = xr.open_dataset(self.mom_input_dir / "hgrid.nc") @@ -1356,7 +1357,7 @@ def tidy_bathymetry( ## REMOVE INLAND LAKES min_depth = self.vgrid.zi[minimum_layers] - + self.min_depth = min_depth ocean_mask = bathymetry.copy(deep=True).depth.where( bathymetry.depth <= min_depth, 1 ) @@ -1698,7 +1699,7 @@ def setup_run_directory( print("Number of CPUs required: ", ncpus) - ## Modify the input namelists to give the correct layouts + ## Modify the MOM_layout file to have correct horizontal dimensions and CPU layout # TODO Re-implement with package that works for this file type? or at least tidy up code with open(self.mom_run_dir / "MOM_layout", "r") as file: lines = file.readlines() @@ -1716,10 +1717,21 @@ def setup_run_directory( if "NJGLOBAL" in lines[jj]: lines[jj] = f"NJGLOBAL = {self.hgrid.ny.shape[0]//2}\n" - with open(self.mom_run_dir / "MOM_layout", "w") as f: f.writelines(lines) + # Overwrite values pertaining to vertical structure in the MOM_input file + with open(self.mom_run_dir / "MOM_input", "r") as file: + lines = file.readlines() + for jj in range(len(lines)): + if "MINIMUM_DEPTH" in lines[jj]: + lines[jj] = f'MINIMUM_DEPTH = "{self.min_depth}"\n' + if "NK =" in lines[jj]: + lines[jj] = f'NK = {len(self.vgrid.zl.values)}\n' + with open(self.mom_run_dir / "MOM_input", "w") as f: + f.writelines(lines) + + ## If using payu to run the model, create a payu configuration file if not using_payu and os.path.exists(f"{self.mom_run_dir}/config.yaml"): os.remove(f"{self.mom_run_dir}/config.yaml") From 0523f1d595b3d2bb7fc8a250dfe8a168d02adcd1 Mon Sep 17 00:00:00 2001 From: ashjbarnes Date: Wed, 28 Aug 2024 14:02:04 -0600 Subject: [PATCH 2/2] black --- regional_mom6/regional_mom6.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/regional_mom6/regional_mom6.py b/regional_mom6/regional_mom6.py index e86a78d4..8cd57c0d 100644 --- a/regional_mom6/regional_mom6.py +++ b/regional_mom6/regional_mom6.py @@ -485,7 +485,7 @@ def __init__( self.repeat_year_forcing = repeat_year_forcing self.ocean_mask = None self.layout = None # This should be a tuple. Leaving in a dummy 'None' makes it easy to remind the user to provide a value later on. - self.min_depth = 0.0 # Minimum depth. Shallower water will be masked out. This value is overwritten when running "setup_bathymetry" method. + self.min_depth = 0.0 # Minimum depth. Shallower water will be masked out. This value is overwritten when running "setup_bathymetry" method. if read_existing_grids: try: self.hgrid = xr.open_dataset(self.mom_input_dir / "hgrid.nc") @@ -1727,11 +1727,10 @@ def setup_run_directory( if "MINIMUM_DEPTH" in lines[jj]: lines[jj] = f'MINIMUM_DEPTH = "{self.min_depth}"\n' if "NK =" in lines[jj]: - lines[jj] = f'NK = {len(self.vgrid.zl.values)}\n' + lines[jj] = f"NK = {len(self.vgrid.zl.values)}\n" with open(self.mom_run_dir / "MOM_input", "w") as f: f.writelines(lines) - ## If using payu to run the model, create a payu configuration file if not using_payu and os.path.exists(f"{self.mom_run_dir}/config.yaml"): os.remove(f"{self.mom_run_dir}/config.yaml")