Skip to content

Commit 63282e6

Browse files
authored
Merge pull request #1109 from xylar/use-mpaso-mesh-file-not-restart
Switch from restart file to mesh file in all tasks
2 parents 7a0d49c + 5c77cac commit 63282e6

40 files changed

Lines changed: 227 additions & 228 deletions

docs/tutorials/dev_add_task.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ script into the ``customize_masked_climatology()`` function:
997997
"""
998998
logger = self.logger
999999
1000-
ds_mesh = xr.open_dataset(self.restartFileName)
1000+
ds_mesh = xr.open_dataset(self.meshFilename)
10011001
ds_mesh = ds_mesh[['cellsOnEdge', 'cellsOnVertex', 'nEdgesOnCell',
10021002
'edgesOnCell', 'verticesOnCell', 'verticesOnEdge',
10031003
'dcEdge', 'dvEdge']]
@@ -1313,7 +1313,7 @@ described in this tutorial:
13131313
"""
13141314
logger = self.logger
13151315
1316-
ds_mesh = xr.open_dataset(self.restartFileName)
1316+
ds_mesh = xr.open_dataset(self.meshFilename)
13171317
ds_mesh = ds_mesh[['cellsOnEdge', 'cellsOnVertex', 'nEdgesOnCell',
13181318
'edgesOnCell', 'verticesOnCell', 'verticesOnEdge',
13191319
'dcEdge', 'dvEdge']]

docs/tutorials/dev_understand_a_task.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ at that before we continue with ``customize_masked_climatology()``.
779779
Compute the OHC from the temperature and layer thicknesses in a given
780780
climatology data sets.
781781
"""
782-
ds_restart = xr.open_dataset(self.restartFileName)
783-
ds_restart = ds_restart.isel(Time=0)
782+
ds_mesh = xr.open_dataset(self.meshFilename)
783+
ds_mesh = ds_mesh.isel(Time=0)
784784
785785
# specific heat [J/(kg*degC)]
786786
cp = self.namelist.getfloat('config_specific_heat_sea_water')
@@ -789,18 +789,18 @@ at that before we continue with ``customize_masked_climatology()``.
789789
790790
units_scale_factor = 1e-9
791791
792-
n_vert_levels = ds_restart.sizes['nVertLevels']
792+
n_vert_levels = ds_mesh.sizes['nVertLevels']
793793
794-
z_mid = compute_zmid(ds_restart.bottomDepth, ds_restart.maxLevelCell-1,
795-
ds_restart.layerThickness)
794+
z_mid = compute_zmid(ds_mesh.bottomDepth, ds_mesh.maxLevelCell-1,
795+
ds_mesh.layerThickness)
796796
797797
vert_index = xr.DataArray.from_dict(
798798
{'dims': ('nVertLevels',), 'data': np.arange(n_vert_levels)})
799799
800800
temperature = climatology['timeMonthly_avg_activeTracers_temperature']
801801
layer_thickness = climatology['timeMonthly_avg_layerThickness']
802802
803-
masks = [vert_index < ds_restart.maxLevelCell,
803+
masks = [vert_index < ds_mesh.maxLevelCell,
804804
z_mid <= self.min_depth,
805805
z_mid >= self.max_depth]
806806
for mask in masks:
@@ -812,7 +812,7 @@ at that before we continue with ``customize_masked_climatology()``.
812812
return ohc
813813
814814
This function uses a combination of mesh information taken from an MPAS
815-
restart file (available from the ``self.restartFileName`` attribute inherited
815+
mesh file (available from the ``self.meshFilename`` attribute inherited
816816
from :py:class:`~mpas_analysis.shared.climatology.RemapMpasClimatologySubtask`),
817817
namelist options available from the ``self.namelist`` reader (inherited from
818818
:py:class:`~mpas_analysis.shared.AnalysisTask`), and ``temperature`` and
@@ -1160,8 +1160,8 @@ here is the full analysis task as described in this tutorial:
11601160
Compute the OHC from the temperature and layer thicknesses in a given
11611161
climatology data sets.
11621162
"""
1163-
ds_restart = xr.open_dataset(self.restartFileName)
1164-
ds_restart = ds_restart.isel(Time=0)
1163+
ds_mesh = xr.open_dataset(self.meshFilename)
1164+
ds_mesh = ds_mesh.isel(Time=0)
11651165
11661166
# specific heat [J/(kg*degC)]
11671167
cp = self.namelist.getfloat('config_specific_heat_sea_water')
@@ -1170,18 +1170,18 @@ here is the full analysis task as described in this tutorial:
11701170
11711171
units_scale_factor = 1e-9
11721172
1173-
n_vert_levels = ds_restart.sizes['nVertLevels']
1173+
n_vert_levels = ds_mesh.sizes['nVertLevels']
11741174
1175-
z_mid = compute_zmid(ds_restart.bottomDepth, ds_restart.maxLevelCell-1,
1176-
ds_restart.layerThickness)
1175+
z_mid = compute_zmid(ds_mesh.bottomDepth, ds_mesh.maxLevelCell-1,
1176+
ds_mesh.layerThickness)
11771177
11781178
vert_index = xr.DataArray.from_dict(
11791179
{'dims': ('nVertLevels',), 'data': np.arange(n_vert_levels)})
11801180
11811181
temperature = climatology['timeMonthly_avg_activeTracers_temperature']
11821182
layer_thickness = climatology['timeMonthly_avg_layerThickness']
11831183
1184-
masks = [vert_index < ds_restart.maxLevelCell,
1184+
masks = [vert_index < ds_mesh.maxLevelCell,
11851185
z_mid <= self.min_depth,
11861186
z_mid >= self.max_depth]
11871187
for mask in masks:

mpas_analysis/default.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,13 @@ lonLines = np.arange(-180., 181., 30.)
527527
generate = True
528528

529529

530+
[ocean]
531+
## options related to ocean analysis
532+
533+
# the name of the stream that points to the MPAS mesh file.
534+
meshStream = mesh
535+
536+
530537
[oceanObservations]
531538
## options related to ocean observations with which the results will be
532539
## compared
@@ -585,6 +592,14 @@ remappedClimSubdirectory = clim/obs/remapped
585592
baseDirectory = /dir/to/ocean/reference
586593

587594

595+
[seaIce]
596+
## options related to sea-ice analysis
597+
598+
# the name of the stream that points to the MPAS mesh file. The "mesh" stream
599+
# in MPAS-seaice points to a dummy file, so it is not useful for this purpose.
600+
meshStream = landIceMasks
601+
602+
588603
[seaIceObservations]
589604
## options related to sea ice observations with which the results will be
590605
## compared

mpas_analysis/ocean/climatology_map_antarctic_melt.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ def run_task(self):
333333
# -------
334334
# Xylar Asay-Davis
335335

336-
# first, load the land-ice mask from the restart file
337-
dsLandIceMask = xr.open_dataset(self.restartFileName)
336+
# first, load the land-ice mask from the mesh file
337+
dsLandIceMask = xr.open_dataset(self.meshFilename)
338338
dsLandIceMask = dsLandIceMask[['landIceMask']]
339339
dsLandIceMask = dsLandIceMask.isel(Time=0)
340340
self.landIceMask = dsLandIceMask.landIceMask > 0.
@@ -555,12 +555,11 @@ def run_task(self):
555555
cellMasks = \
556556
dsRegionMask.regionCellMasks.chunk({'nRegions': 10})
557557

558-
restartFileName = \
559-
self.runStreams.readpath('restart')[0]
558+
meshFilename = self.get_mesh_filename()
560559

561-
dsRestart = xr.open_dataset(restartFileName)
562-
landIceFraction = dsRestart.landIceFraction.isel(Time=0)
563-
areaCell = dsRestart.areaCell
560+
dsMesh = xr.open_dataset(meshFilename)
561+
landIceFraction = dsMesh.landIceFraction.isel(Time=0)
562+
areaCell = dsMesh.areaCell
564563

565564
# convert from kg/s to kg/yr
566565
totalMeltFlux = constants.sec_per_year * \

mpas_analysis/ocean/climatology_map_bsf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def customize_masked_climatology(self, climatology, season):
315315
logger = self.logger
316316
config = self.config
317317

318-
ds_mesh = xr.open_dataset(self.restartFileName)
318+
ds_mesh = xr.open_dataset(self.meshFilename)
319319
var_list = [
320320
'cellsOnEdge',
321321
'cellsOnVertex',
@@ -332,6 +332,10 @@ def customize_masked_climatology(self, climatology, season):
332332
'latVertex',
333333
'areaTriangle',
334334
]
335+
if 'minLevelCell' not in ds_mesh:
336+
# some older meshes don't have this one
337+
ds_mesh['minLevelCell'] = xr.ones_like(ds_mesh.maxLevelCell)
338+
335339
ds_mesh = ds_mesh[var_list].as_numpy()
336340

337341
masked_filename = self.get_masked_file_name(season)

mpas_analysis/ocean/climatology_map_custom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ def _add_thermal_forcing(self, climatology, derivedVars):
316316
press = dp.cumsum(dim='nVertLevels') - 0.5*dp
317317

318318
# add land ice pressure if available
319-
ds_restart = xr.open_dataset(self.restartFileName)
320-
ds_restart = ds_restart.isel(Time=0)
321-
if 'landIcePressure' in ds_restart:
322-
press += ds_restart.landIcePressure
319+
ds_mesh = xr.open_dataset(self.meshFilename)
320+
ds_mesh = ds_mesh.isel(Time=0)
321+
if 'landIcePressure' in ds_mesh:
322+
press += ds_mesh.landIcePressure
323323

324324
tempFreeze = c0 + cs*salin + cp*press + cps*press*salin
325325

mpas_analysis/ocean/climatology_map_ohc_anomaly.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ def _compute_ohc(self, climatology):
295295
Compute the OHC from the temperature and layer thicknesses in a given
296296
climatology data sets.
297297
"""
298-
ds_restart = xr.open_dataset(self.restartFileName)
299-
ds_restart = ds_restart.isel(Time=0)
298+
ds_mesh = xr.open_dataset(self.meshFilename)
299+
ds_mesh = ds_mesh.isel(Time=0)
300300

301301
# specific heat [J/(kg*degC)]
302302
cp = self.namelist.getfloat('config_specific_heat_sea_water')
@@ -305,18 +305,18 @@ def _compute_ohc(self, climatology):
305305

306306
units_scale_factor = 1e-9
307307

308-
n_vert_levels = ds_restart.sizes['nVertLevels']
308+
n_vert_levels = ds_mesh.sizes['nVertLevels']
309309

310-
z_mid = compute_zmid(ds_restart.bottomDepth, ds_restart.maxLevelCell-1,
311-
ds_restart.layerThickness)
310+
z_mid = compute_zmid(ds_mesh.bottomDepth, ds_mesh.maxLevelCell-1,
311+
ds_mesh.layerThickness)
312312

313313
vert_index = xr.DataArray.from_dict(
314314
{'dims': ('nVertLevels',), 'data': np.arange(n_vert_levels)})
315315

316316
temperature = climatology['timeMonthly_avg_activeTracers_temperature']
317317
layer_thickness = climatology['timeMonthly_avg_layerThickness']
318318

319-
masks = [vert_index < ds_restart.maxLevelCell,
319+
masks = [vert_index < ds_mesh.maxLevelCell,
320320
z_mid <= self.min_depth,
321321
z_mid >= self.max_depth]
322322
for mask in masks:

mpas_analysis/ocean/climatology_map_wind_stress_curl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def customize_masked_climatology(self, climatology, season):
174174
"""
175175
logger = self.logger
176176

177-
ds_mesh = xr.open_dataset(self.restartFileName)
177+
ds_mesh = xr.open_dataset(self.meshFilename)
178178
var_list = [
179179
'verticesOnEdge',
180180
'cellsOnVertex',

mpas_analysis/ocean/compute_transects_subtask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def run_task(self):
247247

248248
# first, get maxLevelCell and zMid, needed for masking
249249

250-
dsMesh = xr.open_dataset(self.restartFileName)
250+
dsMesh = xr.open_dataset(self.meshFilename)
251251
dsMesh = dsMesh.isel(Time=0)
252252

253253
self.maxLevelCell = dsMesh.maxLevelCell - 1

mpas_analysis/ocean/histogram.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ def run_task(self):
247247
ds_mask = ds_region_mask.isel(nRegions=region_index)
248248
cell_mask = ds_mask.regionCellMasks == 1
249249

250-
# Open the restart file, which contains unmasked weight variables
251-
restart_filename = self.runStreams.readpath('restart')[0]
252-
ds_restart = xarray.open_dataset(restart_filename)
253-
ds_restart = ds_restart.isel(Time=0)
250+
# Open the mesh file, which contains unmasked weight variables
251+
mesh_filename = self.get_mesh_filename()
252+
ds_mesh = xarray.open_dataset(mesh_filename)
253+
ds_mesh = ds_mesh.isel(Time=0)
254254

255255
# Save the cell mask only for the region in its own file, which may be
256256
# referenced by future analysis (i.e., as a control run)
@@ -263,13 +263,15 @@ def run_task(self):
263263
# Fetch the weight variables and mask them for each region
264264
for index, var in enumerate(self.variableList):
265265
weight_var_name = self.weightList[index]
266-
if weight_var_name in ds_restart.keys():
266+
if weight_var_name in ds_mesh.keys():
267267
var_name = f'timeMonthly_avg_{var}'
268268
ds_weights[f'{var_name}_weight'] = \
269-
ds_restart[weight_var_name].where(cell_mask, drop=True)
269+
ds_mesh[weight_var_name].where(cell_mask, drop=True)
270270
else:
271-
self.logger.warn(f'Weight variable {weight_var_name} is '
272-
f'not in the restart file, skipping')
271+
self.logger.warning(
272+
f'Weight variable {weight_var_name} is '
273+
f'not in the mesh file, skipping'
274+
)
273275

274276
weights_filename = \
275277
f'{base_directory}/{self.filePrefix}_{self.regionName}_weights.nc'

0 commit comments

Comments
 (0)