5.1.12.1. MTD using Python Embedding

met_tool_wrapper/MTD/MTD_python_embedding.conf

Scientific Objective

Compare forecast and observation 3 hour precipitation accumulation spatially and temporally over the 6 hour, 9 hour, and 12 hour forecast leads.

Datasets

Forecast: Dummy text files found in the MET shared directory
Observation: Dummy text files found in the MET shared directory
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.

METplus Components

This use case utilizes the METplus MTD wrapper to read in files using Python Embedding to demonstrate how to read in data this way.

METplus Workflow

MTD is the only tool called in this example. It processes a single run time with three forecast leads. The input data are simple text files with no timing information, so the list of forecast leads simply duplicates the same file multiple times to demonstrate how data is read in via Python Embedding.

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/MTD/MTD_python_embedding.conf

# MTD (MODE Time Domain) using Python Embedding METplus Configuration

[config]

# List of applications to run - only MTD for this case
PROCESS_LIST = MTD

# time looping - options are INIT, VALID, RETRO, and REALTIME
# If set to INIT or RETRO:
#   INIT_TIME_FMT, INIT_BEG, INIT_END, and INIT_INCREMENT must also be set
# If set to VALID or REALTIME:
#   VALID_TIME_FMT, VALID_BEG, VALID_END, and VALID_INCREMENT must also be set
LOOP_BY = INIT

# Format of INIT_BEG and INT_END using % items
# %Y = 4 digit year, %m = 2 digit month, %d = 2 digit day, etc.
# see www.strftime.org for more information
# %Y%m%d%H expands to YYYYMMDDHH
INIT_TIME_FMT = %Y%m%d%H

# Start time for METplus run - must match INIT_TIME_FMT
INIT_BEG=2005080700

# End time for METplus run - must match INIT_TIME_FMT
INIT_END=2005080700

# Increment between METplus runs (in seconds if no units are specified)
#  Must be >= 60 seconds
INIT_INCREMENT=1M

# List of forecast leads to process for each run time (init or valid)
# In hours if units are not specified
# If unset, defaults to 0 (don't loop through forecast leads)
LEAD_SEQ = 0, 1, 2


# Order of loops to process data - Options are times, processes
# Not relevant if only one item is in the PROCESS_LIST
# times = run all wrappers in the PROCESS_LIST for a single run time, then
#   increment the run time and run all wrappers again until all times have
#   been evaluated.
# processes = run the first wrapper in the PROCESS_LIST for all times
#   specified, then repeat for the next item in the PROCESS_LIST until all
#   wrappers have been run
LOOP_ORDER = times

# if true, only process a single data set with MTD
MTD_SINGLE_RUN = False

# Data to process in single mode
# FCST and OBS are valid options
MTD_SINGLE_DATA_SRC = OBS

# forecast convolution radius list
FCST_MTD_CONV_RADIUS = 0

# forecast convolution threshold list
FCST_MTD_CONV_THRESH = >=10

# observation convolution radius list
OBS_MTD_CONV_RADIUS = 15

# observation convolution threshold list
OBS_MTD_CONV_THRESH = >=1.0

# list of variables to compare
FCST_VAR1_NAME = {MET_INSTALL_DIR}/share/met/python/read_ascii_numpy.py MET_PYTHON_INPUT_ARG FCST

OBS_VAR1_NAME = {MET_INSTALL_DIR}/share/met/python/read_ascii_numpy.py MET_PYTHON_INPUT_ARG OBS

FCST_MTD_INPUT_DATATYPE = PYTHON_NUMPY

OBS_MTD_INPUT_DATATYPE = PYTHON_NUMPY


# description of data to be processed
# used in output file path
MODEL = FCST
OBTYPE = OBS

#MTD_DESC =

# location of MODE Time Domain MET config file
# References CONFIG_DIR from the [dir] section
MTD_CONFIG_FILE = {CONFIG_DIR}/MTDConfig_wrapped

# grid to remap data. Value is set as the 'to_grid' variable in the 'regrid' dictionary
# See MET User's Guide for more information
MTD_REGRID_TO_GRID = OBS

# Minimum volume
FCST_MTD_MIN_VOLUME = 2000

# convolution radius for forecast data
FCST_MTD_CONV_RADIUS = 15

# convolution threshold for forecast data
FCST_MTD_CONV_THRESH = >=5.0

# output prefix to add to output filenames
MTD_OUTPUT_PREFIX = PYTHON

# set to True if forecast data is probabilistic
FCST_IS_PROB = false

# True if probabilistic information is in the GRIB Product Definition Section
FCST_PROB_IN_GRIB_PDS = false

# End of [config] section and start of [dir] section
[dir]
# location of configuration files used by MET applications
CONFIG_DIR={PARM_BASE}/met_config

# input and output data directories for each application in PROCESS_LIST
FCST_MTD_INPUT_DIR = {INPUT_BASE}/met_test/data/python

OBS_MTD_INPUT_DIR = {INPUT_BASE}/met_test/data/python

MTD_OUTPUT_DIR = {OUTPUT_BASE}/met_tool_wrapper/MTD/mtd_python_embedding

# End of [dir] section and start of [filename_templates] section
[filename_templates]
# format of filenames

FCST_MTD_INPUT_TEMPLATE= fcst.txt

OBS_MTD_INPUT_TEMPLATE = obs.txt

MTD_OUTPUT_TEMPLATE =

MET Configuration

METplus sets environment variables based on user settings in the METplus configuration file. See How METplus controls MET config file settings 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: Overriding Unsupported MET config file settings

Note

See the MTD MET Configuration section of the User’s Guide for more information on the environment variables used in the file below:

////////////////////////////////////////////////////////////////////////////////
//
// MODE Time Domain configuration file.
//
// For additional information, see the MET_BASE/config/README file.
//
////////////////////////////////////////////////////////////////////////////////

   //
   // Output model name to be written
   //

${METPLUS_MODEL}

   //
   // Output description to be written
   //

${METPLUS_DESC}

   //
   // Output observation type to be written
   //

${METPLUS_OBTYPE}

////////////////////////////////////////////////////////////////////////////////

   //
   //  Verification grid
   //  May be set separately in each "field" entry
   //
${METPLUS_REGRID_DICT}

////////////////////////////////////////////////////////////////////////////////

   //
   // Approximate grid resolution (km)
   //

grid_res = 4;

////////////////////////////////////////////////////////////////////////////////

   //
   // Forecast and observation fields to be verified
   //

fcst = {

   ${METPLUS_FCST_FILE_TYPE}

   ${METPLUS_FCST_FIELD}

   censor_thresh     = [];
   censor_val        = [];
   conv_time_window  = { beg = -1; end = 1; };
   ${METPLUS_FCST_CONV_RADIUS}
   ${METPLUS_FCST_CONV_THRESH}

}

obs = {

   ${METPLUS_OBS_FILE_TYPE}

   ${METPLUS_OBS_FIELD}

   censor_thresh     = [];
   censor_val        = [];
   conv_time_window  = { beg = -1; end = 1; };
   ${METPLUS_OBS_CONV_RADIUS}
   ${METPLUS_OBS_CONV_THRESH}
}

////////////////////////////////////////////////////////////////////////////////

   //
   // Intensity percentile value to be written
   //

inten_perc_value = 99;

////////////////////////////////////////////////////////////////////////////////

   //
   //  Throw away 3D objects with volumes smaller than this
   //
${METPLUS_MIN_VOLUME}


////////////////////////////////////////////////////////////////////////////////

   //
   // Fuzzy engine weights
   //

weight = {

   space_centroid_dist  = 1.0;

   time_centroid_delta  = 1.0;

   speed_delta          = 1.0;

   direction_diff       = 1.0;

   volume_ratio         = 1.0;

   axis_angle_diff      = 1.0;

   start_time_delta     = 1.0;

   end_time_delta       = 1.0;

}

////////////////////////////////////////////////////////////////////////////////

   //
   // Fuzzy engine interest functions
   //

interest_function = {

   space_centroid_dist = (

      (   0.0, 1.0 )
      (  50.0, 0.5 )
      ( 100.0, 0.0 )

   );

   time_centroid_delta = (

      ( -3.0, 0.0 )
      ( -2.0, 0.5 )
      ( -1.0, 0.8 )
      (  0.0, 1.0 )
      (  1.0, 0.8 )
      (  2.0, 0.5 )
      (  3.0, 0.0 )

   );

   speed_delta = (

      ( -10.0, 0.0 )
      (  -5.0, 0.5 )
      (   0.0, 1.0 )
      (   5.0, 0.5 )
      (  10.0, 0.0 )

   );

   direction_diff = (

      (   0.0, 1.0 )
      (  90.0, 0.0 )
      ( 180.0, 0.0 )

   );

   volume_ratio = (

      (  0.0, 0.0 )
      (  0.5, 0.5 )
      (  1.0, 1.0 )
      (  1.5, 0.5 )
      (  2.0, 0.0 )

   );

   axis_angle_diff = (

      (  0.0, 1.0 )
      ( 30.0, 1.0 )
      ( 90.0, 0.0 )

   );

   start_time_delta = (

      ( -5.0, 0.0 )
      ( -3.0, 0.5 )
      (  0.0, 1.0 )
      (  3.0, 0.5 )
      (  5.0, 0.0 )

   );

   end_time_delta = (

      ( -5.0, 0.0 )
      ( -3.0, 0.5 )
      (  0.0, 1.0 )
      (  3.0, 0.5 )
      (  5.0, 0.0 )

   );

}   //  interest functions


////////////////////////////////////////////////////////////////////////////////

   //
   // Total interest threshold for determining matches
   //

total_interest_thresh = 0.7;


////////////////////////////////////////////////////////////////////////////////

   //
   // Output flags
   //

nc_output = {

   latlon       = true;
   raw          = true;
   object_id    = true;
   cluster_id   = true;

}

txt_output = {

   attributes_2d   = true;
   attributes_3d   = true;

}


////////////////////////////////////////////////////////////////////////////////

${METPLUS_OUTPUT_PREFIX}
//version        = "V9.0";

////////////////////////////////////////////////////////////////////////////////

${METPLUS_MET_CONFIG_OVERRIDES}

Python Embedding

This use case calls a Python script to read the input data. The Python script is stored in the MET repository: /path/to/MET/installation/share/met/python/read_ascii_numpy.py

read_ascii_numpy.py

Running METplus

This use case can be run two ways:

  1. Passing in MTD_python_embedding.conf then a user-specific system configuration file:

    run_metplus.py -c /path/to/METplus/parm/use_cases/met_tool_wrapper/MTD/MTD_python_embedding.conf -c /path/to/user_system.conf
    
  2. Modifying the configurations in parm/metplus_config, then passing in MTD_python_embedding.conf:

    run_metplus.py -c /path/to/METplus/parm/use_cases/met_tool_wrapper/MTD/MTD_python_embedding.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 met_tool_wrapper/MTD/mtd_python_embedding (relative to OUTPUT_BASE) and will contain the following files:

  • mtd_PYTHON_20050807_120000V_2d.txt

  • mtd_PYTHON_20050807_120000V_3d_pair_cluster.txt

  • mtd_PYTHON_20050807_120000V_3d_pair_simple.txt

  • mtd_PYTHON_20050807_120000V_3d_single_cluster.txt

  • mtd_PYTHON_20050807_120000V_3d_single_simple.txt

  • mtd_PYTHON_20050807_120000V_obj.nc

Keywords

sphinx_gallery_thumbnail_path = ‘_static/met_tool_wrapper-MTD.png’

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery