@@ -42,6 +42,9 @@ class ConservationTask(AnalysisTask):
4242 config : mpas_tools.config.MpasConfigParser
4343 Contains configuration options
4444
45+ controlConfig : mpas_tools.config.MpasConfigParser
46+ Contains configuration options for a control run, if provided
47+
4548 outputFile : str
4649 The path to the output file produced by this analysis
4750
@@ -63,12 +66,6 @@ class ConservationTask(AnalysisTask):
6366 mainRunName : str
6467 The name of the main run from the config file
6568
66- referenceRunName : str
67- The name of the reference run from the config file
68-
69- referenceInputDirectory : str
70- The directory of the reference run from the config file
71-
7269 plotTypes : list of str
7370 The plot types requested in the config file
7471
@@ -95,7 +92,7 @@ class ConservationTask(AnalysisTask):
9592 # -------
9693 # Carolyn Begeman
9794
98- def __init__ (self , config ):
95+ def __init__ (self , config , controlConfig ):
9996 """
10097 Construct the analysis task.
10198
@@ -114,6 +111,8 @@ def __init__(self, config):
114111 componentName = 'ocean' ,
115112 tags = ['timeSeries' , 'conservation' ])
116113
114+ self .controlConfig = controlConfig
115+
117116 def setup_and_check (self ):
118117 """
119118 Perform steps to set up the analysis and check for errors in the setup.
@@ -170,10 +169,6 @@ def setup_and_check(self):
170169 self .allVariables = list (ds .data_vars .keys ())
171170
172171 self .mainRunName = self .config .get ('runs' , 'mainRunName' )
173- self .referenceRunName = \
174- config .get ('runs' , 'preprocessedReferenceRunName' )
175- self .referenceInputDirectory = config .get ('oceanPreprocessedReference' ,
176- 'baseDirectory' )
177172
178173 self .plotTypes = self .config .getexpression ('timeSeriesConservation' , 'plotTypes' )
179174
@@ -341,28 +336,30 @@ def _make_plot(self, plot_type):
341336 startDate = f'{ self .startYear :04d} -01-01_00:00:00' ,
342337 endDate = f'{ self .endYear :04d} -01-01_00:00:00' )
343338
344- if self .referenceRunName != 'None' and self .referenceInputDirectory != 'None' :
345- inFilesPreprocessed = f'{ self .referenceInputDirectory } /timeseries/{ self .fullTaskName } .nc'
346- self .logger .info (' Load in conservation for a preprocessed reference '
347- f'run { inFilesPreprocessed } ...' )
348- ds_ref = open_mpas_dataset (fileName = inFilesPreprocessed ,
349- calendar = self .calendar ,
350- variableList = self .variableList [plot_type ],
351- timeVariableNames = 'xtime' )
352- yearEndPreprocessed = days_to_datetime (ds_ref .Time .max (),
353- calendar = self .calendar ).year
354- if self .startYear <= yearEndPreprocessed :
339+ if self .controlConfig is not None :
340+ baseDirectory = build_config_full_path (
341+ self .controlConfig , 'output' , 'timeSeriesSubdirectory' )
342+
343+ controlFileName = f'{ baseDirectory } /{ self .fullTaskName } .nc'
344+ self .logger .info (' Load in conservation for a control run '
345+ f'{ controlFileName } ...' )
346+ ds_ref = open_mpas_dataset (fileName = controlFileName ,
347+ calendar = self .calendar ,
348+ variableList = self .variableList [plot_type ],
349+ timeVariableNames = 'xtime' )
350+ controlEndYear = self .controlConfig .getint ('timeSeries' , 'endYear' )
351+ if self .startYear <= controlEndYear :
355352 timeStart = date_to_days (year = self .startYear , month = 1 , day = 1 ,
356353 calendar = self .calendar )
357354 timeEnd = date_to_days (year = self .endYear , month = 12 , day = 31 ,
358355 calendar = self .calendar )
359- ds_ref_slice = \
356+ ds_ref_slice = \
360357 ds_ref .sel (Time = slice (timeStart , timeEnd ))
361358 else :
362- self .logger .warning ('Preprocessed time series ends before the '
359+ self .logger .warning ('Control time series ends before the '
363360 'timeSeries startYear and will not be '
364361 'plotted.' )
365- self .referenceRunName = ' None'
362+ self .controlConfig = None
366363
367364 # make the plot
368365 self .logger .info (' Make conservation plots...' )
@@ -380,7 +377,7 @@ def _make_plot(self, plot_type):
380377 variable = self ._get_variable (ds , varname )
381378 fields .append (variable )
382379 legend_text = ''
383- if self .referenceRunName != ' None' :
380+ if self .controlConfig is not None :
384381 legend_text = self .mainRunName
385382 if len (self .masterVariableList [plot_type ]) > 1 :
386383 if len (legend_text ) > 0 :
@@ -389,10 +386,10 @@ def _make_plot(self, plot_type):
389386 legendText .append (legend_text )
390387 lineColors .append (config .get ('timeSeries' , 'mainColor' ))
391388 lineStyles .append (lineStylesBase [index ])
392- if self .referenceRunName != ' None' :
393- variable = self ._get_variable (ds , varname )
389+ if self .controlConfig is not None :
390+ variable = self ._get_variable (ds_ref , varname )
394391 fields .append (variable )
395- legend_text = self .referenceRunName
392+ legend_text = self .controlConfig . get ( 'runs' , 'mainRunName' )
396393 if len (self .masterVariableList [plot_type ]) > 1 :
397394 legend_text = f"{ legend_text } , { varname .replace ('accumulated' , '' ).replace ('Flux' , '' )} "
398395 legendText .append (legend_text )
0 commit comments