Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Any Metview function that normally returns a vector will return a numPy array when called from Python. dtypes of float32 and float64 are supported. For example, the follownig fieldset functions return numPy arrays:

...

This is based on the Open Source cfgrib package which is planned to be ultimately integrated into xarray.

From version 0.8.6 of Metview's Python interface, it is also possible to convert an xarray dataset to a Metview Fieldset, and also to pass one directly to Metview functions. Note that this uses an experimental feature of cfgrib and will only work for a small subsset of xarray datasets. Examples:

Code Block
languagepy
grib = mv.read('temperature_on_pl.grib')
x = grib.to_dataset() # convert from Fieldset to dataset
f = mv.dataset_to_fieldset(x) # convert back to Fieldset


Code Block
languagepy
grib = mv.read('temperature_on_pl.grib')
x = grib.to_dataset() # x is now an xarray dataset
fs = mv.mean(x*2) # *2 is done by xarray, mean() is done by Metview

Icon functions

Macro functions which correspond to icons, such as retrieve(), which corresponds to the Mars Retrieval icon, can take their arguments in a number of ways:

...

  • Macro indexing starts at 1, but Python indexing starts at 0. Aside from the standard Python structures such as lists, this is also true for Metview Python classes such as Fieldset. Given a fieldset fs, the first field is obtained in Macro by fs[1], but in Python it is obtained by fs[0].
  • Some MARS requests require a class parameter. As class is a restricted keyword in Python, please use class_ in its place.
  • In order to support the more interactive coding environments provided by Python, any call to the plot() command will immediately produce a plot. This is different from Macro, where plots are delayed until the end. The result of this is that multiple plot() commands in Python will result in multiple plot windows. Fortunately, a single plot() command can be given any number of items, including multiple pages. To see how to produce a multi-plot layout, please see the Layoutx3 Example gallery example.
  • To produce multiple physical pages in a PostScript file, add calls to newpage() within the plot() command, e.g. plot(dw, data1, visdef1, newpage(), data2, visdef2).