Skip to content

Commit

Permalink
feature 931 default wrapped MET config file (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgemccabe authored Jul 29, 2021
1 parent e4c9d3c commit a254f5a
Show file tree
Hide file tree
Showing 28 changed files with 295 additions and 89 deletions.
22 changes: 17 additions & 5 deletions internal_tests/pytests/ascii2nc/test_ascii2nc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_ascii2nc_wrapper(metplus_config, config_overrides,
'use_cases/met_tool_wrapper/ASCII2NC/ASCII2NC.conf',
config_overrides)
)
assert(wrapper.isOK)
assert wrapper.isOK

input_path = wrapper.config.getraw('config', 'ASCII2NC_INPUT_TEMPLATE')
input_dir = os.path.dirname(input_path)
Expand All @@ -157,10 +157,10 @@ def test_ascii2nc_wrapper(metplus_config, config_overrides,
config_file = wrapper.c_dict.get('CONFIG_FILE')

expected_cmd = (f"{app_path} "
f"{input_dir}/{input_file} "
f"{output_dir}/{output_file} "
f"-config {config_file} "
f"{verbosity}")
f"{input_dir}/{input_file} "
f"{output_dir}/{output_file} "
f"-config {config_file} "
f"{verbosity}")

assert(all_commands[0][0] == expected_cmd)

Expand All @@ -172,3 +172,15 @@ def test_ascii2nc_wrapper(metplus_config, config_overrides,
value = match.split('=', 1)[1]

assert (env_var_values.get(env_var_key, '') == value)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'
config = metplus_config()
config.set('config', 'INPUT_MUST_EXIST', False)

wrapper = ASCII2NCWrapper(config)
assert not wrapper.c_dict['CONFIG_FILE']

config.set('config', 'ASCII2NC_CONFIG_FILE', fake_config_name)
wrapper = ASCII2NCWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
19 changes: 17 additions & 2 deletions internal_tests/pytests/ensemble_stat/test_ensemble_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_handle_climo_file_variables(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = EnsembleStatWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

all_cmds = wrapper.run_all_times()
for (_, actual_env_vars), run_time in zip(all_cmds, run_times):
Expand Down Expand Up @@ -499,7 +499,7 @@ def test_ensemble_stat_single_field(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = EnsembleStatWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -537,3 +537,18 @@ def test_ensemble_stat_single_field(metplus_config, config_overrides,
assert (actual_value == ens_fmt)
else:
assert(env_var_values.get(env_var_key, '') == actual_value)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'EnsembleStatConfig_wrapped')

wrapper = EnsembleStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'ENSEMBLE_STAT_CONFIG_FILE', fake_config_name)
wrapper = EnsembleStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
15 changes: 15 additions & 0 deletions internal_tests/pytests/grid_diag/test_grid_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,18 @@ def test_get_all_files_and_subset(metplus_config, time_info, expected_subset):
def test_get_list_file_name(metplus_config, time_info, expected_filename):
wrapper = GridDiagWrapper(metplus_config())
assert(wrapper.get_list_file_name(time_info, 'input0') == expected_filename)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'GridDiagConfig_wrapped')

wrapper = GridDiagWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'GRID_DIAG_CONFIG_FILE', fake_config_name)
wrapper = GridDiagWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
19 changes: 17 additions & 2 deletions internal_tests/pytests/grid_stat/test_grid_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_handle_climo_file_variables(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = GridStatWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

all_cmds = wrapper.run_all_times()
for (_, actual_env_vars), run_time in zip(all_cmds, run_times):
Expand Down Expand Up @@ -553,7 +553,7 @@ def test_grid_stat_single_field(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = GridStatWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -589,3 +589,18 @@ def test_grid_stat_single_field(metplus_config, config_overrides,
assert (actual_value == obs_fmt)
else:
assert(env_var_values.get(env_var_key, '') == actual_value)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'GridStatConfig_wrapped')

wrapper = GridStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'GRID_STAT_CONFIG_FILE', fake_config_name)
wrapper = GridStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
19 changes: 17 additions & 2 deletions internal_tests/pytests/mode/test_mode_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_mode_single_field(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = MODEWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -433,8 +433,23 @@ def test_config_synonyms(metplus_config, config_name, env_var_name,
set_minimum_config_settings(config)
config.set('config', config_name, in_value)
wrapper = MODEWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK


expected_output = f'{met_name} = {out_value};'
assert(wrapper.env_var_dict[env_var_name] == expected_output)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'MODEConfig_wrapped')

wrapper = MODEWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'MODE_CONFIG_FILE', fake_config_name)
wrapper = MODEWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
17 changes: 16 additions & 1 deletion internal_tests/pytests/mtd/test_mtd_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_mtd_single(metplus_config):
mw.c_dict['SINGLE_DATA_SRC'] = 'FCST'
mw.c_dict['FCST_INPUT_DIR'] = fcst_dir
mw.c_dict['FCST_INPUT_TEMPLATE'] = "{init?fmt=%Y%m%d}/{init?fmt=%Y%m%d}_i{init?fmt=%H}_f{lead?fmt=%.3H}_HRRRTLE_PHPT.grb2"
input_dict = {'init' : datetime.datetime.strptime("201705100300", '%Y%m%d%H%M') }
input_dict = {'init': datetime.datetime.strptime("201705100300", '%Y%m%d%H%M') }

mw.run_at_time(input_dict)
single_list_file = os.path.join(mw.config.getdir('STAGING_DIR'), 'file_lists', '20170510040000_mtd_single_APCP.txt')
Expand All @@ -203,3 +203,18 @@ def test_mtd_single(metplus_config):
single_list[1] == os.path.join(fcst_dir,'20170510', '20170510_i03_f002_HRRRTLE_PHPT.grb2') and
single_list[2] == os.path.join(fcst_dir,'20170510', '20170510_i03_f003_HRRRTLE_PHPT.grb2')
)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'MTDConfig_wrapped')

wrapper = MTDWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'MTD_CONFIG_FILE', fake_config_name)
wrapper = MTDWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
17 changes: 16 additions & 1 deletion internal_tests/pytests/pb2nc/test_pb2nc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_pb2nc_all_fields(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = PB2NCWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -347,3 +347,18 @@ def test_pb2nc_all_fields(metplus_config, config_overrides,
assert(match is not None)
value = match.split('=', 1)[1]
assert(env_var_values.get(env_var_key, '') == value)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'PB2NCConfig_wrapped')

wrapper = PB2NCWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'PB2NC_CONFIG_FILE', fake_config_name)
wrapper = PB2NCWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
19 changes: 17 additions & 2 deletions internal_tests/pytests/point_stat/test_point_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_met_dictionary_in_var_options(metplus_config):
'interp = { type = [ { method = NEAREST; width = 1; } ] };')

wrapper = PointStatWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

all_cmds = wrapper.run_all_times()

Expand Down Expand Up @@ -469,7 +469,7 @@ def test_point_stat_all_fields(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = PointStatWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -507,3 +507,18 @@ def test_point_stat_all_fields(metplus_config, config_overrides,
assert (value == obs_fmt)
else:
assert(env_var_values.get(env_var_key, '') == value)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'PointStatConfig_wrapped')

wrapper = PointStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'POINT_STAT_CONFIG_FILE', fake_config_name)
wrapper = PointStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
17 changes: 16 additions & 1 deletion internal_tests/pytests/series_analysis/test_series_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_series_analysis_single_field(metplus_config, config_overrides,
config.set('config', key, value)

wrapper = SeriesAnalysisWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -801,3 +801,18 @@ def test_get_netcdf_min_max(metplus_config):
min, max = wrapper.get_netcdf_min_max(filepath, variable_name)
assert(min == expected_min)
assert(max == expected_max)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'SeriesAnalysisConfig_wrapped')

wrapper = SeriesAnalysisWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'SERIES_ANALYSIS_CONFIG_FILE', fake_config_name)
wrapper = SeriesAnalysisWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
12 changes: 12 additions & 0 deletions internal_tests/pytests/stat_analysis/test_stat_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,15 @@ def test_get_level_list(metplus_config, data_type, config_list, expected_list):
saw = StatAnalysisWrapper(config)

assert(saw.get_level_list(data_type) == expected_list)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'
config = metplus_config()
config.set('config', 'INPUT_MUST_EXIST', False)

wrapper = StatAnalysisWrapper(config)
assert not wrapper.c_dict['CONFIG_FILE']

config.set('config', 'STAT_ANALYSIS_CONFIG_FILE', fake_config_name)
wrapper = StatAnalysisWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
17 changes: 16 additions & 1 deletion internal_tests/pytests/tc_gen/test_tc_gen_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
config.set('config', key, value)

wrapper = TCGenWrapper(config)
assert(wrapper.isOK)
assert wrapper.isOK

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
Expand Down Expand Up @@ -361,3 +361,18 @@ def test_tc_gen(metplus_config, config_overrides, env_var_values):
with open(track_path, 'r') as file_handle:
lines = file_handle.read().splitlines()
assert(len(lines) == expected_track_count)

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'TCGenConfig_wrapped')

wrapper = TCGenWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'TC_GEN_CONFIG_FILE', fake_config_name)
wrapper = TCGenWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
19 changes: 18 additions & 1 deletion internal_tests/pytests/tc_pairs/test_tc_pairs_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_read_storm_info(metplus_config, config_overrides, isOK):
config.set('config', key, value)

wrapper = TCPairsWrapper(config)
assert(wrapper.isOK == isOK)
assert wrapper.isOK == isOK

@pytest.mark.parametrize(
'storm_id,basin,cyclone', [
Expand Down Expand Up @@ -511,3 +511,20 @@ def test_tc_pairs_read_all_files(metplus_config, config_overrides,
# unset begin and end for next loop
del env_var_values[f'METPLUS_{loop_by}_BEG']
del env_var_values[f'METPLUS_{loop_by}_END']

def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()
config.set('config', 'INIT_TIME_FMT', time_fmt)
config.set('config', 'INIT_BEG', run_times[0])
default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'TCPairsConfig_wrapped')

wrapper = TCPairsWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'TC_PAIRS_CONFIG_FILE', fake_config_name)
wrapper = TCPairsWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
17 changes: 17 additions & 0 deletions internal_tests/pytests/tc_stat/test_tc_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,20 @@ def test_handle_jobs_create_parent_dir(metplus_config, jobs, init_dt,

# remove parent dirs to clean up for next run
cleanup_test_dirs(parent_dirs, output_dir)


def test_get_config_file(metplus_config):
fake_config_name = '/my/config/file'

config = metplus_config()

default_config_file = os.path.join(config.getdir('PARM_BASE'),
'met_config',
'TCStatConfig_wrapped')

wrapper = TCStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == default_config_file

config.set('config', 'TC_STAT_CONFIG_FILE', fake_config_name)
wrapper = TCStatWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
8 changes: 5 additions & 3 deletions metplus/wrappers/ascii2nc_wrapper.py
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit a254f5a

Please sign in to comment.