Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix 1421 EnsembleStat use fcst fields in ens dictionary if ens is unset #1422

Merged
merged 4 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Grid-Stat: 6hr PQPF Probability Verification
==========================================================================

model_applications/precipitation/GridStat_fcstHRRR
model_applications/precipitation/GridStat_fcstHRRR-TLE
_obsStgIV_GRIB.conf

"""
Expand Down
86 changes: 79 additions & 7 deletions internal_tests/pytests/ensemble_stat/test_ensemble_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
time_fmt = '%Y%m%d%H'
run_times = ['2005080700', '2005080712']

def set_minimum_config_settings(config):
def set_minimum_config_settings(config, set_fields=True):
# set config variables to prevent command from running and bypass check
# if input files actually exist
config.set('config', 'DO_NOT_RUN_EXE', True)
Expand Down Expand Up @@ -59,12 +59,84 @@ def set_minimum_config_settings(config):
'{OUTPUT_BASE}/EnsembleStat/output')
config.set('config', 'ENSEMBLE_STAT_OUTPUT_TEMPLATE', '{valid?fmt=%Y%m%d%H}')

config.set('config', 'FCST_VAR1_NAME', fcst_name)
config.set('config', 'FCST_VAR1_LEVELS', fcst_level)
config.set('config', 'OBS_VAR1_NAME', obs_name)
config.set('config', 'OBS_VAR1_LEVELS', obs_level)
config.set('config', 'ENS_VAR1_NAME', ens_name)
config.set('config', 'ENS_VAR1_LEVELS', ens_level)
if set_fields:
config.set('config', 'FCST_VAR1_NAME', fcst_name)
config.set('config', 'FCST_VAR1_LEVELS', fcst_level)
config.set('config', 'OBS_VAR1_NAME', obs_name)
config.set('config', 'OBS_VAR1_LEVELS', obs_level)
config.set('config', 'ENS_VAR1_NAME', ens_name)
config.set('config', 'ENS_VAR1_LEVELS', ens_level)

@pytest.mark.parametrize(
'config_overrides, env_var_values', [
# 0 : 3 ens, 1 fcst, 1 obs
({'ENS_VAR1_NAME': 'ens_name_1',
'ENS_VAR1_LEVELS': 'ENS_LEVEL_1',
'ENS_VAR2_NAME': 'ens_name_2',
'ENS_VAR2_LEVELS': 'ENS_LEVEL_2A, ENS_LEVEL_2B',
'FCST_VAR1_NAME': 'fcst_name_1',
'FCST_VAR1_LEVELS': 'FCST_LEVEL_1',
'OBS_VAR1_NAME': 'obs_name_1',
'OBS_VAR1_LEVELS': 'OBS_LEVEL_1',
},
{'METPLUS_ENS_FIELD': ('field = ['
'{ name="ens_name_1"; level="ENS_LEVEL_1"; },'
'{ name="ens_name_2"; level="ENS_LEVEL_2A"; },'
'{ name="ens_name_2"; level="ENS_LEVEL_2B"; }'
'];'),
'METPLUS_FCST_FIELD': ('field = ['
'{ name="fcst_name_1"; level="FCST_LEVEL_1"; }'
'];'),
'METPLUS_OBS_FIELD': ('field = ['
'{ name="obs_name_1"; level="OBS_LEVEL_1"; }'
'];'),
}),
# 1 : no ens, 1 fcst, 1 obs -- use fcst for ens
({'FCST_VAR1_NAME': 'fcst_name_1',
'FCST_VAR1_LEVELS': 'FCST_LEVEL_1',
'OBS_VAR1_NAME': 'obs_name_1',
'OBS_VAR1_LEVELS': 'OBS_LEVEL_1',
},
{'METPLUS_ENS_FIELD': ('field = ['
'{ name="fcst_name_1"; level="FCST_LEVEL_1"; }'
'];'),
'METPLUS_FCST_FIELD': ('field = ['
'{ name="fcst_name_1"; level="FCST_LEVEL_1"; }'
'];'),
'METPLUS_OBS_FIELD': ('field = ['
'{ name="obs_name_1"; level="OBS_LEVEL_1"; }'
'];'),
}),
]
)
def test_ensemble_stat_field_info(metplus_config, config_overrides,
env_var_values):

config = metplus_config()

set_minimum_config_settings(config, set_fields=False)

# set config variable overrides
for key, value in config_overrides.items():
config.set('config', key, value)

wrapper = EnsembleStatWrapper(config)
assert wrapper.isOK

all_cmds = wrapper.run_all_times()

assert len(all_cmds) == 2

actual_env_vars = all_cmds[0][1]
for key, expected_value in env_var_values.items():
match = next((item for item in actual_env_vars if
item.startswith(key)), None)
assert match is not None
actual_value = match.split('=', 1)[1]
assert actual_value == expected_value
print(f"ACTUAL : {actual_value}")
print(f"EXPECTED: {expected_value}")


@pytest.mark.parametrize(
'config_overrides, env_var_values', [
Expand Down
2 changes: 1 addition & 1 deletion internal_tests/use_cases/all_use_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Category: precipitation
4::GridStat_fcstHRRR-TLE_obsStgIV_GRIB:: model_applications/precipitation/GridStat_fcstHRRR-TLE_obsStgIV_GRIB.conf
5::MTD_fcstHRRR-TLE_FcstOnly_RevisionSeries_GRIB:: model_applications/precipitation/MTD_fcstHRRR-TLE_FcstOnly_RevisionSeries_GRIB.conf
6::MTD_fcstHRRR-TLE_obsMRMS:: model_applications/precipitation/MTD_fcstHRRR-TLE_obsMRMS.conf

7::EnsembleStat_fcstWOFS_obsWOFS:: model_applications/precipitation/EnsembleStat_fcstWOFS_obsWOFS.conf::

Category: s2s
0::GridStat_SeriesAnalysis_fcstNMME_obsCPC_seasonal_forecast:: model_applications/s2s/GridStat_SeriesAnalysis_fcstNMME_obsCPC_seasonal_forecast.conf:: netcdf4_env
Expand Down
4 changes: 4 additions & 0 deletions metplus/wrappers/ensemble_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ def run_at_time_all_fields(self, time_info):
self.log_error("Could not build field info for fcst, obs, or ens")
return

# if ens is not set, use fcst
if not ens_field:
ens_field = fcst_field

self.format_field('FCST', fcst_field)
self.format_field('OBS', obs_field)
self.format_field('ENS', ens_field)
Expand Down