Metview's documentation is now on readthedocs!

Here are some different ways that you can use Metview's Python interface. Make sure you have set up your environment first.

Text editor and command line

Perhaps the simplest - just use any text editor to edit the Python code and run it from the command line, e.g.

python3 my_metv_python_script.py

Python IDE

Python IDEs, such as PyCharm, provide an interactive environment and even debugging facilities.

Jupyter notebook

A Jupyter notebook provides an interactive workspace combining code, plots and documentation. It runs in a web browser and can be started from the command-line as follows:

jupyter notebook

This command will open a new tab in your web browser, or you can copy the URL yourself.

Now, create a new Notebook using the New menu and selecting Python 3:

You can start typing your code into the cells. Press CTRL-Return to execute the code in the current cell, or SHIFT-Return to execute and move to the next code cell. The Kernel menu allows the restart of a session. To generate plots inside the notebook, call

mv.setoutput('jupyter')

at some point before calling the plot() command. By default, plots will go to an interactive Metview plot window unless this is done.

mv.setoutput('jupyter') for inline plotsWith no setoutput command, an interactive plot window

A Metview session

A Metview Python script can be created, edited and run from within an interactive Metview session in the same way that a Metview Macro can.

From the main user interface, right-click on an empty part of the Metview desktop, select Create New Icon and choose Python Script.

You can either just start writing your Python code, or you can use Metview to help you. Any Metview icons can be dropped into Metview's Code Editor, and the corresponding Python code will be automatically generated for you, giving a convenient way of trying things out interactively before committing them to code.

Pressing the Run button will invoke the Python interpreter (whatever the python3 command runs) and show output in the bottom panel.


2 Comments

  1. What version of metview does one need to be running to get the option to create a python script from the 'Create new icon menu'?

  2. You need Metview 5.0.3