Skip to content

Commit

Permalink
per #931, added function to read MET config file and used default wra…
Browse files Browse the repository at this point in the history
…pped config file in parm/met_config if unset in METplus config, don't use default value for ASCII2NC and STATAnalysis since their config file is optional
  • Loading branch information
georgemccabe committed Jul 1, 2021
1 parent 0b4c66f commit c63fb4a
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 66 deletions.
8 changes: 5 additions & 3 deletions metplus/wrappers/ascii2nc_wrapper.py
Expand Up @@ -43,9 +43,11 @@ def create_c_dict(self):
'LOG_ASCII2NC_VERBOSITY',
c_dict['VERBOSITY'])
c_dict['ALLOW_MULTIPLE_FILES'] = True
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'ASCII2NC_CONFIG_FILE',
'')

# ASCII2NC config file is optional, so
# don't provide wrapped config file name as default value
c_dict['CONFIG_FILE'] = self.get_config_file()

c_dict['ASCII_FORMAT'] = self.config.getstr('config',
'ASCII2NC_INPUT_FORMAT',
'')
Expand Down
23 changes: 23 additions & 0 deletions metplus/wrappers/command_builder.py
Expand Up @@ -2283,3 +2283,26 @@ def get_met_config(self, **kwargs):
@returns METConfigInfo object
"""
return met_config(**kwargs)

def get_config_file(self, default_config_file=None):
"""! Get the MET config file path for the wrapper from the
METplusConfig object. If unset, use the default value if provided.
@param default_config_file (optional) filename of wrapped MET config
file found in parm/met_config to use if config file is not set
@returns path to wrapped config file or None if no default is provided
"""
config_name = f'{self.app_name.upper()}_CONFIG_FILE'
config_file = self.config.getraw('config', config_name, '')
if not config_file:
if not default_config_file:
return None

default_config_path = os.path.join(self.config.getdir('PARM_BASE'),
'met_config',
default_config_file)
self.logger.debug(f"{config_name} is not set. "
f"Using {default_config_path}")
config_file = default_config_path

return config_file
11 changes: 4 additions & 7 deletions metplus/wrappers/ensemble_stat_wrapper.py
Expand Up @@ -204,13 +204,10 @@ def create_c_dict(self):
c_dict['OBS_GRID_FILE_WINDOW_BEGIN'] = c_dict['OBS_FILE_WINDOW_BEGIN']
c_dict['OBS_GRID_FILE_WINDOW_END'] = c_dict['OBS_FILE_WINDOW_END']

# set the MET config file path and variables set
# in th config file via environment variables
c_dict['CONFIG_FILE'] = \
self.config.getraw('config', 'ENSEMBLE_STAT_CONFIG_FILE', '')

if not c_dict['CONFIG_FILE']:
self.log_error("Must set ENSEMBLE_STAT_CONFIG_FILE.")
# get the MET config file path or use default
c_dict['CONFIG_FILE'] = (
self.get_config_file('EnsembleStatConfig_wrapped')
)

# read by MET through environment variable, not set in MET config file
c_dict['MET_OBS_ERR_TABLE'] = \
Expand Down
7 changes: 3 additions & 4 deletions metplus/wrappers/grid_diag_wrapper.py
Expand Up @@ -48,10 +48,9 @@ def create_c_dict(self):
'LOG_GRID_DIAG_VERBOSITY',
c_dict['VERBOSITY'])
c_dict['ALLOW_MULTIPLE_FILES'] = True
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'GRID_DIAG_CONFIG_FILE')
if not c_dict['CONFIG_FILE']:
self.log_error('GRID_DIAG_CONFIG_FILE required to run.')

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('GridDiagConfig_wrapped')

c_dict['INPUT_DIR'] = self.config.getdir('GRID_DIAG_INPUT_DIR', '')
c_dict['INPUT_TEMPLATES'] = util.getlist(
Expand Down
6 changes: 4 additions & 2 deletions metplus/wrappers/grid_stat_wrapper.py
Expand Up @@ -104,8 +104,10 @@ def create_c_dict(self):
c_dict['VERBOSITY'] = self.config.getstr('config',
'LOG_GRID_STAT_VERBOSITY',
c_dict['VERBOSITY'])
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'GRID_STAT_CONFIG_FILE', '')

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('GridStatConfig_wrapped')

c_dict['OBS_INPUT_DIR'] = \
self.config.getdir('OBS_GRID_STAT_INPUT_DIR', '')
c_dict['OBS_INPUT_TEMPLATE'] = \
Expand Down
8 changes: 3 additions & 5 deletions metplus/wrappers/mode_wrapper.py
Expand Up @@ -116,11 +116,9 @@ def create_c_dict(self):
c_dict['VERBOSITY'] = self.config.getstr('config',
'LOG_MODE_VERBOSITY',
c_dict['VERBOSITY'])
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'MODE_CONFIG_FILE',
'')
if not c_dict['CONFIG_FILE']:
self.log_error('MODE_CONFIG_FILE must be set')

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('MODEConfig_wrapped')

c_dict['OBS_INPUT_DIR'] = \
self.config.getdir('OBS_MODE_INPUT_DIR', '')
Expand Down
7 changes: 4 additions & 3 deletions metplus/wrappers/mtd_wrapper.py
Expand Up @@ -62,9 +62,10 @@ def create_c_dict(self):
self.config.getraw('config',
'MTD_OUTPUT_TEMPLATE')
)
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'MTD_CONFIG_FILE',
'')

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('MTDConfig_wrapped')

# new method of reading/setting MET config values
self.set_met_config_int(self.env_var_dict, 'MTD_MIN_VOLUME',
'min_volume', 'METPLUS_MIN_VOLUME')
Expand Down
8 changes: 2 additions & 6 deletions metplus/wrappers/pb2nc_wrapper.py
Expand Up @@ -88,12 +88,8 @@ def create_c_dict(self):
'PB2NC_INPUT_DATATYPE', '')
)

# Configuration
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'PB2NC_CONFIG_FILE',
'')
if c_dict['CONFIG_FILE'] == '':
self.log_error('PB2NC_CONFIG_FILE is required')
# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('PB2NCConfig_wrapped')

self.set_met_config_list(self.env_var_dict,
'PB2NC_MESSAGE_TYPE',
Expand Down
9 changes: 2 additions & 7 deletions metplus/wrappers/point_stat_wrapper.py
Expand Up @@ -134,10 +134,8 @@ def create_c_dict(self):
# get climatology config variables
self.handle_climo_dict()

# Configuration
c_dict['CONFIG_FILE'] = (
self.config.getraw('config', 'POINT_STAT_CONFIG_FILE', '')
)
# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('PointStatConfig_wrapped')

self.handle_obs_window_variables(c_dict)

Expand Down Expand Up @@ -232,9 +230,6 @@ def create_c_dict(self):
if not c_dict['OUTPUT_DIR']:
self.log_error('Must set POINT_STAT_OUTPUT_DIR in config file')

if not c_dict['CONFIG_FILE']:
self.log_error("POINT_STAT_CONFIG_FILE must be set.")

return c_dict

def add_obs_valid_args(self, time_info):
Expand Down
6 changes: 2 additions & 4 deletions metplus/wrappers/series_analysis_wrapper.py
Expand Up @@ -221,12 +221,10 @@ def create_c_dict(self):
if not c_dict['OUTPUT_DIR']:
self.log_error("Must set SERIES_ANALYSIS_OUTPUT_DIR to run.")

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = (
self.config.getraw('config',
'SERIES_ANALYSIS_CONFIG_FILE')
self.get_config_file('SeriesAnalysisConfig_wrapped')
)
if not c_dict['CONFIG_FILE']:
self.log_error("SERIES_ANALYSIS_CONFIG_FILE must be set")

c_dict['BACKGROUND_MAP'] = (
self.config.getbool('config',
Expand Down
7 changes: 4 additions & 3 deletions metplus/wrappers/stat_analysis_wrapper.py
Expand Up @@ -154,9 +154,10 @@ def create_c_dict(self):
c_dict['VERBOSITY'])
)
c_dict['LOOP_ORDER'] = self.config.getstr('config', 'LOOP_ORDER')
c_dict['CONFIG_FILE'] = self.config.getstr('config',
'STAT_ANALYSIS_CONFIG_FILE',
'')

# STATAnalysis config file is optional, so
# don't provide wrapped config file name as default value
c_dict['CONFIG_FILE'] = self.get_config_file()

c_dict['OUTPUT_DIR'] = self.config.getdir('STAT_ANALYSIS_OUTPUT_DIR',
'')
Expand Down
7 changes: 3 additions & 4 deletions metplus/wrappers/tc_gen_wrapper.py
Expand Up @@ -105,10 +105,9 @@ def create_c_dict(self):
c_dict['VERBOSITY'])
)
c_dict['ALLOW_MULTIPLE_FILES'] = True
c_dict['CONFIG_FILE'] = (
self.config.getraw('config',
f'{app_name_upper}_CONFIG_FILE', '')
)

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('TCGenConfig_wrapped')

c_dict['GENESIS_INPUT_DIR'] = (
self.config.getdir(f'{app_name_upper}_GENESIS_INPUT_DIR', '')
Expand Down
9 changes: 3 additions & 6 deletions metplus/wrappers/tc_pairs_wrapper.py
Expand Up @@ -96,12 +96,9 @@ def create_c_dict(self):
c_dict['MISSING_VAL'] = (
self.config.getstr('config', 'TC_PAIRS_MISSING_VAL', '-9999')
)
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'TC_PAIRS_CONFIG_FILE',
'')
if not c_dict['CONFIG_FILE']:
self.log_error("TC_PAIRS_CONFIG_FILE is required to "
"run TCPairs wrapper")

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('TCPairsConfig_wrapped')

self.add_met_config(name='init_beg',
data_type='string',
Expand Down
12 changes: 2 additions & 10 deletions metplus/wrappers/tc_stat_wrapper.py
Expand Up @@ -124,16 +124,8 @@ def create_c_dict(self):
self.log_error('No job arguments defined. '
'Please set TC_STAT_JOB_ARGS')

c_dict['CONFIG_FILE'] = self.config.getstr('config',
'TC_STAT_CONFIG_FILE',
'')
if not c_dict['CONFIG_FILE']:
default_config = os.path.join(self.config.getdir('PARM_BASE'),
'met_config',
'TCStatConfig_wrapped')
self.logger.debug("TC_STAT_CONFIG_FILE not set. Using "
f"{default_config}")
c_dict['CONFIG_FILE'] = default_config
# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('TCStatConfig_wrapped')

self.handle_description()

Expand Down
5 changes: 3 additions & 2 deletions metplus/wrappers/tcrmw_wrapper.py
Expand Up @@ -60,8 +60,9 @@ def create_c_dict(self):
'LOG_TC_RMW_VERBOSITY',
c_dict['VERBOSITY'])
c_dict['ALLOW_MULTIPLE_FILES'] = True
c_dict['CONFIG_FILE'] = self.config.getraw('config',
'TC_RMW_CONFIG_FILE', '')

# get the MET config file path or use default
c_dict['CONFIG_FILE'] = self.get_config_file('TCRMWConfig_wrapped')

c_dict['INPUT_DIR'] = self.config.getdir('TC_RMW_INPUT_DIR', '')
c_dict['INPUT_TEMPLATE'] = self.config.getraw('filename_templates',
Expand Down

0 comments on commit c63fb4a

Please sign in to comment.