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

Feature 779 pb2nc configs #893

Merged
merged 52 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
df4458b
modified handle_mask function to use new approach to setting env vars…
georgemccabe Apr 13, 2021
7d0f1d6
try moving fcst/obs options to FCST/OBS_VAR<n>_OPTIONS, ci-run-diff
georgemccabe Apr 13, 2021
849c41d
started adding support for new env vars for the wrapped MET configs
georgemccabe Apr 13, 2021
292d974
change use case conf back because the fix did not work
georgemccabe Apr 13, 2021
cc647a6
Merge branch 'develop' into feature_779_common_met_configs
georgemccabe Apr 15, 2021
3f02781
added support for many MODEConfig variables
georgemccabe Apr 15, 2021
d02a487
removed MODE_MET_CONFIG_OVERRIDES and replaced the values with the ne…
georgemccabe Apr 15, 2021
ea7dd43
fixed typo in functiona argument, ci-run-diff
georgemccabe Apr 15, 2021
3b2d919
started pytests for mode to test new configs
georgemccabe Apr 15, 2021
5e5dc3d
Merge branch 'develop' into feature_779_common_met_configs
georgemccabe Apr 19, 2021
6d84cf0
added support for rest of MODE config vars that reference grid_res, r…
georgemccabe Apr 19, 2021
b2f9265
added variables that reference grid_res since grid_res value is chang…
georgemccabe Apr 19, 2021
4d36737
no longer set MODE_GRID_RES in wrapped MET config since it should be …
georgemccabe Apr 19, 2021
cb5fa61
added support to set default value for string or list MET config valu…
georgemccabe Apr 20, 2021
49ae35a
set METPLUS_GRID_RES again and set default value for variables that r…
georgemccabe Apr 20, 2021
b898899
removed unnecessary default values, ci-run-diff
georgemccabe Apr 20, 2021
898fd0a
added optional argument to set env var name if it differs from the up…
georgemccabe Apr 20, 2021
40a0eb0
read env_var_name and prepend METPLUS_ if it is not found to use as d…
georgemccabe Apr 20, 2021
f2d22e6
clean up formatting
georgemccabe Apr 20, 2021
5e06a03
added default values for variables that reference grid_res so they wi…
georgemccabe Apr 20, 2021
6e04137
make mask grid_flag and poly_flag uppercase
georgemccabe Apr 20, 2021
f9d2771
no need to set isOK to false because log_error does that automatically
georgemccabe Apr 20, 2021
c7ada93
rearrange list of env vars that are set by wrapper for organization sake
georgemccabe Apr 20, 2021
e36034f
add synonyms for METplus config variables like FCST_MODE_X and MODE_F…
georgemccabe Apr 20, 2021
5fb79c6
auto set uppercase for flag variables
georgemccabe Apr 20, 2021
880efe4
if MODE_GRID_RES is set, set default values for any MET config variab…
georgemccabe Apr 20, 2021
b6571c8
wrote unit tests for mode to check that commands are generated for 2 …
georgemccabe Apr 20, 2021
76b4041
formatting and ci-run-diff
georgemccabe Apr 20, 2021
a5cf482
removed unused variable and reordered variables
georgemccabe Apr 20, 2021
91c24b1
added missing METplus config variables
georgemccabe Apr 20, 2021
58a9ab1
rearranged config variables to group related items for clarify, remov…
georgemccabe Apr 20, 2021
1d78596
added support for setting obs_quality in PointStat wrapped config
georgemccabe Apr 21, 2021
1d886b8
added new config to basic use case
georgemccabe Apr 21, 2021
bc01b40
removed obs_quality from POINT_STAT_MET_CONFIG_OVERRIDES because it i…
georgemccabe Apr 21, 2021
91d163b
added support for all output_flag dictionary values in PointStat, rem…
georgemccabe Apr 21, 2021
f2389de
added name of variable above env var
georgemccabe Apr 21, 2021
28f5074
add output flags that were set to STAT in wrapped config file previou…
georgemccabe Apr 21, 2021
81728c2
changed values in wrapped PointStat config to match default PointStat…
georgemccabe Apr 21, 2021
ba139b1
install cartopy 0.18 because new version won't install properly using…
georgemccabe Apr 21, 2021
5b1e1e0
revert back changes to match default MET config to ensure no differen…
georgemccabe Apr 21, 2021
690d254
changes to support handling MET config variables in a common way incl…
georgemccabe Apr 22, 2021
921053b
added support for climo_mean.time_interp_method, climo_stdev.time_int…
georgemccabe Apr 22, 2021
a415a4e
added old defaults from wrapped config, ci-run-diff
georgemccabe Apr 22, 2021
63e4233
specify version of cartopy to avoid failure
georgemccabe Apr 22, 2021
bcc1cca
Merge branch 'feature_779_point_stat_configs' into feature_779_mode_c…
georgemccabe Apr 22, 2021
36a75ba
added support for pb2nc config variables, made setting overrides opti…
georgemccabe Apr 22, 2021
b43265f
add old defaults to pb2nc basic use case
georgemccabe Apr 22, 2021
6f6ff61
Merge branch 'feature_779_mode_configs' into feature_779_pb2nc_configs
georgemccabe Apr 22, 2021
10d1220
merged develop and resolved conflicts
georgemccabe Apr 26, 2021
a6fd458
added PB2NC_QUALITY_MARK_THRESH = 3 to produce same results as before…
georgemccabe Apr 26, 2021
935b945
added previous default values for pb_report_type and level_category t…
georgemccabe Apr 27, 2021
4b7e460
Merge branch 'develop' into feature_779_pb2nc_configs
georgemccabe Apr 27, 2021
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
25 changes: 25 additions & 0 deletions docs/Users_Guide/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6664,3 +6664,28 @@ METplus Configuration Glossary
Specify the value for 'climo_stdev.time_interp_method' in the MET configuration file for PointStat.

| *Used by:* PointStat

PB2NC_PB_REPORT_TYPE
Specify the value for 'pb_report_type' in the MET configuration file for PB2NC.

| *Used by:* PB2NC

PB2NC_LEVEL_RANGE_BEG
Specify the value for 'level_range.beg' in the MET configuration file for PB2NC.

| *Used by:* PB2NC

PB2NC_LEVEL_RANGE_END
Specify the value for 'level_range.end' in the MET configuration file for PB2NC.

| *Used by:* PB2NC

PB2NC_LEVEL_CATEGORY
Specify the value for 'level_category' in the MET configuration file for PB2NC.

| *Used by:* PB2NC

PB2NC_QUALITY_MARK_THRESH
Specify the value for 'quality_mark_thresh' in the MET configuration file for PB2NC.

| *Used by:* PB2NC
53 changes: 52 additions & 1 deletion docs/Users_Guide/wrappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2656,7 +2656,11 @@ Configuration
| :term:`PB2NC_VALID_END`
| :term:`PB2NC_CUSTOM_LOOP_LIST`
| :term:`PB2NC_MET_CONFIG_OVERRIDES`
|
| :term:`PB2NC_PB_REPORT_TYPE`
| :term:`PB2NC_LEVEL_RANGE_BEG`
| :term:`PB2NC_LEVEL_RANGE_END`
| :term:`PB2NC_LEVEL_CATEGORY`
| :term:`PB2NC_QUALITY_MARK_THRESH`

.. warning:: **DEPRECATED:**

Expand Down Expand Up @@ -2792,6 +2796,53 @@ Below the file contents are descriptions of each environment variable referenced
* - :term:`PB2NC_MET_CONFIG_OVERRIDES`
- n/a

**${METPLUS_PB_REPORT_TYPE}**

.. list-table::
:widths: 5 5
:header-rows: 0

* - METplus Config(s)
- MET Config File
* - :term:`PB2NC_PB_REPORT_TYPE`
- pb_report_type

**${METPLUS_LEVEL_RANGE_DICT}**

.. list-table::
:widths: 5 5
:header-rows: 0

* - METplus Config(s)
- MET Config File
* - :term:`PB2NC_LEVEL_RANGE_BEG`
- level_range.beg
* - :term:`PB2NC_LEVEL_RANGE_END`
- level_range.end

**${METPLUS_LEVEL_CATEGORY}**

.. list-table::
:widths: 5 5
:header-rows: 0

* - METplus Config(s)
- MET Config File
* - :term:`PB2NC_LEVEL_CATEGORY`
- level_category

**${METPLUS_QUALITY_MARK_THRESH}**

.. list-table::
:widths: 5 5
:header-rows: 0

* - METplus Config(s)
- MET Config File
* - :term:`PB2NC_QUALITY_MARK_THRESH`
- quality_mark_thresh


.. _pcp_combine_wrapper:

PCPCombine
Expand Down
178 changes: 178 additions & 0 deletions internal_tests/pytests/pb2nc/test_pb2nc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,181 @@ def test_find_input_files(metplus_config, offsets, offset_to_find):
assert result is None
else:
assert result['offset_hours'] == offset_to_find

@pytest.mark.parametrize(
'config_overrides, env_var_values', [
({'PB2NC_MESSAGE_TYPE': 'ADPUPA, ADPSFC'},
{'METPLUS_MESSAGE_TYPE': 'message_type = ["ADPUPA", "ADPSFC"];'}),

({'PB2NC_STATION_ID': 'station1, station2'},
{'METPLUS_STATION_ID': 'station_id = ["station1", "station2"];'}),

({'OBS_PB2NC_WINDOW_BEGIN': '-1800', },
{'METPLUS_OBS_WINDOW_DICT': 'obs_window = {beg = -1800;}'}),

({'OBS_PB2NC_WINDOW_END': '1800', },
{'METPLUS_OBS_WINDOW_DICT': 'obs_window = {end = 1800;}'}),

({
'OBS_PB2NC_WINDOW_BEGIN': '-1800',
'OBS_PB2NC_WINDOW_END': '1800',
},
{'METPLUS_OBS_WINDOW_DICT': 'obs_window = {beg = -1800;end = 1800;}'}),

({'PB2NC_MASK_GRID': 'FULL', },
{'METPLUS_MASK_DICT': 'mask = {grid = "FULL";}'}),

({'PB2NC_MASK_POLY': 'SAO.poly', },
{'METPLUS_MASK_DICT': 'mask = {poly = "SAO.poly";}'}),

({'PB2NC_MASK_GRID': 'FULL',
'PB2NC_MASK_POLY': 'SAO.poly'},
{'METPLUS_MASK_DICT': 'mask = {grid = "FULL";poly = "SAO.poly";}'}),

({'PB2NC_PB_REPORT_TYPE': '1, 2, 3, 4, 5', },
{'METPLUS_PB_REPORT_TYPE': 'pb_report_type = [1, 2, 3, 4, 5];'}),

({'PB2NC_LEVEL_RANGE_BEGIN': '2', },
{'METPLUS_LEVEL_RANGE_DICT': 'level_range = {beg = 2;}'}),

({'PB2NC_LEVEL_RANGE_END': '512', },
{'METPLUS_LEVEL_RANGE_DICT': 'level_range = {end = 512;}'}),

({'PB2NC_LEVEL_RANGE_BEGIN': '2',
'PB2NC_LEVEL_RANGE_END': '512',
},
{'METPLUS_LEVEL_RANGE_DICT': 'level_range = {beg = 2;end = 512;}'}),

({'PB2NC_LEVEL_CATEGORY': '0, 1, 4, 5, 6', },
{'METPLUS_LEVEL_CATEGORY': 'level_category = [0, 1, 4, 5, 6];'}),

({'PB2NC_OBS_BUFR_VAR_LIST': 'QOB, TOB', },
{'METPLUS_OBS_BUFR_VAR': 'obs_bufr_var = ["QOB", "TOB"];'}),

({'PB2NC_QUALITY_MARK_THRESH': '3', },
{'METPLUS_QUALITY_MARK_THRESH': 'quality_mark_thresh = 3;'}),

({'PB2NC_TIME_SUMMARY_FLAG': 'True', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {flag = TRUE;}'}),

({'PB2NC_TIME_SUMMARY_RAW_DATA': 'True', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {raw_data = TRUE;}'}),

({'PB2NC_TIME_SUMMARY_BEG': '012345', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {beg = "012345";}'}),

({'PB2NC_TIME_SUMMARY_END': '234559', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {end = "234559";}'}),

({'PB2NC_TIME_SUMMARY_STEP': '200', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {step = 200;}'}),

({'PB2NC_TIME_SUMMARY_WIDTH': '500', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {width = 500;}'}),

({'PB2NC_TIME_SUMMARY_GRIB_CODES': '11, 204, 211', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {grib_code = [11, 204, 211];}'}),

({'PB2NC_TIME_SUMMARY_VAR_NAMES': 'PMO,TOB,TDO', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {obs_var = ["PMO", "TOB", "TDO"];}'}),

({'PB2NC_TIME_SUMMARY_TYPE': 'min, max, range', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {type = ["min", "max", "range"];}'}),

({'PB2NC_TIME_SUMMARY_VLD_FREQ': '1', },
{'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {vld_freq = 1;}'}),

({'PB2NC_TIME_SUMMARY_VLD_THRESH': '0.1', },
{
'METPLUS_TIME_SUMMARY_DICT': 'time_summary = {vld_thresh = 0.1;}'}),

({
'PB2NC_TIME_SUMMARY_FLAG': 'TRUE',
'PB2NC_TIME_SUMMARY_RAW_DATA': 'TRUE',
'PB2NC_TIME_SUMMARY_BEG': '012345',
'PB2NC_TIME_SUMMARY_END': '234559',
'PB2NC_TIME_SUMMARY_STEP': '200',
'PB2NC_TIME_SUMMARY_WIDTH': '500',
'PB2NC_TIME_SUMMARY_GRIB_CODES': '11, 204, 211',
'PB2NC_TIME_SUMMARY_VAR_NAMES': 'PMO,TOB,TDO',
'PB2NC_TIME_SUMMARY_TYPE': 'min, max, range',
'PB2NC_TIME_SUMMARY_VLD_FREQ': '1',
'PB2NC_TIME_SUMMARY_VLD_THRESH': '0.1',
},
{
'METPLUS_TIME_SUMMARY_DICT': ('time_summary = {flag = TRUE;'
'raw_data = TRUE;beg = "012345";'
'end = "234559";step = 200;'
'width = 500;grib_code = [11, 204, 211];'
'obs_var = ["PMO", "TOB", "TDO"];'
'type = ["min", "max", "range"];'
'vld_freq = 1;'
'vld_thresh = 0.1;}')}),

]
)
def test_pb2nc_all_fields(metplus_config, config_overrides,
env_var_values):
input_dir = '/some/input/dir'
config = metplus_config()

# set config variables to prevent command from running and bypass check
# if input files actually exist
config.set('config', 'DO_NOT_RUN_EXE', True)
config.set('config', 'INPUT_MUST_EXIST', False)

# set process and time config variables
config.set('config', 'PROCESS_LIST', 'PB2NC')
config.set('config', 'LOOP_BY', 'VALID')
config.set('config', 'VALID_TIME_FMT', '%Y%m%d%H')
config.set('config', 'VALID_BEG', '2007033112')
config.set('config', 'VALID_END', '2007040100')
config.set('config', 'VALID_INCREMENT', '12H')
config.set('config', 'LEAD_SEQ', '0')
config.set('config', 'PB2NC_OFFSETS', '12')
config.set('config', 'LOOP_ORDER', 'processes')

config.set('config', 'PB2NC_CONFIG_FILE',
'{PARM_BASE}/met_config/PB2NCConfig_wrapped')
config.set('config', 'PB2NC_INPUT_DIR', input_dir)
config.set('config', 'PB2NC_INPUT_TEMPLATE',
'ndas.t{da_init?fmt=%2H}z.prepbufr.tm{offset?fmt=%2H}.{da_init?fmt=%Y%m%d}.nr')
config.set('config', 'PB2NC_OUTPUT_DIR',
'{OUTPUT_BASE}/PB2NC/output')
config.set('config', 'PB2NC_OUTPUT_TEMPLATE', '{valid?fmt=%Y%m%d%H}.nc')

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

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

app_path = os.path.join(config.getdir('MET_BIN_DIR'), wrapper.app_name)
verbosity = f"-v {wrapper.c_dict['VERBOSITY']}"
config_file = wrapper.c_dict.get('CONFIG_FILE')
out_dir = wrapper.c_dict.get('OUTPUT_DIR')
expected_cmds = [(f"{app_path} {verbosity} "
f"{input_dir}/ndas.t00z.prepbufr.tm12.20070401.nr "
f"{out_dir}/2007033112.nc "
f"{config_file}"),
(f"{app_path} {verbosity} "
f"{input_dir}/ndas.t12z.prepbufr.tm12.20070401.nr "
f"{out_dir}/2007040100.nc "
f"{config_file}"),
]

all_cmds = wrapper.run_all_times()
print(f"ALL COMMANDS: {all_cmds}")

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

# check that environment variables were set properly
for env_var_key in wrapper.WRAPPER_ENV_VAR_KEYS:
match = next((item for item in env_vars if
item.startswith(env_var_key)), None)
assert(match is not None)
value = match.split('=', 1)[1]
assert(env_var_values.get(env_var_key, '') == value)
1 change: 1 addition & 0 deletions metplus/wrappers/command_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def handle_obs_window_variables(self, c_dict):
tmp_dict = {}
for edge, default_val in edges:
input_list = [f'OBS_{app}_WINDOW_{edge}',
f'{app}_OBS_WINDOW_{edge}',
f'OBS_WINDOW_{edge}',
]
output_key = f'OBS_WINDOW_{edge}'
Expand Down
67 changes: 53 additions & 14 deletions metplus/wrappers/pb2nc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class PB2NCWrapper(CommandBuilder):
'METPLUS_MASK_DICT',
'METPLUS_OBS_BUFR_VAR',
'METPLUS_TIME_SUMMARY_DICT',
'METPLUS_PB_REPORT_TYPE',
'METPLUS_LEVEL_RANGE_DICT',
'METPLUS_LEVEL_CATEGORY',
'METPLUS_QUALITY_MARK_THRESH',
]

def __init__(self, config, instance=None, config_overrides={}):
Expand Down Expand Up @@ -136,13 +140,46 @@ def create_c_dict(self):
station_id = '[]'
c_dict['STATION_ID'] = station_id

c_dict['GRID'] = self.config.getstr('config', 'PB2NC_GRID')
c_dict['POLY'] = self.config.getstr('config', 'PB2NC_POLY')
c_dict['GRID'] = self.config.getstr('config', 'PB2NC_GRID', '')
c_dict['POLY'] = self.config.getstr('config', 'PB2NC_POLY', '')

c_dict['BUFR_VAR_LIST'] = (
self.get_env_var_value('METPLUS_OBS_BUFR_VAR')
)

self.add_met_config(name='pb_report_type',
data_type='list',
metplus_configs=['PB2NC_PB_REPORT_TYPE'],
extra_args={'remove_quotes': True})

# get level_range beg and end
level_range_items = []
level_range_items.append(
self.get_met_config(name='beg',
data_type='int',
metplus_configs=['PB2NC_LEVEL_RANGE_BEG',
'PB2NC_LEVEL_RANGE_BEGIN'])
)
level_range_items.append(
self.get_met_config(name='end',
data_type='int',
metplus_configs=['PB2NC_LEVEL_RANGE_END'])
)

self.add_met_config(name='level_range',
data_type='dict',
children=level_range_items)

self.add_met_config(name='level_category',
data_type='list',
metplus_configs=['PB2NC_LEVEL_CATEGORY'],
extra_args={'remove_quotes': True})

self.add_met_config(name='quality_mark_thresh',
data_type='int',
metplus_configs=['PB2NC_QUALITY_MARK_THRESH'])


return c_dict

def set_environment_variables(self, time_info):
Expand All @@ -153,26 +190,28 @@ def set_environment_variables(self, time_info):
@param time_info dictionary containing timing info from current run
"""
# set old method of setting env vars needed for MET config file
self.add_env_var("PB2NC_MESSAGE_TYPE", self.c_dict['MESSAGE_TYPE'])
self.add_env_var("PB2NC_STATION_ID", self.c_dict['STATION_ID'])
self.add_env_var("PB2NC_MESSAGE_TYPE", self.c_dict.get('MESSAGE_TYPE', ''))
self.add_env_var("PB2NC_STATION_ID", self.c_dict.get('STATION_ID', ''))
self.add_env_var("OBS_WINDOW_BEGIN",
str(self.c_dict['OBS_WINDOW_BEGIN']))
self.add_env_var("OBS_WINDOW_END", str(self.c_dict['OBS_WINDOW_END']))
self.add_env_var("PB2NC_GRID", self.c_dict['GRID'])
self.add_env_var("PB2NC_POLY", self.c_dict['POLY'])
str(self.c_dict.get('OBS_WINDOW_BEGIN', '')))
self.add_env_var("OBS_WINDOW_END",
str(self.c_dict.get('OBS_WINDOW_END', '')))
self.add_env_var("PB2NC_GRID", self.c_dict.get('GRID', ''))
self.add_env_var("PB2NC_POLY", self.c_dict.get('POLY', ''))

self.add_env_var("OBS_BUFR_VAR_LIST", self.c_dict['BUFR_VAR_LIST'])
self.add_env_var("OBS_BUFR_VAR_LIST", self.c_dict.get('BUFR_VAR_LIST',
''))

self.add_env_var('TIME_SUMMARY_FLAG',
self.c_dict['TIME_SUMMARY_FLAG'])
self.c_dict.get('TIME_SUMMARY_FLAG', ''))
self.add_env_var('TIME_SUMMARY_BEG',
self.c_dict['TIME_SUMMARY_BEG'])
self.c_dict.get('TIME_SUMMARY_BEG', ''))
self.add_env_var('TIME_SUMMARY_END',
self.c_dict['TIME_SUMMARY_END'])
self.c_dict.get('TIME_SUMMARY_END', ''))
self.add_env_var('TIME_SUMMARY_VAR_NAMES',
self.c_dict['TIME_SUMMARY_VAR_NAMES'])
self.c_dict.get('TIME_SUMMARY_VAR_NAMES', ''))
self.add_env_var('TIME_SUMMARY_TYPES',
self.c_dict['TIME_SUMMARY_TYPES'])
self.c_dict.get('TIME_SUMMARY_TYPES', ''))

super().set_environment_variables(time_info)

Expand Down
Loading