3131from mpas_analysis .shared .time_series import compute_moving_avg , \
3232 combine_time_series_with_ncrcat
3333
34+ from mpas_analysis .ocean .utility import add_standard_regions_and_subset
35+
3436
3537class PlotDepthIntegratedTimeSeriesSubtask (AnalysisTask ):
3638 """
@@ -157,7 +159,8 @@ def __init__(self, parentTask, regionName, inFileName, outFileLabel,
157159
158160 if subtaskName is None :
159161 suffix = regionName [0 ].upper () + regionName [1 :]
160- subtaskName = 'plotDepthIntegratedTimeSeries{}' .format (suffix )
162+ suffix = suffix .replace (' ' , '_' )
163+ subtaskName = f'plotDepthIntegratedTimeSeries{ suffix } '
161164
162165 # first, call the constructor from the base class (AnalysisTask)
163166 super (PlotDepthIntegratedTimeSeriesSubtask , self ).__init__ (
@@ -205,7 +208,7 @@ def setup_and_check(self):
205208 if self .controlConfig is not None :
206209 # we need to know what file to read from the control run so
207210 # an absolute path won't work
208- assert ( not os .path .isabs (self .inFileName ) )
211+ assert not os .path .isabs (self .inFileName )
209212
210213 baseDirectory = build_config_full_path (
211214 self .controlConfig , 'output' , 'timeSeriesSubdirectory' )
@@ -217,7 +220,7 @@ def setup_and_check(self):
217220 'runs' , 'preprocessedReferenceRunName' )
218221 if preprocessedReferenceRunName != 'None' :
219222
220- assert ( not os .path .isabs (self .inFileName ) )
223+ assert not os .path .isabs (self .inFileName )
221224
222225 baseDirectory = build_config_full_path (
223226 config , 'output' , 'timeSeriesSubdirectory' )
@@ -263,11 +266,6 @@ def run_task(self):
263266
264267 mainRunName = config .get ('runs' , 'mainRunName' )
265268
266- plotTitles = config .getexpression ('regions' , 'plotTitles' )
267- allRegionNames = config .getexpression ('regions' , 'regions' )
268- regionIndex = allRegionNames .index (self .regionName )
269- regionNameInTitle = plotTitles [regionIndex ]
270-
271269 startDate = config .get ('timeSeries' , 'startDate' )
272270 endDate = config .get ('timeSeries' , 'endDate' )
273271
@@ -279,7 +277,17 @@ def run_task(self):
279277 timeVariableNames = None ,
280278 startDate = startDate ,
281279 endDate = endDate )
282- ds = ds .isel (nOceanRegionsTmp = regionIndex )
280+ if 'regionNames' in ds .coords :
281+ # we added region names already
282+ ds = ds .set_xindex ('regionNames' )
283+ ds = ds .sel (regionNames = self .regionName )
284+ regionNameInTitle = ds .regionNames .values
285+ else :
286+ # we need to add region names and select the right region by short
287+ # name
288+ ds = add_standard_regions_and_subset (
289+ ds , config , regionShortNames = [self .regionName ])
290+ regionNameInTitle = ds .regionNames .values [0 ]
283291
284292 depths = ds .depth .values
285293
@@ -436,7 +444,17 @@ def run_task(self):
436444 timeVariableNames = None ,
437445 startDate = controlStartDate ,
438446 endDate = controlEndDate )
439- dsRef = dsRef .isel (nOceanRegionsTmp = regionIndex )
447+
448+ if 'regionNames' in dsRef .coords :
449+ # we added region names already
450+ dsRef = dsRef .set_xindex ('regionNames' )
451+ dsRef = dsRef .sel (regionNames = self .regionName )
452+ else :
453+ # we need to add region names and select the right region by
454+ # short name
455+ dsRef = add_standard_regions_and_subset (
456+ dsRef , self .controlConfig ,
457+ regionShortNames = [self .regionName ])
440458
441459 color = config .get ('timeSeries' , 'controlColor' )
442460
@@ -468,8 +486,9 @@ def run_task(self):
468486
469487 fig = timeseries_analysis_plot (
470488 config = config , dsvalues = timeSeries , calendar = calendar ,
471- title = title , xlabel = xLabel , ylabel = yLabel , movingAveragePoints = None ,
472- lineColors = lineColors , lineStyles = lineStyles , markers = lineMarkers ,
489+ title = title , xlabel = xLabel , ylabel = yLabel ,
490+ movingAveragePoints = None , lineColors = lineColors ,
491+ lineStyles = lineStyles , markers = lineMarkers ,
473492 lineWidths = lineWidths , legendText = legendText , maxPoints = maxPoints ,
474493 firstYearXTicks = firstYearXTicks , yearStrideXTicks = yearStrideXTicks )
475494
0 commit comments