METplus Practical Session Guide (Version 5.0) | Session 9: Python Embedding > Python Embedding for Point Data

A Simple Point Data Example with MET Tools

To demonstrate how to use Python Embedding for point data, you will use some test data included with the MET installation, the MET plot_point_obs tool, and the sample Python Embedding script named that you created earlier in this session. There are three required elements to the command for using Python Embedding with plot_point_obs:

  1. The path to the plot_point_obs MET executable
  2. The plot_point_obs nc_file argument, modified for Python Embedding
  3. The plot_point_obs ps_file argument

Let's build the command!

Element 1: Use your tutorial environment variable MET_BUILD_BASE to access plot_point_obs:


Element 2: The nc_file argument for plot_point_obs. The nc_file argument is typically the path to a netCDF data file containing point observations in a specific MET format created by a MET tool like pb2nc. However, you can also replace this argument with the path to a Python Embedding script. Unlike the gridded data example above, the Python Embedding keyword is included with the Python Embedding script rather than as a separate command line element. Since you are using point data, you will use PYTHON_NUMPY as the Python Embedding keyword. The Python Embedding script being used here only takes a single argument that is the path to the input data file:

" {METPLUS_DATA}/met_test/data/sample_obs/ascii/sample_ascii_obs.txt"

Element 3: Choose your own output filename. The plot_point_obs tool outputs an image in PostScript format so typically the filename will end with ".ps":

Let's run the command!

Verify you are in the Python Embedding practice directory:

cd ${METPLUS_TUTORIAL_DIR}/python_embed

Copy each of the four elements from above to construct the full Python Embedding command for plot_data_plane:

${MET_BUILD_BASE}/bin/plot_point_obs "PYTHON_NUMPY=${METPLUS_TUTORIAL_DIR}/python_embed/ ${METPLUS_DATA}/met_test/data/sample_obs/ascii/sample_ascii_obs.txt"

View the output image

The output file is a PostScript graphic file that typically can only be viewed with certain software. If you do not have a display tool that can view PostScript files, you can use the ImageMagick convert command to convert to a PNG file type which may be easier to view:

convert -rotate 90 -background white my_point_pyembed_plot.png

A Simple Point Data Example with METplus Wrappers

Now instead of using plot_point_obs directly, you will practice the above example using the METplus Wrappers. For each of the three elements shown above, the equivalent configuration items for METplus Wrappers will be described. But first, you will need to set up a basic METplus Wrappers configuration file:

Verify you are in the Python Embedding practice directory:

cd ${METPLUS_TUTORIAL_DIR}/python_embed

Open a new file named my_point_pyembed.conf with a text editor:

vi my_point_pyembed.conf

Some basic elements are required to get the METplus wrappers to run. For this example, you need to provide some time looping information despite not actually looping over those times. You also need to provide a top-level output directory (OUTPUT_BASE):


For Element 1 above, the METplus Wrappers will find plot_point_obs through the MET_INSTALL_DIR and PROCESS_LIST configuration items:


For Element 2 above, we will use the PLOT_POINT_OBS_INPUT_TEMPLATE configuration item:

PLOT_POINT_OBS_INPUT_TEMPLATE=PYTHON_NUMPY={ENV[METPLUS_TUTORIAL_DIR]}/python_embed/ {ENV[METPLUS_DATA]}/met_test/data/sample_obs/ascii/sample_ascii_obs.txt

For Element 3 above, we will use the PLOT_POINT_OBS_OUTPUT_TEMPLATE configuration item:


Now save the file, and run METplus wrappers: -c my_point_pyembed.conf

You can verify that the output image (which is found in your METplus OUTPUT_BASE) directory, exactly matches the image above when using plot_point_obs directly.

Congratulations! You've run Python Embedding for point data using MET tools directly and with METplus Wrappers. Continue to the next section to practice writing your own Python Embedding script.