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 1490 Python Embedding for Point Observations #1491

Merged
merged 8 commits into from
Mar 8, 2022
7 changes: 7 additions & 0 deletions .github/jobs/docker_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ export DOCKERFILE_PATH=${GITHUB_WORKSPACE}/scripts/docker/Dockerfile

MET_TAG=`${GITHUB_WORKSPACE}/scripts/docker/hooks/get_met_version`

MET_DOCKER_REPO=met-dev
if [ "${MET_TAG}" != "develop" ]; then
MET_DOCKER_REPO=met
fi

# if MET_FORCE_TAG variable is set and not empty, use that version instead
if [ ! -z "$MET_FORCE_TAG" ]; then
MET_TAG=$MET_FORCE_TAG
fi

echo Using MET_DOCKER_REPO=$MET_DOCKER_REPO
echo Using MET_TAG=$MET_TAG
echo Setting DOCKER_BUILDKIT=1
export DOCKER_BUILDKIT=1

time_command docker build --pull --cache-from ${DOCKERHUB_TAG} \
-t ${DOCKERHUB_TAG} \
--build-arg OBTAIN_SOURCE_CODE=copy \
--build-arg MET_DOCKER_REPO=$MET_DOCKER_REPO \
--build-arg MET_TAG=$MET_TAG \
-f ${DOCKERFILE_PATH} ${GITHUB_WORKSPACE}

Expand Down
5 changes: 5 additions & 0 deletions .github/parm/use_case_groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"index_list": "59",
"run": false
},
{
"category": "met_tool_wrapper",
"index_list": "60",
"run": true
},
{
"category": "air_quality_and_comp",
"index_list": "0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
"""
PointStat: Using Python Embedding for Point Observations
========================================================

met_tool_wrapper/PointStat/PointStat_python_embedding_obs.conf

"""
##############################################################################
# Scientific Objective
# --------------------
#
# Compare hourly forecasts for temperature, u-, and v-wind components to observations
# in a 3-hour observation window. Generate statistics of the results.
# Calls a Python Embedding script to read point observations.

##############################################################################
# Datasets
# --------
#
# | **Forecast:** NAM temperature, u-wind component, and v-wind component
# | **Observation:** prepBUFR data that has been converted to NetCDF format via PB2NC
#
# | **Location:** All of the input data required for this use case can be found in the met_test sample data tarball. Click here to the METplus releases page and download sample data for the appropriate release: https://github.com/dtcenter/METplus/releases
# | This tarball should be unpacked into the directory that you will set the value of INPUT_BASE. See `Running METplus`_ section for more information.
#
# | **Data Source:** Unknown
# |

##############################################################################
# METplus Components
# ------------------
#
# This use case utilizes the METplus PointStat wrapper to search for
# files that are valid at a given run time and generate a command to run
# the MET tool point_stat if all required files are found.
# This example demonstrates how to configure a use case to call a Python
# Embedding script to read in point observations into point_stat.

##############################################################################
# METplus Workflow
# ----------------
#
# PointStat is the only tool called in this example. It processes the following
# run times:
#
# | **Valid:** 2007-03-30_0Z
# |

##############################################################################
# METplus Configuration
# ---------------------
#
# METplus first loads all of the configuration files found in parm/metplus_config,
# then it loads any configuration files passed to METplus via the command line
# with the -c option, i.e. -c parm/use_cases/met_tool_wrapper/PointStat/PointStat_python_embedding_obs.conf
#
# .. highlight:: bash
# .. literalinclude:: ../../../../parm/use_cases/met_tool_wrapper/PointStat/PointStat_python_embedding_obs.conf

##############################################################################
# MET Configuration
# ---------------------
#
# METplus sets environment variables based on user settings in the METplus configuration file.
# See :ref:`How METplus controls MET config file settings<metplus-control-met>` for more details.
#
# **YOU SHOULD NOT SET ANY OF THESE ENVIRONMENT VARIABLES YOURSELF! THEY WILL BE OVERWRITTEN BY METPLUS WHEN IT CALLS THE MET TOOLS!**
#
# If there is a setting in the MET configuration file that is currently not supported by METplus you'd like to control, please refer to:
# :ref:`Overriding Unsupported MET config file settings<met-config-overrides>`
#
# .. note:: See the :ref:`PointStat MET Configuration<point-stat-met-conf>` section of the User's Guide for more information on the environment variables used in the file below:
#
# .. highlight:: bash
# .. literalinclude:: ../../../../parm/met_config/PointStatConfig_wrapped

##############################################################################
# Running METplus
# ---------------
#
# This use case can be run two ways:
#
# 1) Passing in PointStat_python_embedding_obs.conf then a user-specific system configuration file::
#
# run_metplus.py -c /path/to/METplus/parm/use_cases/met_tool_wrapper/PointStat/PointStat_python_embedding_obs.conf -c /path/to/user_system.conf
#
# 2) Modifying the configurations in parm/metplus_config, then passing in PointStat_python_embedding_obs.conf::
#
# run_metplus.py -c /path/to/METplus/parm/use_cases/met_tool_wrapper/PointStat/PointStat_python_embedding_obs.conf
#
# The former method is recommended. Whether you add them to a user-specific configuration file or modify the metplus_config files, the following variables must be set correctly:
#
# * **INPUT_BASE** - Path to directory where sample data tarballs are unpacked (See Datasets section to obtain tarballs). This is not required to run METplus, but it is required to run the examples in parm/use_cases
# * **OUTPUT_BASE** - Path where METplus output will be written. This must be in a location where you have write permissions
# * **MET_INSTALL_DIR** - Path to location where MET is installed locally
#
# Example User Configuration File::
#
# [dir]
# INPUT_BASE = /path/to/sample/input/data
# OUTPUT_BASE = /path/to/output/dir
# MET_INSTALL_DIR = /path/to/met-X.Y
#
# **NOTE:** All of these items must be found under the [dir] section.
#

##############################################################################
# Expected Output
# ---------------
#
# A successful run will output the following both to the screen and to the logfile::
#
# INFO: METplus has successfully finished running.
#
# Refer to the value set for **OUTPUT_BASE** to find where the output data was generated.
# Output for this use case will be found in point_stat_py_embed_obs
# (relative to **OUTPUT_BASE**) and will contain the following files:
#
# * point_stat_360000L_20070331_120000V.stat

##############################################################################
# Keywords
# --------
#
# .. note::
#
# * PointStatToolUseCase
# * PythonEmbeddingFileUseCase
#
# Navigate to the :ref:`quick-search` page to discover other similar use cases.
#
#
#
# sphinx_gallery_thumbnail_path = '_static/met_tool_wrapper-PointStat.png'
#
1 change: 1 addition & 0 deletions internal_tests/use_cases/all_use_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Category: met_tool_wrapper
57::GFDLTracker_Genesis::met_tool_wrapper/GFDLTracker/GFDLTracker_Genesis.conf::gfdl-tracker_env
58::GenEnsProd::met_tool_wrapper/GenEnsProd/GenEnsProd.conf
59::IODA2NC::met_tool_wrapper/IODA2NC/IODA2NC.conf
60::PointStat_python_embedding_obs:: met_tool_wrapper/PointStat/PointStat_python_embedding_obs.conf

Category: air_quality_and_comp
0::EnsembleStat_fcstICAP_obsMODIS_aod::model_applications/air_quality_and_comp/EnsembleStat_fcstICAP_obsMODIS_aod.conf
Expand Down
6 changes: 6 additions & 0 deletions metplus/util/met_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,12 @@ def preprocess_file(filename, data_type, config, allow_dir=False):
if os.path.basename(filename) in PYTHON_EMBEDDING_TYPES:
return os.path.basename(filename)

# if filename starts with a python embedding type, return the full value
for py_embed_type in PYTHON_EMBEDDING_TYPES:
if filename.startswith(py_embed_type):
return filename

# if _INPUT_DATATYPE value contains PYTHON, return the full value
if data_type is not None and 'PYTHON' in data_type:
return filename

Expand Down
10 changes: 8 additions & 2 deletions metplus/wrappers/compare_gridded_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,16 @@ def get_command(self):
return None

# add forecast file
cmd += self.infiles[0] + ' '
fcst_file = self.infiles[0]
if fcst_file.startswith('PYTHON'):
fcst_file = f"'{fcst_file}'"
cmd += f'{fcst_file} '

# add observation file
cmd += self.infiles[1] + ' '
obs_file = self.infiles[1]
if obs_file.startswith('PYTHON'):
obs_file = f"'{obs_file}'"
cmd += f'{obs_file} '

if self.param == '':
self.log_error('Must specify config file to run MET tool')
Expand Down
2 changes: 2 additions & 0 deletions metplus/wrappers/ensemble_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ def get_command(self):
cmd += self.param + " "

for obs_file in self.point_obs_files:
if obs_file.startswith('PYTHON'):
obs_file = f"'{obs_file}'"
cmd += "-point_obs " + obs_file + " "

for obs_file in self.grid_obs_files:
Expand Down
2 changes: 2 additions & 0 deletions metplus/wrappers/point2grid_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def get_command(self):

# add input files
for infile in self.infiles:
if infile.startswith('PYTHON'):
infile = f"'{infile}'"
cmd += ' ' + infile

# add grid name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
[config]

PROCESS_LIST = PointStat

###
# Time Info
###

LOOP_BY = INIT
INIT_TIME_FMT = %Y%m%d
INIT_BEG = 20070330
INIT_END = 20070330
INIT_INCREMENT = 1M

LEAD_SEQ = 36

###
# File I/O
###

FCST_POINT_STAT_INPUT_DIR = {INPUT_BASE}/met_test/data/sample_fcst
FCST_POINT_STAT_INPUT_TEMPLATE = {init?fmt=%Y%m%d%H}/nam.t00z.awip1236.tm00.{init?fmt=%Y%m%d}.grb

OBS_POINT_STAT_INPUT_DIR =
OBS_POINT_STAT_INPUT_TEMPLATE = PYTHON_NUMPY= {MET_INSTALL_DIR}/share/met/python/read_met_point_obs.py {INPUT_BASE}/met_test/out/pb2nc/sample_pb.nc

POINT_STAT_OUTPUT_DIR = {OUTPUT_BASE}/point_stat_py_embed_obs

POINT_STAT_CLIMO_MEAN_INPUT_DIR =
POINT_STAT_CLIMO_MEAN_INPUT_TEMPLATE =

POINT_STAT_CLIMO_STDEV_INPUT_DIR =
POINT_STAT_CLIMO_STDEV_INPUT_TEMPLATE =

###
# Field Info
###

POINT_STAT_ONCE_PER_FIELD = False

#POINT_STAT_FCST_FILE_TYPE =
#POINT_STAT_OBS_FILE_TYPE =

FCST_VAR1_NAME = TMP
FCST_VAR1_LEVELS = P750-900
FCST_VAR1_THRESH = <=273, >273
OBS_VAR1_NAME = TMP
OBS_VAR1_LEVELS = P750-900
OBS_VAR1_THRESH = <=273, >273

FCST_VAR2_NAME = UGRD
FCST_VAR2_LEVELS = Z10
FCST_VAR2_THRESH = >=5
OBS_VAR2_NAME = UGRD
OBS_VAR2_LEVELS = Z10
OBS_VAR2_THRESH = >=5

FCST_VAR3_NAME = VGRD
FCST_VAR3_LEVELS = Z10
FCST_VAR3_THRESH = >=5
OBS_VAR3_NAME = VGRD
OBS_VAR3_LEVELS = Z10
OBS_VAR3_THRESH = >=5

###
# PointStat
###

#LOG_POINT_STAT_VERBOSITY = 2

POINT_STAT_CONFIG_FILE ={PARM_BASE}/met_config/PointStatConfig_wrapped

#POINT_STAT_OBS_QUALITY_INC = 1, 2, 3
#POINT_STAT_OBS_QUALITY_EXC =

POINT_STAT_CLIMO_MEAN_TIME_INTERP_METHOD = NEAREST
#POINT_STAT_CLIMO_STDEV_TIME_INTERP_METHOD =

#POINT_STAT_INTERP_VLD_THRESH =
#POINT_STAT_INTERP_SHAPE =
POINT_STAT_INTERP_TYPE_METHOD = BILIN
POINT_STAT_INTERP_TYPE_WIDTH = 2

#POINT_STAT_OUTPUT_FLAG_FHO =
#POINT_STAT_OUTPUT_FLAG_CTC =
#POINT_STAT_OUTPUT_FLAG_CTS =
#POINT_STAT_OUTPUT_FLAG_MCTC =
#POINT_STAT_OUTPUT_FLAG_MCTS =
#POINT_STAT_OUTPUT_FLAG_CNT =
POINT_STAT_OUTPUT_FLAG_SL1L2 = STAT
#POINT_STAT_OUTPUT_FLAG_SAL1L2 =
POINT_STAT_OUTPUT_FLAG_VL1L2 = STAT
#POINT_STAT_OUTPUT_FLAG_VAL1L2 =
#POINT_STAT_OUTPUT_FLAG_VCNT =
#POINT_STAT_OUTPUT_FLAG_PCT =
#POINT_STAT_OUTPUT_FLAG_PSTD =
#POINT_STAT_OUTPUT_FLAG_PJC =
#POINT_STAT_OUTPUT_FLAG_PRC =
#POINT_STAT_OUTPUT_FLAG_ECNT =
#POINT_STAT_OUTPUT_FLAG_RPS =
#POINT_STAT_OUTPUT_FLAG_ECLV =
#POINT_STAT_OUTPUT_FLAG_MPR =
#POINT_STAT_OUTPUT_FLAG_ORANK =

#POINT_STAT_CLIMO_CDF_BINS = 1
#POINT_STAT_CLIMO_CDF_CENTER_BINS = False
#POINT_STAT_CLIMO_CDF_WRITE_BINS = True
#POINT_STAT_CLIMO_CDF_DIRECT_PROB =

#POINT_STAT_HSS_EC_VALUE =

OBS_POINT_STAT_WINDOW_BEGIN = -5400
OBS_POINT_STAT_WINDOW_END = 5400

POINT_STAT_OFFSETS = 0

MODEL = WRF

POINT_STAT_DESC = NA
OBTYPE =

POINT_STAT_REGRID_TO_GRID = NONE
POINT_STAT_REGRID_METHOD = BILIN
POINT_STAT_REGRID_WIDTH = 2

POINT_STAT_OUTPUT_PREFIX =

#POINT_STAT_OBS_VALID_BEG = {valid?fmt=%Y%m%d_%H}
#POINT_STAT_OBS_VALID_END = {valid?fmt=%Y%m%d_%H}

POINT_STAT_MASK_GRID = DTC165, DTC166
POINT_STAT_MASK_POLY = MET_BASE/poly/LMV.poly
POINT_STAT_MASK_SID =
#POINT_STAT_MASK_LLPNT =

POINT_STAT_MESSAGE_TYPE = ADPUPA, ADPSFC

#POINT_STAT_HIRA_FLAG =
#POINT_STAT_HIRA_WIDTH =
#POINT_STAT_HIRA_VLD_THRESH =
#POINT_STAT_HIRA_COV_THRESH =
#POINT_STAT_HIRA_SHAPE =
#POINT_STAT_HIRA_PROB_CAT_THRESH =

#POINT_STAT_MESSAGE_TYPE_GROUP_MAP =
Loading