Skip to content

Commit

Permalink
per #1569, added test for setting -ens_mean and -point_obs, and -grid…
Browse files Browse the repository at this point in the history
…_obs arguments
  • Loading branch information
georgemccabe committed Nov 16, 2022
1 parent fb28694 commit 2c9a8f1
Showing 1 changed file with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

fcst_dir = '/some/path/fcst'
obs_dir = '/some/path/obs'
ens_mean_dir = '/some/path/ens_mean'
ens_mean_template = 'the_ens_mean_file.nc'
obs_point_template = 'point_obs.nc'
fcst_name = 'APCP'
fcst_level = 'A03'
obs_name = 'APCP_03'
Expand Down Expand Up @@ -43,10 +46,10 @@ def set_minimum_config_settings(config, set_fields=True):
config.set('config', 'ENSEMBLE_STAT_CONFIG_FILE',
'{PARM_BASE}/met_config/EnsembleStatConfig_wrapped')
config.set('config', 'FCST_ENSEMBLE_STAT_INPUT_DIR', fcst_dir)
config.set('config', 'OBS_ENSEMBLE_STAT_INPUT_DIR', obs_dir)
config.set('config', 'OBS_ENSEMBLE_STAT_GRID_INPUT_DIR', obs_dir)
config.set('config', 'FCST_ENSEMBLE_STAT_INPUT_TEMPLATE',
'{init?fmt=%Y%m%d%H}/fcst_file_F{lead?fmt=%3H}')
config.set('config', 'OBS_ENSEMBLE_STAT_INPUT_TEMPLATE',
config.set('config', 'OBS_ENSEMBLE_STAT_GRID_INPUT_TEMPLATE',
'{valid?fmt=%Y%m%d%H}/obs_file')
config.set('config', 'ENSEMBLE_STAT_OUTPUT_DIR',
'{OUTPUT_BASE}/EnsembleStat/output')
Expand Down Expand Up @@ -199,11 +202,11 @@ def test_handle_climo_file_variables(metplus_config, config_overrides,
for old_env in old_env_vars:
match = next((item for item in actual_env_vars if
item.startswith(old_env)), None)
assert(match is not None)
assert match is not None
actual_value = match.split('=', 1)[1]
expected_value = env_var_values.get(old_env, '')
expected_value = expected_value.replace('YMDH', ymdh)
assert(expected_value == actual_value)
assert expected_value == actual_value


@pytest.mark.parametrize(
Expand Down Expand Up @@ -601,6 +604,21 @@ def test_handle_climo_file_variables(metplus_config, config_overrides,
({'ENSEMBLE_STAT_OBS_THRESH': 'NA, 0.5', },
{'METPLUS_OBS_THRESH': 'obs_thresh = [NA, 0.5];'}),
({'ENSEMBLE_STAT_ENS_MEAN_INPUT_DIR': ens_mean_dir,
'ENSEMBLE_STAT_ENS_MEAN_INPUT_TEMPLATE': ens_mean_template},
{}),
({'OBS_ENSEMBLE_STAT_POINT_INPUT_DIR': obs_dir,
'OBS_ENSEMBLE_STAT_POINT_INPUT_TEMPLATE': obs_point_template},
{}),
({'ENSEMBLE_STAT_ENS_MEAN_INPUT_DIR': ens_mean_dir,
'ENSEMBLE_STAT_ENS_MEAN_INPUT_TEMPLATE': ens_mean_template,
'OBS_ENSEMBLE_STAT_POINT_INPUT_DIR': obs_dir,
'OBS_ENSEMBLE_STAT_POINT_INPUT_TEMPLATE': obs_point_template},
{}),
]
)
@pytest.mark.wrapper_c
Expand All @@ -623,12 +641,24 @@ def test_ensemble_stat_single_field(metplus_config, config_overrides,
file_list_dir = wrapper.config.getdir('FILE_LISTS_DIR')
config_file = wrapper.c_dict.get('CONFIG_FILE')
out_dir = wrapper.c_dict.get('OUTPUT_DIR')

point_obs = ' '
ens_mean = ' '
if 'OBS_ENSEMBLE_STAT_POINT_INPUT_TEMPLATE' in config_overrides:
point_obs = f' -point_obs "{obs_dir}/{obs_point_template}" '
if 'ENSEMBLE_STAT_ENS_MEAN_INPUT_TEMPLATE' in config_overrides:
ens_mean = f' -ens_mean {ens_mean_dir}/{ens_mean_template} '

expected_cmds = [(f"{app_path} {verbosity} "
f"{file_list_dir}/20050807000000_12_ensemble_stat.txt "
f"{config_file} -outdir {out_dir}/2005080712"),
f"{config_file}{point_obs}"
f'-grid_obs "{obs_dir}/2005080712/obs_file"{ens_mean}'
f"-outdir {out_dir}/2005080712"),
(f"{app_path} {verbosity} "
f"{file_list_dir}/20050807120000_12_ensemble_stat.txt "
f"{config_file} -outdir {out_dir}/2005080800"),
f"{config_file}{point_obs}"
f'-grid_obs "{obs_dir}/2005080800/obs_file"{ens_mean}'
f"-outdir {out_dir}/2005080800"),
]

all_cmds = wrapper.run_all_times()
Expand All @@ -637,7 +667,7 @@ def test_ensemble_stat_single_field(metplus_config, config_overrides,

for (cmd, env_vars), expected_cmd in zip(all_cmds, expected_cmds):
# ensure commands are generated as expected
assert(cmd == expected_cmd)
assert cmd == expected_cmd

# check that environment variables were set properly
# including deprecated env vars (not in wrapper env var keys)
Expand All @@ -650,11 +680,11 @@ def test_ensemble_stat_single_field(metplus_config, config_overrides,
assert(match is not None)
actual_value = match.split('=', 1)[1]
if env_var_key == 'METPLUS_FCST_FIELD':
assert(actual_value == fcst_fmt)
assert actual_value == fcst_fmt
elif env_var_key == 'METPLUS_OBS_FIELD':
assert (actual_value == obs_fmt)
assert actual_value == obs_fmt
else:
assert(env_var_values.get(env_var_key, '') == actual_value)
assert env_var_values.get(env_var_key, '') == actual_value


@pytest.mark.wrapper_c
Expand Down

0 comments on commit 2c9a8f1

Please sign in to comment.