Skip to content

Commit

Permalink
per #2540, add support for setting values in a config file for Point2…
Browse files Browse the repository at this point in the history
…Grid wrapper -- removed -qc flag argument in favor of setting obs_quality_inc in the config file
  • Loading branch information
georgemccabe committed May 9, 2024
1 parent 14b9128 commit f35b6a5
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 23 deletions.
47 changes: 46 additions & 1 deletion docs/Users_Guide/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ METplus Configuration Glossary
| *Used by:* Point2Grid
POINT2GRID_QC_FLAGS
Specify the qc flags name that is read by Point2Grid.
.. warning:: **DEPRECATED:** Please use :term:`POINT2GRID_OBS_QUALITY_INC`.

| *Used by:* Point2Grid
Expand Down Expand Up @@ -11633,3 +11633,48 @@ METplus Configuration Glossary
Specify the value for 'obs_perc_value' in the MET configuration file for PointStat.

| *Used by:* PointStat
POINT2GRID_VALID_TIME
Specify the value for 'valid_time' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_OBS_WINDOW_BEG
Specify the value for 'obs_window.beg' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_OBS_WINDOW_END
Specify the value for 'obs_window.end' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_MESSAGE_TYPE
Specify the value for 'message_type' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_VAR_NAME_MAP<n>_KEY
Specify the value for the nth 'var_name_map.key' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_VAR_NAME_MAP<n>_VAL
Specify the value for the nth 'var_name_map.val' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_QUALITY_MARK_THRESH
Specify the value for 'quality_mark_thresh' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_OBS_QUALITY_INC
Specify the value for 'obs_quality_inc' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
POINT2GRID_OBS_QUALITY_EXC
Specify the value for 'obs_quality_exc' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid
128 changes: 127 additions & 1 deletion docs/Users_Guide/wrappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6261,7 +6261,6 @@ METplus Configuration
| :term:`POINT2GRID_REGRID_TO_GRID`
| :term:`POINT2GRID_INPUT_FIELD`
| :term:`POINT2GRID_INPUT_LEVEL`
| :term:`POINT2GRID_QC_FLAGS`
| :term:`POINT2GRID_ADP`
| :term:`POINT2GRID_REGRID_METHOD`
| :term:`POINT2GRID_GAUSSIAN_DX`
Expand All @@ -6274,8 +6273,135 @@ METplus Configuration
| :term:`POINT2GRID_INC_VALID_TIMES`
| :term:`POINT2GRID_SKIP_INIT_TIMES`
| :term:`POINT2GRID_INC_INIT_TIMES`
| :term:`POINT2GRID_VALID_TIME`
| :term:`POINT2GRID_OBS_WINDOW_BEG`
| :term:`POINT2GRID_OBS_WINDOW_END`
| :term:`POINT2GRID_MESSAGE_TYPE`
| :term:`POINT2GRID_VAR_NAME_MAP<n>_KEY`
| :term:`POINT2GRID_VAR_NAME_MAP<n>_VAL`
| :term:`POINT2GRID_QUALITY_MARK_THRESH`
| :term:`POINT2GRID_OBS_QUALITY_INC`
| :term:`POINT2GRID_OBS_QUALITY_EXC`
|
.. warning:: **DEPRECATED:**

| :term:`POINT2GRID_QC_FLAGS`
.. _point2grid-met-conf:

MET Configuration
-----------------

Below is the wrapped MET configuration file used for this wrapper.
Environment variables are used to control entries in this configuration file.
The default value for each environment variable is obtained from
(except where noted below):

`MET_INSTALL_DIR/share/met/config/Point2GridConfig_default <https://github.com/dtcenter/MET/blob/HEAD/data/config/Point2GridConfig_default>`_

Below the file contents are descriptions of each environment variable
referenced in this file and the corresponding METplus configuration item used
to set the value of the environment variable. For detailed examples showing
how METplus sets the values of these environment variables,
see :ref:`How METplus controls MET config file settings<metplus-control-met>`.

.. dropdown:: Click to view parm/met_config/Point2GridConfig_wrapped

.. literalinclude:: ../../parm/met_config/Point2GridConfig_wrapped

Environment variables in wrapped MET config
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

${METPLUS_VALID_TIME}
^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_VALID_TIME`
- valid_time

${METPLUS_OBS_WINDOW_DICT}
^^^^^^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_OBS_WINDOW_BEG`
- obs_window.beg
* - :term:`POINT2GRID_OBS_WINDOW_END`
- obs_window.end

${METPLUS_MESSAGE_TYPE}
^^^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_MESSAGE_TYPE`
- message_type

${METPLUS_VAR_NAME_MAP_LIST}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_VAR_NAME_MAP<n>_KEY`
- var_name_map.key
* - :term:`POINT2GRID_VAR_NAME_MAP<n>_VAL`
- var_name_map.val

${METPLUS_QUALITY_MARK_THRESH}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

${METPLUS_OBS_QUALITY_INC}
^^^^^^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_OBS_QUALITY_INC`
- obs_quality_inc

${METPLUS_OBS_QUALITY_EXC}
^^^^^^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_OBS_QUALITY_EXC`
- obs_quality_exc


.. _point_stat_wrapper:

PointStat
Expand Down
94 changes: 80 additions & 14 deletions internal/tests/pytests/wrappers/point2grid/test_point2grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,57 @@ def test_point2grid_missing_inputs(metplus_config, get_test_data_dir,


@pytest.mark.parametrize(
'config_overrides, optional_args', [
({}, {}),
({'POINT2GRID_REGRID_METHOD': 'UW_MEAN'}, ['-method UW_MEAN']),
'config_overrides, env_var_values, optional_args', [
({}, {}, []),
({'POINT2GRID_REGRID_METHOD': 'UW_MEAN'}, {}, ['-method UW_MEAN']),
({'POINT2GRID_REGRID_METHOD': 'UW_MEAN',
'POINT2GRID_GAUSSIAN_DX': '2',},
'POINT2GRID_GAUSSIAN_DX': '2',}, {},
['-method UW_MEAN', '-gaussian_dx 2']),
({'POINT2GRID_GAUSSIAN_RADIUS': '81.231'},
({'POINT2GRID_GAUSSIAN_RADIUS': '81.231'}, {},
['-gaussian_radius 81.231']),
({'POINT2GRID_PROB_CAT_THRESH': '1'}, ['-prob_cat_thresh 1']),
({'POINT2GRID_VLD_THRESH': '0.5'}, ['-vld_thresh 0.5']),
({'POINT2GRID_QC_FLAGS': '0,1'}, ['-qc 0,1']),
({'POINT2GRID_ADP': '{valid?fmt=%Y%m}.nc'}, ['-adp 201706.nc']),
({'POINT2GRID_REGRID_TO_GRID': 'G212'}, []),
({'POINT2GRID_INPUT_LEVEL': '(*,*)'}, []),
({'POINT2GRID_PROB_CAT_THRESH': '1'}, {}, ['-prob_cat_thresh 1']),
({'POINT2GRID_VLD_THRESH': '0.5'}, {}, ['-vld_thresh 0.5']),
({'POINT2GRID_ADP': '{valid?fmt=%Y%m}.nc'}, {}, ['-adp 201706.nc']),
({'POINT2GRID_REGRID_TO_GRID': 'G212'}, {}, []),
({'POINT2GRID_INPUT_LEVEL': '(*,*)'}, {}, []),
({'POINT2GRID_VALID_TIME': '20240509_120800', },
{'METPLUS_VALID_TIME': 'valid_time = "20240509_120800";'}, []),
({'POINT2GRID_OBS_WINDOW_BEG': '-5400', },
{'METPLUS_OBS_WINDOW_DICT': 'obs_window = {beg = -5400;}'}, []),
({'POINT2GRID_OBS_WINDOW_END': '3600', },
{'METPLUS_OBS_WINDOW_DICT': 'obs_window = {end = 3600;}'}, []),
({'POINT2GRID_OBS_WINDOW_BEG': '-3600', 'POINT2GRID_OBS_WINDOW_END': '5400'},
{'METPLUS_OBS_WINDOW_DICT': 'obs_window = {beg = -3600;end = 5400;}'}, []),
({'POINT2GRID_MESSAGE_TYPE': 'ADPSFC, ADPUPA'},
{'METPLUS_MESSAGE_TYPE': 'message_type = ["ADPSFC", "ADPUPA"];'}, []),
({'POINT2GRID_VAR_NAME_MAP1_KEY': '3', 'POINT2GRID_VAR_NAME_MAP1_VAL': 'MAGIC'},
{'METPLUS_VAR_NAME_MAP_LIST': 'var_name_map = [{key = "3";val = "MAGIC";}];'}, []),
({'POINT2GRID_VAR_NAME_MAP1_KEY': '13', 'POINT2GRID_VAR_NAME_MAP1_VAL': 'LUCKY',
'POINT2GRID_VAR_NAME_MAP2_KEY': '3', 'POINT2GRID_VAR_NAME_MAP2_VAL': 'MAGIC'
},
{'METPLUS_VAR_NAME_MAP_LIST': 'var_name_map = [{key = "13";val = "LUCKY";},{key = "3";val = "MAGIC";}];'}, []),
({'POINT2GRID_QUALITY_MARK_THRESH': '3', },
{'METPLUS_QUALITY_MARK_THRESH': 'quality_mark_thresh = 3;'}, []),
({'POINT2GRID_OBS_QUALITY_INC': '0, 1, 2', },
{'METPLUS_OBS_QUALITY_INC': 'obs_quality_inc = ["0", "1", "2"];'}, []),
({'POINT2GRID_OBS_QUALITY_EXC': '3,4, 5', },
{'METPLUS_OBS_QUALITY_EXC': 'obs_quality_exc = ["3", "4", "5"];'}, []),
({'POINT2GRID_QC_FLAGS': '0,1'}, {'METPLUS_OBS_QUALITY_INC': 'obs_quality_inc = ["0", "1"];'}, []),
]
)
@pytest.mark.wrapper
def test_point2grid_run(metplus_config, config_overrides, optional_args):
def test_point2grid_run(metplus_config, config_overrides, optional_args,
env_var_values):
config = metplus_config
set_minimum_config_settings(config)

Expand Down Expand Up @@ -139,13 +172,19 @@ def test_point2grid_run(metplus_config, config_overrides, optional_args):
else:
level = ''

config_file = wrapper.c_dict.get('CONFIG_FILE')
extra_args = " ".join(optional_args) + " " if optional_args else ""

missing_env = [item for item in env_var_values
if item not in wrapper.WRAPPER_ENV_VAR_KEYS]
env_var_keys = wrapper.WRAPPER_ENV_VAR_KEYS + missing_env

expected_cmds = []
for idx in range(0, 3):
for idx in range(0, len(input_files)):
expected_cmds.append(
f'{app_path} {input_files[idx]} "{grids[idx]}" {output_files[idx]}'
f' -field \'name="{input_name}"; level="{level}";\''
f' {extra_args}{verbosity}'
f' -config {config_file} {extra_args}{verbosity}'
)

all_cmds = wrapper.run_all_times()
Expand All @@ -154,3 +193,30 @@ def test_point2grid_run(metplus_config, config_overrides, optional_args):
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
# including deprecated env vars (not in wrapper env var keys)
for env_var_key in env_var_keys:
print(f"ENV VAR: {env_var_key}")
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


@pytest.mark.wrapper
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',
'Point2GridConfig_wrapped')

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

config.set('config', 'POINT2GRID_CONFIG_FILE', fake_config_name)
wrapper = Point2GridWrapper(config)
assert wrapper.c_dict['CONFIG_FILE'] == fake_config_name
Loading

0 comments on commit f35b6a5

Please sign in to comment.