Skip to content

Commit a519c6c

Browse files
authored
Merge pull request #932 from xylar/fix-mali-draft
Several fixes to global ocean meshes with MALI topography
2 parents b253579 + 367ed60 commit a519c6c

File tree

1 file changed

+48
-16
lines changed
  • compass/ocean/tests/global_ocean/mesh/remap_mali_topography

1 file changed

+48
-16
lines changed

compass/ocean/tests/global_ocean/mesh/remap_mali_topography/__init__.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@ def _remap_mali_topo(self):
132132
self._partition_scrip_file('mali.scrip.nc')
133133

134134
out_mesh_name = self.mesh_name
135-
out_descriptor = MpasCellMeshDescriptor(
136-
filename='base_mesh.nc',
137-
mesh_name=out_mesh_name)
138-
out_descriptor.format = 'NETCDF3_64BIT'
139-
out_descriptor.to_scrip('mpaso.scrip.nc')
140-
self._partition_scrip_file('mpaso.scrip.nc')
141135

142136
map_filename = \
143137
f'map_{in_mesh_name}_to_{out_mesh_name}_mbtraave.nc'
@@ -168,14 +162,16 @@ def _modify_mali_topo(self):
168162

169163
g = constants['SHR_CONST_G']
170164

171-
draft = - (ice_density / ocean_density) * thickness
165+
draft = - (ice_density / ocean_density) * thickness + sea_level
172166

173167
ice_mask = ds_mali.thickness > 0
174-
floating_mask = np.logical_and(
175-
ice_mask,
176-
ice_density / ocean_density * thickness <= sea_level - bed)
168+
floating_mask = np.logical_and(ice_mask, draft > bed)
177169
grounded_mask = np.logical_and(ice_mask, np.logical_not(floating_mask))
178170

171+
# draft is determined by the bed where the ice is grounded and by
172+
# flotation where the ice is not grounded (floating or no ice)
173+
draft = xr.where(grounded_mask, bed, draft)
174+
179175
if self.ocean_includes_grounded:
180176
ocean_mask = bed < sea_level
181177
else:
@@ -191,10 +187,10 @@ def _modify_mali_topo(self):
191187

192188
# we will remap conservatively
193189
ds_in = xr.Dataset()
194-
ds_in['bed_elevation'] = bed
195-
ds_in['landIceThkObserved'] = thickness
196-
ds_in['landIcePressureObserved'] = lithop
197-
ds_in['landIceDraftObserved'] = draft
190+
ds_in['bed_elevation'] = ocean_frac * bed
191+
ds_in['landIceThkObserved'] = ocean_frac * thickness
192+
ds_in['landIcePressureObserved'] = ocean_frac * lithop
193+
ds_in['landIceDraftObserved'] = ocean_frac * draft
198194
ds_in['landIceFrac'] = ice_frac
199195
ds_in['landIceGroundedFrac'] = grounded_frac
200196
ds_in['oceanFrac'] = ocean_frac
@@ -211,10 +207,11 @@ def _create_mali_to_mpaso_weights(self, map_filename):
211207
logger = self.logger
212208
logger.info('Create weights file')
213209

210+
# target h5m file was created in parent class
214211
args = [
215212
'mbtempest', '--type', '5',
216213
'--load', f'mali.scrip.p{self.ntasks}.h5m',
217-
'--load', f'mpaso.scrip.p{self.ntasks}.h5m',
214+
'--load', f'target.scrip.p{self.ntasks}.h5m',
218215
'--file', map_filename,
219216
'--weights', '--gnomonic',
220217
'--boxeps', '1e-9',
@@ -233,6 +230,9 @@ def _remap_mali_to_mpaso(self, map_filename):
233230
"""
234231
logger = self.logger
235232
logger.info('Remap to target')
233+
config = self.config
234+
section = config['remap_topography']
235+
renorm_threshold = section.getfloat('renorm_threshold')
236236

237237
args = [
238238
'ncremap',
@@ -252,6 +252,20 @@ def _remap_mali_to_mpaso(self, map_filename):
252252
var = np.minimum(var, 1.)
253253
ds_out[var_name] = var
254254

255+
# renormalize topography variables based on ocean fraction
256+
ocean_frac = ds_out['oceanFrac']
257+
ocean_mask = ocean_frac > renorm_threshold
258+
norm = xr.where(ocean_mask, 1.0 / ocean_frac, 0.0)
259+
for var_name in [
260+
'bed_elevation',
261+
'landIceThkObserved',
262+
'landIcePressureObserved',
263+
'landIceDraftObserved'
264+
]:
265+
attrs = ds_out[var_name].attrs
266+
ds_out[var_name] = ds_out[var_name] * norm
267+
ds_out[var_name].attrs = attrs
268+
255269
write_netcdf(ds_out, 'mali_topography_remapped.nc')
256270

257271
logger.info(' Done.')
@@ -275,7 +289,10 @@ def _combine_topo(self):
275289

276290
ds_out['landIceFloatingFracObserved'] = (
277291
ds_mali['landIceFrac'] -
278-
ds_mali['landIceGroundedFrac'])
292+
ds_mali['landIceGroundedFrac']
293+
)
294+
295+
ds_out['landIceGroundedFracObserved'] = ds_mali['landIceGroundedFrac']
279296

280297
for var in ['maliFrac']:
281298
mali_field = ds_mali[var]
@@ -289,12 +306,27 @@ def _combine_topo(self):
289306
alpha * ds_mali.bed_elevation +
290307
(1.0 - alpha) * ds_bedmachine.bed_elevation)
291308

309+
# our topography blending technique can lead to locations where the
310+
# ice draft is slightly below the bed elevation; we correct that here
311+
ds_out['landIceDraftObserved'] = xr.where(
312+
ds_out['landIceDraftObserved'] < ds_out['bed_elevation'],
313+
ds_out['bed_elevation'],
314+
ds_out['landIceDraftObserved'])
315+
292316
alpha = ds_out.maliFrac
293317
# NOTE: MALI's ocean fraction is already scaled by the MALI fraction
294318
ds_out['oceanFracObserved'] = (
295319
ds_mali.oceanFrac +
296320
(1.0 - alpha) * ds_bedmachine.oceanFracObserved)
297321

322+
# limit land ice floatation fraction to ocean fraction -- because of
323+
# machine-precision noise in the combined ocean fraciton,
324+
# land ice floating fraction can exceed ocean fraction by ~1e-15
325+
ds_out['landIceFloatingFracObserved'] = np.minimum(
326+
ds_out['landIceFloatingFracObserved'],
327+
ds_out['oceanFracObserved']
328+
)
329+
298330
ds_out['ssh'] = ds_out.landIceDraftObserved
299331

300332
write_netcdf(ds_out, 'topography_remapped.nc')

0 commit comments

Comments
 (0)