Skip to content

Commit fb568e9

Browse files
authored
Merge pull request #777 from xylar/reroute-dismf
Reroute missing fluxes in data ice-shelf melt fluxes (DISMF)
2 parents e32eab1 + 10ea52b commit fb568e9

File tree

8 files changed

+260
-98
lines changed

8 files changed

+260
-98
lines changed

compass/ocean/mesh/cull.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def setup(self):
125125
self.add_input_file(filename='topography.nc',
126126
work_dir_target=target)
127127
self.add_output_file('topography_culled.nc')
128+
self.add_output_file('map_culled_to_base.nc')
128129

129130
config = self.config
130131
self.cpus_per_task = config.getint('spherical_mesh',
@@ -267,6 +268,39 @@ def cull_mesh(with_cavities=False, with_critical_passages=False,
267268
convert_to_cdf5, latitude_threshold, sweep_count)
268269

269270

271+
def write_map_culled_to_base(base_mesh_filename, culled_mesh_filename,
272+
out_filename):
273+
ds_base = xr.open_dataset(base_mesh_filename)
274+
ncells_base = ds_base.sizes['nCells']
275+
lon_base = ds_base.lonCell.values
276+
lat_base = ds_base.latCell.values
277+
278+
ds_culled = xr.open_dataset(culled_mesh_filename)
279+
ncells_culled = ds_culled.sizes['nCells']
280+
lon_culled = ds_culled.lonCell.values
281+
lat_culled = ds_culled.latCell.values
282+
283+
# create a map from lat-lon pairs to base-mesh cell indices
284+
map_base = dict()
285+
for cell_index in range(ncells_base):
286+
lon = lon_base[cell_index]
287+
lat = lat_base[cell_index]
288+
map_base[(lon, lat)] = cell_index
289+
290+
# create a map from culled- to base-mesh cell indices
291+
map_culled_to_base = list()
292+
for cell_index in range(ncells_culled):
293+
lon = lon_culled[cell_index]
294+
lat = lat_culled[cell_index]
295+
# each (lon, lat) for a culled cell *must* be in the base mesh
296+
map_culled_to_base.append(map_base[(lon, lat)])
297+
298+
ds_map_culled_to_base = xr.Dataset()
299+
ds_map_culled_to_base['mapCulledToBase'] = (('nCells',),
300+
map_culled_to_base)
301+
write_netcdf(ds_map_culled_to_base, out_filename)
302+
303+
270304
def _cull_mesh_with_logging(logger, with_cavities, with_critical_passages,
271305
custom_critical_passages, custom_land_blockages,
272306
preserve_floodplain, use_progress_bar,
@@ -425,6 +459,9 @@ def _cull_mesh_with_logging(logger, with_cavities, with_critical_passages,
425459
check_call(args, logger=logger)
426460

427461
if has_remapped_topo:
462+
write_map_culled_to_base(base_mesh_filename='base_mesh.nc',
463+
culled_mesh_filename='culeed_mesh.nc',
464+
out_filename='map_culled_to_base.nc')
428465
_cull_topo()
429466

430467
if with_cavities:
@@ -471,30 +508,8 @@ def _cull_mesh_with_logging(logger, with_cavities, with_critical_passages,
471508

472509

473510
def _cull_topo():
474-
ds_base = xr.open_dataset('base_mesh.nc')
475-
ncells_base = ds_base.sizes['nCells']
476-
lon_base = ds_base.lonCell.values
477-
lat_base = ds_base.latCell.values
478-
479-
ds_culled = xr.open_dataset('culled_mesh.nc')
480-
ncells_culled = ds_culled.sizes['nCells']
481-
lon_culled = ds_culled.lonCell.values
482-
lat_culled = ds_culled.latCell.values
483-
484-
# create a map from lat-lon pairs to base-mesh cell indices
485-
map_base = dict()
486-
for cell_index in range(ncells_base):
487-
lon = lon_base[cell_index]
488-
lat = lat_base[cell_index]
489-
map_base[(lon, lat)] = cell_index
490-
491-
# create a map from culled- to base-mesh cell indices
492-
map_culled_to_base = list()
493-
for cell_index in range(ncells_culled):
494-
lon = lon_culled[cell_index]
495-
lat = lat_culled[cell_index]
496-
# each (lon, lat) for a culled cell *must* be in the base mesh
497-
map_culled_to_base.append(map_base[(lon, lat)])
511+
ds_map = xr.open_dataset('map_culled_to_base.nc')
512+
map_culled_to_base = ds_map.mapCulledToBase.values
498513

499514
ds_topo = xr.open_dataset('topography.nc')
500515
ds_topo = ds_topo.isel(nCells=map_culled_to_base)

compass/ocean/tests/global_ocean/files_for_e3sm/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ def configure(self):
154154
graph_filename = os.path.abspath(graph_filename)
155155
config.set('files_for_e3sm', 'graph_filename', graph_filename)
156156

157+
base_mesh_filename = os.path.join(
158+
self.base_work_dir, mesh.steps['base_mesh'].path,
159+
'base_mesh.nc')
160+
base_mesh_filename = os.path.abspath(base_mesh_filename)
161+
config.set('files_for_e3sm', 'base_mesh_filename',
162+
base_mesh_filename)
163+
157164
if init is not None:
158165
if mesh.with_ice_shelf_cavities:
159166
initial_state_filename = \

compass/ocean/tests/global_ocean/files_for_e3sm/files_for_e3sm_step.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,20 @@ def setup(self):
109109
"""
110110
setup input files based on config options
111111
"""
112+
config = self.config
112113
self.add_input_file(filename='README', target='../README')
113114

114-
initial_state_filename = self.config.get(
115-
'files_for_e3sm', 'ocean_initial_state_filename')
116-
if initial_state_filename != 'autodetect':
117-
initial_state_filename = os.path.normpath(os.path.join(
118-
self.test_case.work_dir, initial_state_filename))
119-
self.add_input_file(filename='initial_state.nc',
120-
target=initial_state_filename)
121-
122-
restart_filename = self.config.get('files_for_e3sm',
123-
'ocean_restart_filename')
124-
if restart_filename != 'autodetect':
125-
restart_filename = os.path.normpath(os.path.join(
126-
self.test_case.work_dir, restart_filename))
127-
self.add_input_file(filename='restart.nc', target=restart_filename)
128-
129-
with_ice_shelf_cavities = self.config.get('files_for_e3sm',
130-
'with_ice_shelf_cavities')
115+
for prefix in ['base_mesh', 'initial_state', 'restart']:
116+
filename = config.get('files_for_e3sm',
117+
f'ocean_{prefix}_filename')
118+
if filename != 'autodetect':
119+
filename = os.path.normpath(os.path.join(
120+
self.test_case.work_dir, filename))
121+
self.add_input_file(filename='base_mesh.nc',
122+
target=filename)
123+
124+
with_ice_shelf_cavities = config.get('files_for_e3sm',
125+
'with_ice_shelf_cavities')
131126
if with_ice_shelf_cavities != 'autodetect':
132127
self.with_ice_shelf_cavities = \
133128
(with_ice_shelf_cavities.lower() == 'true')
@@ -138,7 +133,7 @@ def run(self): # noqa: C901
138133
Run this step of the testcase
139134
"""
140135
config = self.config
141-
for prefix in ['initial_state', 'restart']:
136+
for prefix in ['base_mesh', 'initial_state', 'restart']:
142137
if not os.path.exists(f'{prefix}.nc'):
143138
filename = config.get('files_for_e3sm',
144139
f'ocean_{prefix}_filename')

compass/ocean/tests/global_ocean/files_for_e3sm/ocean_mesh.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,8 @@ def run(self):
120120

121121
symlink(os.path.abspath(dest_filename),
122122
f'{self.ocean_mesh_dir}/{dest_filename}')
123+
124+
dest_filename = f'{self.mesh_short_name}_base.{self.creation_date}.nc'
125+
126+
symlink(os.path.abspath('base_mesh.nc'),
127+
f'{self.ocean_mesh_dir}/{dest_filename}')

compass/ocean/tests/global_ocean/files_for_e3sm/remap_ice_shelf_melt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ def run(self):
8181

8282
parallel_executable = config.get('parallel', 'parallel_executable')
8383

84-
mesh_filename = 'initial_state.nc'
84+
base_mesh_filename = 'base_mesh.nc'
85+
culled_mesh_filename = 'initial_state.nc'
8586
mesh_name = self.mesh_short_name
8687
land_ice_mask_filename = 'initial_state.nc'
8788

88-
remap_adusumilli(in_filename, mesh_filename, mesh_name,
89+
remap_adusumilli(in_filename, base_mesh_filename,
90+
culled_mesh_filename, mesh_name,
8991
land_ice_mask_filename, remapped_filename,
9092
logger=logger, mpi_tasks=ntasks,
9193
parallel_executable=parallel_executable)

compass/ocean/tests/global_ocean/global_ocean.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ mesh_short_name = autodetect
181181
# directory of an ocean restart file on the given mesh
182182
ocean_restart_filename = autodetect
183183

184+
# the base mesh before culling for remapping and rerouting data ice-shelf melt
185+
# fluxes
186+
ocean_base_mesh_filename = autodetect
187+
184188
# the initial state used to extract the ocean and sea-ice meshes
185189
ocean_initial_state_filename = ${ocean_restart_filename}
186190

0 commit comments

Comments
 (0)