Skip to content

Commit

Permalink
Update tasks for standard region names
Browse files Browse the repository at this point in the history
  • Loading branch information
xylar committed Feb 22, 2025
1 parent 245c8da commit 027f2b4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 46 deletions.
24 changes: 12 additions & 12 deletions mpas_analysis/default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ endYear = 20

# list of region names (needs to be in the same order as region indices in
# time-series stats)
regions = ['arctic', 'equatorial', 'so', 'nino3', 'nino4', 'nino3.4', 'global']
# list of plot titles (needs to be in the same order as region indices in
# time-series stats)
plotTitles = ['Arctic', 'Equatorial (15S-15N)', 'Southern Ocean', 'Nino 3',
'Nino 4', 'Nino 3.4', 'Global Ocean']
regionShortNames = ['arctic', 'equatorial', 'so', 'nino3', 'nino4', 'nino3.4',
'global']
# list of full names (e.g. for plot titles) same order as regionShortNames
regionNames = ['Arctic', 'Equatorial (15S-15N)', 'Southern Ocean', 'Nino 3',
'Nino 4', 'Nino 3.4', 'Global Ocean']


[plot]
Expand Down Expand Up @@ -608,8 +608,8 @@ concentrationAltibergSH = Altiberg/Altiberg_1991-2017_20180308.nc
## options related to plotting time series of ocean heat content (OHC)
## anomalies from year 1

# list of regions to plot from the region list in [regions] below
regions = ['global']
# list of region shrot names to plot from the region list in [regions] above
regionShortNames = ['global']

# approximate depths (m) separating plots of the upper, middle and lower ocean
depths = [700, 2000]
Expand Down Expand Up @@ -672,8 +672,8 @@ movingAveragePoints = 12
[hovmollerTemperatureAnomaly]
## options related to plotting time series of potential temperature vs. depth

# list of regions to plot from the region list in [regions] below
regions = ['global']
# list of region short names to plot from the region list in [regions] above
regionShortNames = ['global']

# Number of points over which to compute moving average(e.g., for monthly
# output, movingAveragePoints=12 corresponds to a 12-month moving average
Expand Down Expand Up @@ -706,8 +706,8 @@ contourLevelsResult = np.arange(-5.0, 5.51, 0.5)
[hovmollerSalinityAnomaly]
## options related to plotting time series of salinity vs. depth

# list of regions to plot from the region list in [regions] below
regions = ['global']
# list of region short names to plot from the region list in [regions] above
regionShortNames = ['global']

# Number of points over which to compute moving average(e.g., for monthly
# output, movingAveragePoints=12 corresponds to a 12-month moving average
Expand Down Expand Up @@ -743,7 +743,7 @@ contourLevelsResult = np.arange(-2., 2.01, 0.2)
## options related to plotting time series of sea surface temperature (SST)

# list of regions to plot from the region list in [regions] below
regions = ['global']
regionShortNames = ['global']

# Number of points over which to compute moving average (e.g., for monthly
# output, movingAveragePoints=12 corresponds to a 12-month moving average
Expand Down
16 changes: 11 additions & 5 deletions mpas_analysis/ocean/index_nino34.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from mpas_analysis.shared import AnalysisTask
from mpas_analysis.shared.html import write_image_xml

from mpas_analysis.ocean.utility import add_standard_regions_and_subset


class IndexNino34(AnalysisTask):
"""
Expand Down Expand Up @@ -129,7 +131,7 @@ def setup_and_check(self):
regionToPlot = config.get('indexNino34', 'region')

if regionToPlot not in ['nino3.4', 'nino3', 'nino4']:
raise ValueError('Unexpectes El Nino Index region {}'.format(
raise ValueError('Unexpected El Nino Index region {}'.format(
regionToPlot))
ninoIndexNumber = regionToPlot[4:]

Expand Down Expand Up @@ -193,9 +195,7 @@ def run_task(self):

# regionIndex should correspond to NINO34 in surface weighted Average
# AM
regions = config.getexpression('regions', 'regions')
regionToPlot = config.get('indexNino34', 'region')
regionIndex = regions.index(regionToPlot)

# Load data:
ds = open_mpas_dataset(fileName=self.inputFile,
Expand All @@ -204,6 +204,9 @@ def run_task(self):
startDate=startDate,
endDate=endDate)

ds = add_standard_regions_and_subset(ds, config,
regionShortNames=[regionToPlot])

# Observations have been processed to the nino34Index prior to reading
dsObs = xr.open_dataset(dataPath, decode_cf=False, decode_times=False)
# add the days between 0001-01-01 and the refDate so we have a new
Expand All @@ -215,7 +218,7 @@ def run_task(self):
self.logger.info(' Compute El Nino {} Index...'.format(
ninoIndexNumber))
varName = self.variableList[0]
regionSST = ds[varName].isel(nOceanRegions=regionIndex)
regionSST = ds[varName]
nino34Main = self._compute_nino34_index(regionSST, calendar)

# Compute the observational index over the entire time range
Expand Down Expand Up @@ -262,7 +265,10 @@ def run_task(self):
calendar=calendar,
variableList=self.variableList)

regionSSTRef = dsRef[varName].isel(nOceanRegions=regionIndex)
dsRef = add_standard_regions_and_subset(
dsRef, self.controlConfig, regionShortNames=[regionToPlot])

regionSSTRef = dsRef[varName]
nino34Ref = self._compute_nino34_index(regionSSTRef, calendar)

nino34s = [nino34Subset, nino34Main[2:-3], nino34Ref[2:-3]]
Expand Down
9 changes: 4 additions & 5 deletions mpas_analysis/ocean/time_series_ohc_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
PlotDepthIntegratedTimeSeriesSubtask

from mpas_analysis.shared.constants import constants as mpas_constants
from mpas_analysis.ocean.utility import get_standard_region_names


class TimeSeriesOHCAnomaly(AnalysisTask):
Expand Down Expand Up @@ -63,7 +64,8 @@ def __init__(self, config, mpasTimeSeriesTask, controlConfig=None):
tags=['timeSeries', 'ohc', 'publicObs', 'anomaly'])

sectionName = 'timeSeriesOHCAnomaly'
regionNames = config.getexpression(sectionName, 'regions')
regionShortNames = config.getexpression(sectionName,
'regionShortNames')
movingAveragePoints = config.getint(sectionName, 'movingAveragePoints')

self.variableDict = {}
Expand All @@ -85,6 +87,7 @@ def __init__(self, config, mpasTimeSeriesTask, controlConfig=None):
alter_dataset=self._compute_ohc)
self.add_subtask(anomalyTask)

regionNames = get_standard_region_names(config, regionShortNames)
for regionName in regionNames:
caption = 'Trend of {} OHC Anomaly vs depth'.format(
regionName)
Expand Down Expand Up @@ -133,10 +136,6 @@ def _compute_ohc(self, ds):
"""
Compute the OHC time series.
"""

# regionNames = self.config.getexpression('regions', 'regions')
# ds['regionNames'] = ('nOceanRegionsTmp', regionNames)

# for convenience, rename the variables to simpler, shorter names
ds = ds.rename(self.variableDict)

Expand Down
10 changes: 7 additions & 3 deletions mpas_analysis/ocean/time_series_salinity_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from mpas_analysis.ocean.compute_anomaly_subtask import ComputeAnomalySubtask
from mpas_analysis.ocean.plot_hovmoller_subtask import PlotHovmollerSubtask

from mpas_analysis.ocean.utility import get_standard_region_names


class TimeSeriesSalinityAnomaly(AnalysisTask):
"""
Expand Down Expand Up @@ -50,7 +52,8 @@ def __init__(self, config, mpasTimeSeriesTask):
tags=['timeSeries', 'salinity', 'publicObs', 'anomaly'])

sectionName = 'hovmollerSalinityAnomaly'
regionNames = config.getexpression(sectionName, 'regions')
regionShortNames = config.getexpression(sectionName,
'regionShortNames')
movingAveragePoints = config.getint(sectionName, 'movingAveragePoints')

mpasFieldName = 'timeMonthly_avg_avgValueWithinOceanLayerRegion_' \
Expand All @@ -66,9 +69,10 @@ def __init__(self, config, mpasTimeSeriesTask):
movingAveragePoints=movingAveragePoints)
self.add_subtask(anomalyTask)

regionNames = get_standard_region_names(config, regionShortNames)

for regionName in regionNames:
caption = 'Trend of {} Salinity Anomaly vs depth'.format(
regionName)
caption = f'Trend of {regionName} Salinity Anomaly vs depth'
plotTask = PlotHovmollerSubtask(
parentTask=self,
regionName=regionName,
Expand Down
46 changes: 28 additions & 18 deletions mpas_analysis/ocean/time_series_sst.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
make_directories, check_path_exists
from mpas_analysis.shared.html import write_image_xml

from mpas_analysis.ocean.utility import (
add_standard_regions_and_subset,
get_standard_region_names
)


class TimeSeriesSST(AnalysisTask):
"""
Expand Down Expand Up @@ -109,13 +114,16 @@ def setup_and_check(self):
self.inputFile = self.mpasTimeSeriesTask.outputFile

mainRunName = config.get('runs', 'mainRunName')
regions = config.getexpression('timeSeriesSST', 'regions')
regionShortNames = config.getexpression('timeSeriesSST',
'regionShortNames')

self.xmlFileNames = []
self.filePrefixes = {}

regions = get_standard_region_names(config, regionShortNames)
for region in regions:
filePrefix = 'sst_{}_{}'.format(region, mainRunName)
regionSuffix = region.replace(' ', '_')
filePrefix = 'sst_{}_{}'.format(regionSuffix, mainRunName)
self.xmlFileNames.append('{}/{}.xml'.format(self.plotsDirectory,
filePrefix))
self.filePrefixes[region] = filePrefix
Expand Down Expand Up @@ -147,12 +155,8 @@ def run_task(self):
movingAveragePoints = config.getint('timeSeriesSST',
'movingAveragePoints')

regions = config.getexpression('regions', 'regions')
plotTitles = config.getexpression('regions', 'plotTitles')
regionsToPlot = config.getexpression('timeSeriesSST', 'regions')

regionIndicesToPlot = [regions.index(region) for region in
regionsToPlot]
regionShortNames = config.getexpression('timeSeriesSST',
'regionShortNames')

outputDirectory = build_config_full_path(config, 'output',
'timeseriesSubdirectory')
Expand All @@ -165,6 +169,9 @@ def run_task(self):
startDate=self.startDate,
endDate=self.endDate)

dsSST = add_standard_regions_and_subset(
dsSST, config, regionShortNames=regionShortNames)

yearStart = days_to_datetime(dsSST.Time.min(), calendar=calendar).year
yearEnd = days_to_datetime(dsSST.Time.max(), calendar=calendar).year
timeStart = date_to_days(year=yearStart, month=1, day=1,
Expand All @@ -191,6 +198,9 @@ def run_task(self):
variableList=self.variableList,
startDate=controlStartDate,
endDate=controlEndDate)
dsRefSST = add_standard_regions_and_subset(
dsRefSST, self.controlConfig,
regionShortNames=regionShortNames)
else:
dsRefSST = None

Expand Down Expand Up @@ -221,17 +231,16 @@ def run_task(self):
preprocessedReferenceRunName = 'None'

self.logger.info(' Make plots...')
for regionIndex in regionIndicesToPlot:
region = regions[regionIndex]

title = '{} SST'.format(plotTitles[regionIndex])
for regionName in dsSST.regionNames.values:
title = f'{regionName} SST'
xLabel = 'Time [years]'
yLabel = r'[$\degree$C]'

varName = self.variableList[0]
SST = dsSST[varName].isel(nOceanRegions=regionIndex)
dsSST = dsSST.set_xindex('regionNames')
SST = dsSST[varName].sel(regionNames=regionName)

filePrefix = self.filePrefixes[region]
filePrefix = self.filePrefixes[regionName]

outFileName = '{}/{}.png'.format(self.plotsDirectory, filePrefix)

Expand All @@ -242,7 +251,9 @@ def run_task(self):
legendText = [mainRunName]

if dsRefSST is not None:
refSST = dsRefSST[varName].isel(nOceanRegions=regionIndex)

dsRefSST = dsRefSST.set_xindex('regionNames')
refSST = dsRefSST[varName].sel(regionNames=regionName)
fields.append(refSST)
lineColors.append(config.get('timeSeries', 'controlColor'))
lineWidths.append(1.5)
Expand Down Expand Up @@ -279,16 +290,15 @@ def run_task(self):

savefig(outFileName, config)

caption = 'Running Mean of {} Sea Surface Temperature'.format(
region)
caption = f'Running Mean of {regionName} Sea Surface Temperature'
write_image_xml(
config=config,
filePrefix=filePrefix,
componentName='Ocean',
componentSubdirectory='ocean',
galleryGroup='Time Series',
groupLink='timeseries',
thumbnailDescription='{} SST'.format(region),
thumbnailDescription=f'{regionName} SST',
imageDescription=caption,
imageCaption=caption)

Expand Down
11 changes: 8 additions & 3 deletions mpas_analysis/ocean/time_series_temperature_anomaly.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from mpas_analysis.ocean.compute_anomaly_subtask import ComputeAnomalySubtask
from mpas_analysis.ocean.plot_hovmoller_subtask import PlotHovmollerSubtask

from mpas_analysis.ocean.utility import get_standard_region_names


class TimeSeriesTemperatureAnomaly(AnalysisTask):
"""
Expand Down Expand Up @@ -50,7 +52,8 @@ def __init__(self, config, mpasTimeSeriesTask):
tags=['timeSeries', 'temperature', 'publicObs', 'anomaly'])

sectionName = 'hovmollerTemperatureAnomaly'
regionNames = config.getexpression(sectionName, 'regions')
regionShortNames = config.getexpression(sectionName,
'regionShortNames')
movingAveragePoints = config.getint(sectionName, 'movingAveragePoints')

mpasFieldName = 'timeMonthly_avg_avgValueWithinOceanLayerRegion_' \
Expand All @@ -66,9 +69,11 @@ def __init__(self, config, mpasTimeSeriesTask):
movingAveragePoints=movingAveragePoints)
self.add_subtask(anomalyTask)

regionNames = get_standard_region_names(config, regionShortNames)

for regionName in regionNames:
caption = 'Trend of {} Potential Temperature Anomaly vs ' \
'Depth'.format(regionName)
caption = \
f'Trend of {regionName} Potential Temperature Anomaly vs Depth'
plotTask = PlotHovmollerSubtask(
parentTask=self,
regionName=regionName,
Expand Down

0 comments on commit 027f2b4

Please sign in to comment.