Skip to content

Commit 909e6c9

Browse files
authored
Merge pull request #1097 from xylar/fix-custom-thermal-forcing
Fix custom climatology maps
2 parents a1a5653 + eeb6e95 commit 909e6c9

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed

mpas_analysis/default.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,7 @@ availableVariables = {
21922192
'mpas': ['timeMonthly_avg_activeTracers_temperature',
21932193
'timeMonthly_avg_activeTracers_salinity',
21942194
'timeMonthly_avg_density',
2195-
'timeMonthly_avg_activeTracers_layerThickness']},
2195+
'timeMonthly_avg_layerThickness']},
21962196
'zonalVelocity':
21972197
{'title': 'Zonal Velocity',
21982198
'units': r'm s$$^{-1}$$',
@@ -2202,7 +2202,7 @@ availableVariables = {
22022202
'units': r'm s$$^{-1}$$',
22032203
'mpas': ['timeMonthly_avg_velocityMeridional']},
22042204
'velocityMagnitude':
2205-
{'title': 'Zonal Velocity',
2205+
{'title': 'Velocity Magnitude',
22062206
'units': r'm s$$^{-1}$$',
22072207
'mpas': ['timeMonthly_avg_velocityZonal',
22082208
'timeMonthly_avg_velocityMeridional']},
@@ -2225,8 +2225,8 @@ availableVariables = {
22252225
'has_depth': False},
22262226
}
22272227

2228-
# a list of fields top plot for each transect. All supported fields are listed
2229-
# below
2228+
# a list of fields top plot for each depth slice. All supported fields are
2229+
# listed above
22302230
variables = []
22312231

22322232

mpas_analysis/ocean/climatology_map_custom.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# https://raw.githubusercontent.com/MPAS-Dev/MPAS-Analysis/main/LICENSE
1111

1212
import numpy as np
13+
import xarray as xr
1314
from mpas_tools.cime.constants import constants as cime_constants
1415

1516
from mpas_analysis.ocean.remap_depth_slices_subtask import (
@@ -173,7 +174,7 @@ def __init__(self, config, mpasClimatologyTask, controlConfig=None):
173174
subtaskName=subtaskName)
174175

175176
subtask.set_plot_info(
176-
outFileLabel=varName,
177+
outFileLabel=f'cust_{varName}',
177178
fieldNameInTitle=title,
178179
mpasFieldName=mpasVarName,
179180
refFieldName=mpasVarName,
@@ -269,14 +270,19 @@ def customize_masked_climatology(self, climatology, season):
269270
the modified climatology data set
270271
"""
271272

272-
# first, call the base class's version of this function so we extract
273-
# the desired slices.
274-
climatology = super().customize_masked_climatology(climatology,
275-
season)
273+
# first, compute the derived variables, which may rely on having the
274+
# full 3D variables available
275+
276276
derivedVars = []
277277
self._add_vel_mag(climatology, derivedVars)
278278
self._add_thermal_forcing(climatology, derivedVars)
279279

280+
# then, call the superclass's version of this function so we extract
281+
# the desired slices (but before renaming because it expects the
282+
# original MPAS variable names)
283+
climatology = super().customize_masked_climatology(climatology,
284+
season)
285+
# finally, rename the variables and add metadata
280286
for varName, variable in self.variables.items():
281287
if varName not in derivedVars:
282288
# rename variables from MPAS names to shorter names
@@ -295,10 +301,8 @@ def _add_vel_mag(self, climatology, derivedVars):
295301
"""
296302
Add the velocity magnitude to the climatology if requested
297303
"""
298-
variables = self.variables
299-
300-
varName = 'verlocityMagnitude'
301-
if varName not in variables:
304+
varName = 'velocityMagnitude'
305+
if varName not in self.variables:
302306
return
303307

304308
derivedVars.append(varName)
@@ -311,10 +315,8 @@ def _add_thermal_forcing(self, climatology, derivedVars):
311315
"""
312316
Add thermal forcing to the climatology if requested
313317
"""
314-
variables = self.variables
315-
316318
varName = 'thermalForcing'
317-
if varName not in variables:
319+
if varName not in self.variables:
318320
return
319321

320322
derivedVars.append(varName)
@@ -336,6 +338,12 @@ def _add_thermal_forcing(self, climatology, derivedVars):
336338
dp = cime_constants['SHR_CONST_G']*dens*thick
337339
press = dp.cumsum(dim='nVertLevels') - 0.5*dp
338340

341+
# add land ice pressure if available
342+
ds_restart = xr.open_dataset(self.restartFileName)
343+
ds_restart = ds_restart.isel(Time=0)
344+
if 'landIcePressure' in ds_restart:
345+
press += ds_restart.landIcePressure
346+
339347
tempFreeze = c0 + cs*salin + cp*press + cps*press*salin
340348

341349
climatology[varName] = temp - tempFreeze

mpas_analysis/ocean/remap_depth_slices_subtask.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ def customize_masked_climatology(self, climatology, season):
248248
interfaceIndices = self.dsSlice.interfaceIndices
249249
interfaceIndexMask = self.dsSlice.interfaceIndexMask
250250

251-
for variableName in self.variableList:
251+
# iterate over all variables since some new ones may have been
252+
# added by a subclass
253+
for variableName in climatology.data_vars:
252254
if 'nVertLevels' in climatology[variableName].dims:
253255
# mask only the values with the right vertical index
254256
da = climatology[variableName].where(

suite/main.cfg

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[climatologyMapCustom]
2+
## options related to plotting climatology maps of any field at various depths
3+
## (if they include a depth dimension) without observatons for comparison
4+
5+
# a list of fields top plot for each depth slice. All supported fields are
6+
# listed above
7+
variables = [
8+
'temperature',
9+
'salinity',
10+
'potentialDensity',
11+
'thermalForcing',
12+
'zonalVelocity',
13+
'meridionalVelocity',
14+
'velocityMagnitude',
15+
'vertVelocity',
16+
'vertDiff',
17+
'vertVisc',
18+
'mixedLayerDepth'
19+
]

suite/setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def main():
146146
[config_from_job,
147147
os.path.join('..', '..', 'suite', f'{args.run}.cfg')])
148148

149+
if args.run.startswith('main_py'):
150+
config_from_job = ' '.join(
151+
[config_from_job, os.path.join('..', '..', 'suite', 'main.cfg')])
152+
149153
if args.run not in ['main', 'ctrl']:
150154
try:
151155
os.makedirs(os.path.join(suite_path, args.run))

0 commit comments

Comments
 (0)