Skip to content

Commit

Permalink
per #2026, pass through init/valid/lead to string sub dictionary, if …
Browse files Browse the repository at this point in the history
…looping over init or valid times, set DATE_BEG/END to the run time so that fcst/obs_init/valid_beg/end are set using the YYYYMMDD of the run time (preserves previous behavior)
  • Loading branch information
georgemccabe committed Jan 26, 2023
1 parent 96e7f7b commit b3b9e27
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions metplus/wrappers/stat_analysis_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def create_c_dict(self):
# if start and end times are not equal and
# LOOP_ORDER = times (legacy), set frequency to once per init/valid
if (start_dt != end_dt and
self.config.has_option('LOOP_ORDER') and
self.config.has_option('config', 'LOOP_ORDER') and
self.config.getraw('config', 'LOOP_ORDER') == 'times'):
self.logger.warning('LOOP_ORDER has been deprecated. Please '
'set STAT_ANALYSIS_RUNTIME_FREQ instead')
Expand Down Expand Up @@ -224,6 +224,14 @@ def run_at_time_once(self, time_input):
@returns list of tuples containing all commands that were run and the
environment variables that were set for each
"""
# if init or valid time is set in the time input, set DATE_BEG and
# DATE_END to that time to set fcst/obs_init/valid_beg/end values
# if both init and valid are set, valid is used
for init_or_valid in ['init', 'valid']:
if time_input.get(init_or_valid, '*') != '*':
c_dict['DATE_BEG'] = time_input[init_or_valid]
c_dict['DATE_END'] = time_input[init_or_valid]

self._run_stat_analysis(time_input)
return self.all_commands

Expand Down Expand Up @@ -255,11 +263,8 @@ def _get_all_runtime_settings(self, time_input):
# Loop over run settings.
formatted_runtime_settings_dict_list = []
for runtime_settings in runtime_settings_dict_list:
# set custom, today, and now from time input
runtime_settings['custom'] = time_input.get('custom', '')
runtime_settings['today'] = time_input.get('today', '')
runtime_settings['now'] = time_input.get('now', '')

# add time input values to runtime settings
runtime_settings.update(time_input)
stringsub_dict = self._build_stringsub_dict(runtime_settings)

# Set up stat_analysis -lookin argument, model and obs information
Expand Down Expand Up @@ -574,11 +579,7 @@ def _build_stringsub_dict(self, config_dict):
"""
date_type = self.c_dict['DATE_TYPE']

stringsub_dict = {
'now': config_dict.get('now'),
'today': config_dict.get('today'),
'custom': config_dict.get('custom'),
}
stringsub_dict = {}

# add all loop list and group list items to string sub keys list
for list_item in self.EXPECTED_CONFIG_LISTS:
Expand All @@ -589,6 +590,12 @@ def _build_stringsub_dict(self, config_dict):
for special_key in self.STRING_SUB_SPECIAL_KEYS:
stringsub_dict[special_key] = ''

# set time info from current runtime
for item in ['now', 'today', 'custom', 'init', 'valid', 'lead']:
stringsub_dict[item] = config_dict.get(item, '')
if stringsub_dict[item] == '*':
stringsub_dict[item] = 'ALL'

# Set string sub info from fcst/obs hour lists
self._set_stringsub_hours(stringsub_dict,
config_dict.get(f'FCST_{date_type}_HOUR'),
Expand Down

0 comments on commit b3b9e27

Please sign in to comment.