From 01ff8cc960f98b30570f0e32952b9dcb173dcf0e Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Mon, 27 Feb 2023 12:25:02 -0700 Subject: [PATCH] per #2006, fix priority of obs_window config variables so that wrapper-specific version is preferred over generic OBS_WINDOW_BEGIN/END --- .../point_stat/test_point_stat_wrapper.py | 12 +++++++++ metplus/util/met_config.py | 26 +++++++++++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py b/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py index a384e1b725..0293e84302 100755 --- a/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py +++ b/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py @@ -169,6 +169,18 @@ def test_met_dictionary_in_var_options(metplus_config): 'OBS_WINDOW_BEGIN': '-2700', 'OBS_WINDOW_END': '2700' }), + # test that {app}_OBS_WINDOW are preferred over + # OBS_{app}_WINDOW and generic OBS_WINDOW + ({'OBS_POINT_STAT_WINDOW_BEGIN': '-2700', + 'OBS_POINT_STAT_WINDOW_END': '2700', + 'POINT_STAT_OBS_WINDOW_BEGIN': '-1800', + 'POINT_STAT_OBS_WINDOW_END': '1800', + 'OBS_WINDOW_BEGIN': '-900', + 'OBS_WINDOW_END': '900', + }, + {'METPLUS_OBS_WINDOW_DICT': + 'obs_window = {beg = -1800;end = 1800;}', + }), ({'POINT_STAT_CLIMO_CDF_CDF_BINS': '1', }, {'METPLUS_CLIMO_CDF_DICT': 'climo_cdf = {cdf_bins = 1.0;}'}), diff --git a/metplus/util/met_config.py b/metplus/util/met_config.py index 91b4115b3e..a097dd6990 100644 --- a/metplus/util/met_config.py +++ b/metplus/util/met_config.py @@ -165,28 +165,32 @@ def add_met_config_dict(config, app_name, output_dict, dict_name, items): if 'dict' not in data_type: children = None - # handle legacy OBS_WINDOW variables that put OBS_ before app name - # i.e. OBS_GRID_STAT_WINDOW_[BEGIN/END] + metplus_configs.append(metplus_name) + + # if variable ends with _BEG, read _BEGIN first + if metplus_name.endswith('BEG'): + metplus_configs.append(f'{metplus_name}IN') + if dict_name == 'obs_window': suffix = 'BEGIN' if name == 'beg' else name.upper() + # handle legacy OBS_WINDOW variables that put OBS_ before + # app name i.e. OBS_GRID_STAT_WINDOW_[BEGIN/END] metplus_configs.append( f"OBS_{app_name}_WINDOW_{suffix}".upper() ) # also add support for legacy PB2NC_WINDOW_[BEGIN/END] - metplus_configs.append( - f"{app_name}_WINDOW_{suffix}".upper() - ) + if app_name.lower() == 'pb2nc': + metplus_configs.append( + f"{app_name}_WINDOW_{suffix}".upper() + ) # also add OBS_WINDOW_[BEGIN/END] - metplus_configs.append(f"OBS_WINDOW_{suffix}") - - # if variable ends with _BEG, read _BEGIN first - if metplus_name.endswith('BEG'): - metplus_configs.append(f'{metplus_name}IN') + metplus_configs.append(f"{dict_name}_{name}".upper()) + if name == 'beg': + metplus_configs.append(f"{dict_name}_{name}IN".upper()) - metplus_configs.append(metplus_name) # add other variable names to search if expected name is unset if nicknames: for nickname in nicknames: