MET Online Tutorial for METv8.0 | Python Embedding

Python Embedding Functionality

As of version 8.0, MET includes the ability to embed Python to a limited degree. Users may use scripts and any associated Python packages in order to prepare 2D gridded data fields for reading by the MET tools. The degree of embedding is expected increase in the future. Plans are in place to extend Python with MET in upcoming releases, allowing users to invoke MET tools directly from their Python script.

Currently, only the use of Python 2.7 is supported, but support will be extended to Python 3 in the future.

The compilation of Python embedding is disabled by default. If you did not configure MET with --enable-python, you may proceed to the next section, or go back and reconfigure and reinstall MET. If compiling support for Python embedding, be sure set $MET_PYTHON_CC and $MET_PYTHON_LD before running configure as described in the "Set Environment Variables" section on the Compilation page of this tutorial. For more detailed information on the Python embedding functionality, see Appendix F in the METv8.0 User's Guide.

Python Embedding Usage

Currently, MET offers two ways to interact with Python scripts: by using NumPy arrays or Xarray objects. The user's scripts can use any Python libraries that are desired in order to implement the Python script, so long as the data has been loaded into either a NumPy array or an Xarray object by the end of the script. This offers advantages when using data file formats that MET does not directly support. If there is Python code to read the data format, the user can use those tools to read the data, and then copy the data into a NumPy array or an Xarray object. MET can then ingest the data via the Python script. Note that whether a NumPy array or an Xarray object is used, the data should be stored as double precision floating point numbers. Using different data types, such as integers or single precision floating point numbers, will lead to unexpected results in MET.

The interface to be used (NumPy or Xarray) is specified on the command line. Python embedding can be used with any MET tool that reads 2-D data. This functionality is used when replacing the path to a gridded data file with PYTHON_NUMPY or PYTHON_XARRAY. Additionally, the "name" entry specifies the Python command that should be executed to read the data. The "level" entry is not required for Python. For example:

field = [ { name = " data/python/fcst.txt FCST"; } ];