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 #2540 Point2Grid config file #2580

Merged
merged 9 commits into from
Oct 10, 2024
66 changes: 65 additions & 1 deletion docs/Users_Guide/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ 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_GOES_QC_FLAGS`.

| *Used by:* Point2Grid

POINT2GRID_GOES_QC_FLAGS
Sets the value for the -goes_qc command line argument for Point2Grid.

| *Used by:* Point2Grid

Expand Down Expand Up @@ -11624,6 +11629,46 @@ METplus Configuration Glossary

| *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_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

MADIS2NC_CUSTOM_LOOP_LIST
Sets custom string loop list for a specific wrapper. See :term:`CUSTOM_LOOP_LIST`.

Expand Down Expand Up @@ -11912,6 +11957,25 @@ METplus Configuration Glossary

| *Used by:* WaveletStat

POINT2GRID_TIME_OFFSET_WARNING
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgemccabe the time_offset_warning config option only applies to MET tools that do a grid-to-grid comparison. Doing some grepping, I only see calls to this time_offset_warning(...) function from wavelet_stat, mode, series_analysis, pcp_combine, grid_stat, and wwmca.

So it definitely doesn't impact point2grid. Not sure how to handle this.

Specify the value for 'time_offset_warning' in the MET configuration file for Point2Grid.

| *Used by:* Point2Grid

POINT2GRID_MET_CONFIG_OVERRIDES
Override any variables in the MET configuration file that are not
supported by the wrapper. This should be set to the full variable name
and value that you want to override, including the equal sign and the
ending semi-colon. The value is directly appended to the end of the
wrapped MET config file.

Example:
POINT2GRID_MET_CONFIG_OVERRIDES = desc = "override_desc"; model = "override_model";

See :ref:`Overriding Unsupported MET config file settings<met-config-overrides>` for more information

| *Used by:* Point2Grid

ASCII2NC_VALID_BEG
Specify the value for the command line argument '-valid_beg' for ASCII2NC.

Expand Down
141 changes: 140 additions & 1 deletion docs/Users_Guide/wrappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6862,7 +6862,7 @@ METplus Configuration
| :term:`POINT2GRID_REGRID_TO_GRID`
| :term:`POINT2GRID_INPUT_FIELD`
| :term:`POINT2GRID_INPUT_LEVEL`
| :term:`POINT2GRID_QC_FLAGS`
| :term:`POINT2GRID_GOES_QC_FLAGS`
| :term:`POINT2GRID_ADP`
| :term:`POINT2GRID_REGRID_METHOD`
| :term:`POINT2GRID_GAUSSIAN_DX`
Expand All @@ -6875,8 +6875,147 @@ 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_OBS_QUALITY_INC`
| :term:`POINT2GRID_OBS_QUALITY_EXC`
| :term:`POINT2GRID_TIME_OFFSET_WARNING`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should add POINT2GRID_TIME_OFFSET_WARNING since it isn't actually being used.

| :term:`POINT2GRID_MET_CONFIG_OVERRIDES`
|

.. 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_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

${METPLUS_TIME_OFFSET_WARNING}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_TIME_OFFSET_WARNING`
- time_offset_warning

${METPLUS_MET_CONFIG_OVERRIDES}
"""""""""""""""""""""""""""""""

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

* - METplus Config(s)
- MET Config File
* - :term:`POINT2GRID_MET_CONFIG_OVERRIDES`
- n/a

.. _point_stat_wrapper:

PointStat
Expand Down
96 changes: 81 additions & 15 deletions internal/tests/pytests/wrappers/point2grid/test_point2grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,58 @@ 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_REGRID_TO_GRID': 'lambert 614 428 12.190 -133.459 -95.0 12.19058 6367.47 25.0 N'}, []),
({'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_REGRID_TO_GRID': 'lambert 614 428 12.190 -133.459 -95.0 12.19058 6367.47 25.0 N'}, {}, []),
({'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_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_GOES_QC_FLAGS': '0,1'}, {}, ['-goes_qc 0,1']),
({'POINT2GRID_QC_FLAGS': '0,1'}, {}, ['-goes_qc 0,1']),
({'POINT2GRID_GOES_QC_FLAGS': '0,1', 'POINT2GRID_QC_FLAGS': '2,3'}, {}, ['-goes_qc 0,1']),
({'POINT2GRID_TIME_OFFSET_WARNING': '5', },
{'METPLUS_TIME_OFFSET_WARNING': 'time_offset_warning = 5;'}, []),

]
)
@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 @@ -143,13 +176,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 @@ -158,3 +197,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