From fc473c960f8aa876268b9f8128cd8a6c1f3064b4 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Thu, 13 Apr 2023 15:56:53 +0200 Subject: [PATCH] Add remapping ice shelf melt to `files_for_e3sm` --- compass/ocean/tests/global_ocean/__init__.py | 26 +++--- .../data_ice_shelf_melt/namelist.forward | 2 +- .../global_ocean/files_for_e3sm/__init__.py | 16 +++- .../files_for_e3sm/remap_ice_shelf_melt.py | 87 +++++++++++++++++++ 4 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 compass/ocean/tests/global_ocean/files_for_e3sm/remap_ice_shelf_melt.py diff --git a/compass/ocean/tests/global_ocean/__init__.py b/compass/ocean/tests/global_ocean/__init__.py index 3d0d74f2a3..df6140604f 100644 --- a/compass/ocean/tests/global_ocean/__init__.py +++ b/compass/ocean/tests/global_ocean/__init__.py @@ -130,10 +130,12 @@ def _add_tests(self, mesh_names, DynamicAdjustment, remap_topography=True, time_integrator=time_integrator)) if mesh_test.with_ice_shelf_cavities: - self.add_test_case( - DataIceShelfMelt( - test_group=self, mesh=mesh_test, init=init_test, - time_integrator=time_integrator)) + data_melt_test = DataIceShelfMelt( + test_group=self, mesh=mesh_test, init=init_test, + time_integrator=time_integrator) + self.add_test_case(data_melt_test) + else: + data_melt_test = None dynamic_adjustment_test = DynamicAdjustment( test_group=self, mesh=mesh_test, init=init_test, @@ -143,7 +145,8 @@ def _add_tests(self, mesh_names, DynamicAdjustment, remap_topography=True, self.add_test_case( FilesForE3SM( test_group=self, mesh=mesh_test, init=init_test, - dynamic_adjustment=dynamic_adjustment_test)) + dynamic_adjustment=dynamic_adjustment_test, + data_ice_shelf_melt=data_melt_test)) if include_rk4: time_integrator = 'RK4' @@ -184,10 +187,12 @@ def _add_tests(self, mesh_names, DynamicAdjustment, remap_topography=True, time_integrator=time_integrator)) if mesh_test.with_ice_shelf_cavities: - self.add_test_case( - DataIceShelfMelt( - test_group=self, mesh=mesh_test, init=init_test, - time_integrator=time_integrator)) + data_melt_test = DataIceShelfMelt( + test_group=self, mesh=mesh_test, init=init_test, + time_integrator=time_integrator) + self.add_test_case(data_melt_test) + else: + data_melt_test = None dynamic_adjustment_test = DynamicAdjustment( test_group=self, mesh=mesh_test, init=init_test, @@ -197,7 +202,8 @@ def _add_tests(self, mesh_names, DynamicAdjustment, remap_topography=True, self.add_test_case( FilesForE3SM( test_group=self, mesh=mesh_test, init=init_test, - dynamic_adjustment=dynamic_adjustment_test)) + dynamic_adjustment=dynamic_adjustment_test, + data_ice_shelf_melt=data_melt_test)) if include_bgc: # BGC tests diff --git a/compass/ocean/tests/global_ocean/data_ice_shelf_melt/namelist.forward b/compass/ocean/tests/global_ocean/data_ice_shelf_melt/namelist.forward index b561a772d3..2734a1f178 100644 --- a/compass/ocean/tests/global_ocean/data_ice_shelf_melt/namelist.forward +++ b/compass/ocean/tests/global_ocean/data_ice_shelf_melt/namelist.forward @@ -1,2 +1,2 @@ config_check_ssh_consistency = .false. -config_land_ice_flux_mode = 'prescribed' +config_land_ice_flux_mode = 'data' diff --git a/compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py b/compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py index a2939ee37f..3fd0d80d80 100644 --- a/compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py +++ b/compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py @@ -19,6 +19,9 @@ from compass.ocean.tests.global_ocean.files_for_e3sm.ocean_mesh import ( # noqa: E501 OceanMesh, ) +from compass.ocean.tests.global_ocean.files_for_e3sm.remap_ice_shelf_melt import ( # noqa: E501 + RemapIceShelfMelt, +) from compass.ocean.tests.global_ocean.files_for_e3sm.scrip import Scrip from compass.ocean.tests.global_ocean.files_for_e3sm.seaice_graph_partition import ( # noqa: E501 SeaiceGraphPartition, @@ -50,9 +53,12 @@ class FilesForE3SM(TestCase): dynamic_adjustment : compass.ocean.tests.global_ocean.dynamic_adjustment.DynamicAdjustment The test case that performs dynamic adjustment to dissipate fast-moving waves from the initial condition + + data_ice_shelf_melt : compass.ocean.tests.global_ocean.data_ice_shelf_melt.DataIceShelfMelt + A test case for remapping observed melt rates to the MPAS grid """ # noqa: E501 def __init__(self, test_group, mesh=None, init=None, - dynamic_adjustment=None): + dynamic_adjustment=None, data_ice_shelf_melt=None): """ Create test case for creating a global MPAS-Ocean mesh @@ -70,6 +76,9 @@ def __init__(self, test_group, mesh=None, init=None, dynamic_adjustment : compass.ocean.tests.global_ocean.dynamic_adjustment.DynamicAdjustment, optional The test case that performs dynamic adjustment to dissipate fast-moving waves from the initial condition + + data_ice_shelf_melt : compass.ocean.tests.global_ocean.data_ice_shelf_melt.DataIceShelfMelt, optional + A test case for remapping observed melt rates to the MPAS grid """ # noqa: E501 name = 'files_for_e3sm' if dynamic_adjustment is not None: @@ -83,6 +92,7 @@ def __init__(self, test_group, mesh=None, init=None, self.mesh = mesh self.init = init self.dynamic_adjustment = dynamic_adjustment + self.data_ice_shelf_melt = data_ice_shelf_melt # add metadata if we're running this on an existing mesh add_metadata = (dynamic_adjustment is None) @@ -98,6 +108,10 @@ def __init__(self, test_group, mesh=None, init=None, self.add_step(DiagnosticMaps(test_case=self)) self.add_step(DiagnosticMasks(test_case=self)) + self.add_step(RemapIceShelfMelt( + test_case=self, + data_ice_shelf_melt=data_ice_shelf_melt)) + def configure(self): """ Modify the configuration options for this test case diff --git a/compass/ocean/tests/global_ocean/files_for_e3sm/remap_ice_shelf_melt.py b/compass/ocean/tests/global_ocean/files_for_e3sm/remap_ice_shelf_melt.py new file mode 100644 index 0000000000..aad43d70ba --- /dev/null +++ b/compass/ocean/tests/global_ocean/files_for_e3sm/remap_ice_shelf_melt.py @@ -0,0 +1,87 @@ +import os + +from compass.io import symlink +from compass.ocean.tests.global_ocean.data_ice_shelf_melt.remap_ice_shelf_melt import ( # noqa: E501 + remap_adusumilli, +) +from compass.ocean.tests.global_ocean.files_for_e3sm.files_for_e3sm_step import ( # noqa: E501 + FilesForE3SMStep, +) + + +class RemapIceShelfMelt(FilesForE3SMStep): + """ + A step for for remapping observed melt rates to the MPAS grid and staging + them in ``assembled_files`` + + Attributes + ---------- + data_ice_shelf_melt : compass.ocean.tests.global_ocean.data_ice_shelf_melt.DataIceShelfMelt + A test case where remapping has already occurred + """ # noqa: E501 + def __init__(self, test_case, data_ice_shelf_melt): + """ + Create a new step + + Parameters + ---------- + test_case : compass.TestCase + The test case this step belongs to + + data_ice_shelf_melt : compass.ocean.tests.global_ocean.data_ice_shelf_melt.DataIceShelfMelt + A test case where remapping has already occurred + """ # noqa: E501 + super().__init__(test_case, name='remap_ice_shelf_melt', ntasks=512, + min_tasks=1) + self.data_ice_shelf_melt = data_ice_shelf_melt + filename = 'prescribed_ismf_adusumilli2020.nc' + if data_ice_shelf_melt is None: + self.add_input_file( + filename='Adusumilli_2020_iceshelf_melt_rates_2010-2018_v0.h5', + target='Adusumilli_2020_iceshelf_melt_rates_2010-2018_v0.h5', + database='initial_condition_database', + url='http://library.ucsd.edu/dc/object/bb0448974g/_3_1.h5') + + self.add_output_file(filename=filename) + else: + melt_path = \ + data_ice_shelf_melt.steps['remap_ice_shelf_melt'].path + + self.add_input_file( + filename=filename, + work_dir_target=f'{melt_path}/{filename}') + + def run(self): + """ + Run this step of the test case + """ + super().run() + + data_ice_shelf_melt = self.data_ice_shelf_melt + + prefix = 'prescribed_ismf_adusumilli2020' + suffix = f'{self.mesh_short_name}.{self.creation_date}' + + remapped_filename = f'{prefix}.nc' + dest_filename = f'{prefix}.{suffix}.nc' + + if data_ice_shelf_melt is None: + logger = self.logger + config = self.config + ntasks = self.ntasks + in_filename = 'Adusumilli_2020_iceshelf_melt_rates_2010-2018_v0.h5' + + parallel_executable = config.get('parallel', 'parallel_executable') + + mesh_filename = 'initial_state.nc' + mesh_name = self.mesh_short_name + land_ice_mask_filename = 'initial_state.nc' + + remap_adusumilli(in_filename, mesh_filename, mesh_name, + land_ice_mask_filename, remapped_filename, + logger=logger, mpi_tasks=ntasks, + parallel_executable=parallel_executable) + + symlink( + os.path.abspath(remapped_filename), + f'{self.ocean_inputdata_dir}/{dest_filename}')