diff --git a/metplus/wrappers/ascii2nc_wrapper.py b/metplus/wrappers/ascii2nc_wrapper.py index fdb2a50b09..308a84ee5a 100755 --- a/metplus/wrappers/ascii2nc_wrapper.py +++ b/metplus/wrappers/ascii2nc_wrapper.py @@ -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', '') diff --git a/metplus/wrappers/command_builder.py b/metplus/wrappers/command_builder.py index c6c802ca9b..c1f3831224 100755 --- a/metplus/wrappers/command_builder.py +++ b/metplus/wrappers/command_builder.py @@ -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 diff --git a/metplus/wrappers/ensemble_stat_wrapper.py b/metplus/wrappers/ensemble_stat_wrapper.py index 61a1964caa..5a4677fab1 100755 --- a/metplus/wrappers/ensemble_stat_wrapper.py +++ b/metplus/wrappers/ensemble_stat_wrapper.py @@ -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'] = \ diff --git a/metplus/wrappers/grid_diag_wrapper.py b/metplus/wrappers/grid_diag_wrapper.py index 07f4058030..23eac19b6b 100755 --- a/metplus/wrappers/grid_diag_wrapper.py +++ b/metplus/wrappers/grid_diag_wrapper.py @@ -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( diff --git a/metplus/wrappers/grid_stat_wrapper.py b/metplus/wrappers/grid_stat_wrapper.py index 10995682cf..33ca143376 100755 --- a/metplus/wrappers/grid_stat_wrapper.py +++ b/metplus/wrappers/grid_stat_wrapper.py @@ -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'] = \ diff --git a/metplus/wrappers/mode_wrapper.py b/metplus/wrappers/mode_wrapper.py index 346434abf0..5b126d7455 100755 --- a/metplus/wrappers/mode_wrapper.py +++ b/metplus/wrappers/mode_wrapper.py @@ -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', '') diff --git a/metplus/wrappers/mtd_wrapper.py b/metplus/wrappers/mtd_wrapper.py index be8adea1ee..30807f592a 100755 --- a/metplus/wrappers/mtd_wrapper.py +++ b/metplus/wrappers/mtd_wrapper.py @@ -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') diff --git a/metplus/wrappers/pb2nc_wrapper.py b/metplus/wrappers/pb2nc_wrapper.py index c3c9f52853..8d656df648 100755 --- a/metplus/wrappers/pb2nc_wrapper.py +++ b/metplus/wrappers/pb2nc_wrapper.py @@ -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', diff --git a/metplus/wrappers/point_stat_wrapper.py b/metplus/wrappers/point_stat_wrapper.py index 0c26a268eb..1183bdcec1 100755 --- a/metplus/wrappers/point_stat_wrapper.py +++ b/metplus/wrappers/point_stat_wrapper.py @@ -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) @@ -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): diff --git a/metplus/wrappers/series_analysis_wrapper.py b/metplus/wrappers/series_analysis_wrapper.py index b05f055426..0367b7ad83 100755 --- a/metplus/wrappers/series_analysis_wrapper.py +++ b/metplus/wrappers/series_analysis_wrapper.py @@ -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', diff --git a/metplus/wrappers/stat_analysis_wrapper.py b/metplus/wrappers/stat_analysis_wrapper.py index e78d441bc6..0e6ad4f1e4 100755 --- a/metplus/wrappers/stat_analysis_wrapper.py +++ b/metplus/wrappers/stat_analysis_wrapper.py @@ -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', '') diff --git a/metplus/wrappers/tc_gen_wrapper.py b/metplus/wrappers/tc_gen_wrapper.py index 3a8b61cbf8..6876731bfd 100755 --- a/metplus/wrappers/tc_gen_wrapper.py +++ b/metplus/wrappers/tc_gen_wrapper.py @@ -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', '') diff --git a/metplus/wrappers/tc_pairs_wrapper.py b/metplus/wrappers/tc_pairs_wrapper.py index a82cea3ffc..208194c6fe 100755 --- a/metplus/wrappers/tc_pairs_wrapper.py +++ b/metplus/wrappers/tc_pairs_wrapper.py @@ -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', diff --git a/metplus/wrappers/tc_stat_wrapper.py b/metplus/wrappers/tc_stat_wrapper.py index f90574b761..366d98917f 100755 --- a/metplus/wrappers/tc_stat_wrapper.py +++ b/metplus/wrappers/tc_stat_wrapper.py @@ -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() diff --git a/metplus/wrappers/tcrmw_wrapper.py b/metplus/wrappers/tcrmw_wrapper.py index 5fcca91368..0db3f864c8 100755 --- a/metplus/wrappers/tcrmw_wrapper.py +++ b/metplus/wrappers/tcrmw_wrapper.py @@ -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',