Metview's documentation is now on readthedocs!

Complete documentation for Metview's Python interface is now available on readthedocs.

Metview's Python interface is currently available on internal ECMWF desktop machines, lxc and on the Member State server ecgate as well as the HPCF. It is also on github and PyPi and can be installed with the command "pip install metview".

Setup

To use it, you need two things:

  1. A Python 3 interpreter
  2. Metview 5 needs to be installed and in your PATH

So, to try it right now at ECMWF, do the following from a terminal:

module load python3

The internal installation at ECMWF also includes the cfgrib library for obtaining xarray datasets from GRIB. Metview's to_dataset() function uses this internally from version 0.8.4 onwards.

If you plan to use the cfgrib module directly, you should also ensure that the ecCodes library is in your LD_LIBRARY_PATH:

export LD_LIBRARY_PATH=$ECCODES_LIB_DIR:$LD_LIBRARY_PATH

Test it

To check that Metview's binary and Python parts can communicate with each other, type this

python3 -m metview selfcheck

Here's a quick Python program to check that it's working. Copy this into a file called test-metview.py

import metview as mv

# call Metview's built-in function to return a lower case string
print(mv.lowercase('Hello World!')) # should output "hello world!"

and run it like this:

python3 test-metview.py

If this works, then you have successfully set up Metview's Python interface!

Need more output?

Set the following environment variable before starting your Python interpreter, and you will see much more output from Metview:

export METVIEW_PYTHON_DEBUG=1

Want to use it with a different version of Metview?

On ECMWF machines you can choose a different version of Metview by using the 'module' command before starting your Python session, e.g.

module swap metview/new

Alternatively, you can set this environment variable to point to a specific Metview startup script before starting your Python session.:

export METVIEW_PYTHON_START_CMD=/path/to/my/metview_build/bin/metview


Running on a busy machine?

When you import metview, the Metview startup script is run in order to set up the working environment. Usually this is pretty much instant, but on very heavily loaded machines, it may take a few seconds. There is a default timeout of 8 seconds, but this can be increased if needed, by setting the following environment variable, to, for example, 15 seconds:

export METVIEW_PYTHON_START_TIMEOUT=15

Further reading

For a quick start, check out some of the examples in the Gallery. They all have Python code, and each contains a tarball containing its code and data.

Look at the Jupyter notebooks in the examples folder on github for more inspiration!

To see the different environments you can write Metview Python scripts in, see Developing and Running Metview Python Scripts.

To understand what Metview's functions take as input and output in a Python environment, see Using Metview's Python Interface.

7 Comments

  1. I have problem with Python interface.   For Python selfcheck command i get this result. home/oliver/Meteo/anaconda3/envs/ecmwf/bin/python: No module named metview.__main__; 'metview' is a package and cannot be directly executed

    1. Hi, did you "pip install metview" inside the conda env?  That's needed in order to get the Python interface.

      1. Hi. I installed outside conda env, that was the problem.  I installed now inside conda env, and works.  Thanks. 

  2. I had to add

    export LD_LIBRARY_PATH=/usr/lib/metview-bundle/lib64/
    to my environment, otherwise libMvMacro.so can not be found.

    1. Hi Hans, thanks for that. How did you install Metview, and on which platform, and do you know which version of Metview (binaries, not Python) you got?

      1. This was on OpenSUSE Leap 15.2 with Metview 5.9.1 from SStepke repositories.

        See also SUP-3267.

        1. Thanks for the info. I've looked into the RPMs for this, and everything looks correct, so I'll need to set up a virtual machine in order to find out exactly what's going on. In the meantime, thanks for supplying this tip for others to benefit from!