From acc78b61a5db5a78c544cbc2f6e76accbee3328d Mon Sep 17 00:00:00 2001 From: Steven Brus Date: Fri, 6 Sep 2024 16:15:03 -0500 Subject: [PATCH] Add standalone test for creating wave mesh from existing ocean mesh --- compass/ocean/tests/global_ocean/__init__.py | 3 ++- .../tests/global_ocean/wave_mesh/__init__.py | 8 +++++-- .../tests/global_ocean/wave_mesh/base_mesh.py | 24 ++++++++++++------- .../tests/global_ocean/wave_mesh/cull_mesh.py | 12 ++++++---- .../global_ocean/wave_mesh/scrip_file.py | 12 ++++++---- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/compass/ocean/tests/global_ocean/__init__.py b/compass/ocean/tests/global_ocean/__init__.py index 9c7389c0f..f07959f5f 100644 --- a/compass/ocean/tests/global_ocean/__init__.py +++ b/compass/ocean/tests/global_ocean/__init__.py @@ -63,7 +63,8 @@ def __init__(self, mpas_core): # A test case for making E3SM support files from an existing mesh self.add_test_case(FilesForE3SM(test_group=self)) - # Create waves mesh + # Test cases for creating waves mesh + self.add_test_case(WaveMesh(test_group=self)) self._add_tests(mesh_names=['Icos'], include_wave_mesh=True) def _add_tests(self, mesh_names, high_res_topography=True, diff --git a/compass/ocean/tests/global_ocean/wave_mesh/__init__.py b/compass/ocean/tests/global_ocean/wave_mesh/__init__.py index f75e67f7f..037e08b99 100644 --- a/compass/ocean/tests/global_ocean/wave_mesh/__init__.py +++ b/compass/ocean/tests/global_ocean/wave_mesh/__init__.py @@ -27,7 +27,7 @@ class WaveMesh(TestCase): Attributes ---------- """ - def __init__(self, test_group, ocean_mesh, ocean_init): + def __init__(self, test_group, ocean_mesh=None, ocean_init=None): """ Create test case for creating a global MPAS-Ocean mesh @@ -38,7 +38,11 @@ def __init__(self, test_group, ocean_mesh, ocean_init): """ name = 'wave_mesh' - subdir = f'{ocean_mesh.mesh_name}/{name}' + if ocean_mesh is not None: + subdir = f'{ocean_mesh.mesh_name}/{name}' + else: + subdir = name + super().__init__(test_group=test_group, name=name, subdir=subdir) self.package = 'compass.ocean.tests.global_ocean.wave_mesh' diff --git a/compass/ocean/tests/global_ocean/wave_mesh/base_mesh.py b/compass/ocean/tests/global_ocean/wave_mesh/base_mesh.py index 37c3a061b..b6d9ec76e 100644 --- a/compass/ocean/tests/global_ocean/wave_mesh/base_mesh.py +++ b/compass/ocean/tests/global_ocean/wave_mesh/base_mesh.py @@ -32,24 +32,32 @@ def setup(self): self.opts.init_file = 'init.msh' # Set links to base mesh - if self.config.has_option('wave_mesh', 'ocean_base_mesh'): - ocean_base_mesh_path = self.config.get('wave_mesh', - 'ocean_base_mesh') - else: + if self.ocean_base_mesh is not None: mesh_path = self.ocean_base_mesh.steps['base_mesh'].path ocean_base_mesh_path = f'{mesh_path}/base_mesh.nc' + else: + if self.config.has_option('wave_mesh', 'ocean_base_mesh'): + ocean_base_mesh_path = self.config.get('wave_mesh', + 'ocean_base_mesh') + else: + raise ValueError('ocean_base_mesh option required ' + 'in wave_mesh section in cfg file') self.add_input_file( filename='ocean_base_mesh.nc', work_dir_target=ocean_base_mesh_path) # Set links to culled mesh - if self.config.has_option('wave_mesh', 'ocean_culled_mesh'): - ocean_culled_mesh_path = self.config.get('wave_mesh', - 'ocean_culled_mesh') - else: + if self.ocean_culled_mesh is not None: mesh_path = self.ocean_culled_mesh.steps['initial_state'].path ocean_culled_mesh_path = f'{mesh_path}/initial_state.nc' + else: + if self.config.has_option('wave_mesh', 'ocean_culled_mesh'): + ocean_culled_mesh_path = self.config.get('wave_mesh', + 'ocean_culled_mesh') + else: + raise ValueError('ocean_culled_mesh option required ' + 'in wave_mesh section in cfg file') self.add_input_file( filename='ocean_culled_mesh.nc', diff --git a/compass/ocean/tests/global_ocean/wave_mesh/cull_mesh.py b/compass/ocean/tests/global_ocean/wave_mesh/cull_mesh.py index f048a22c2..4598be368 100644 --- a/compass/ocean/tests/global_ocean/wave_mesh/cull_mesh.py +++ b/compass/ocean/tests/global_ocean/wave_mesh/cull_mesh.py @@ -26,12 +26,16 @@ def setup(self): super().setup() - if self.config.has_option('wave_mesh', 'ocean_culled_mesh'): - culled_mesh_path = self.config.get('wave_mesh', - 'ocean_culled_mesh') - else: + if self.ocean_mesh is not None: mesh_path = self.ocean_mesh.steps['initial_state'].path culled_mesh_path = f'{mesh_path}/initial_state.nc' + else: + if self.config.has_option('wave_mesh', 'ocean_culled_mesh'): + culled_mesh_path = self.config.get('wave_mesh', + 'ocean_culled_mesh') + else: + raise ValueError('ocean_culled_mesh option required ' + 'in wave_mesh section in cfg file') self.add_input_file( filename='ocean_culled_mesh.nc', diff --git a/compass/ocean/tests/global_ocean/wave_mesh/scrip_file.py b/compass/ocean/tests/global_ocean/wave_mesh/scrip_file.py index 6c3a1e650..73e23f88f 100644 --- a/compass/ocean/tests/global_ocean/wave_mesh/scrip_file.py +++ b/compass/ocean/tests/global_ocean/wave_mesh/scrip_file.py @@ -27,12 +27,16 @@ def setup(self): super().setup() - if self.config.has_option('wave_mesh', 'ocean_culled_mesh'): - ocean_mesh_path = self.config.get('wave_mesh', - 'ocean_culled_mesh') - else: + if self.ocean_mesh is not None: mesh_path = self.ocean_mesh.steps['initial_state'].path ocean_mesh_path = f'{mesh_path}/initial_state.nc' + else: + if self.config.has_option('wave_mesh', 'ocean_culled_mesh'): + ocean_mesh_path = self.config.get('wave_mesh', + 'ocean_culled_mesh') + else: + raise ValueError('ocean_culled_mesh option required ' + 'in wave_mesh section in cfg file') self.add_input_file( filename='ocean_mesh.nc',