Info |
---|
Complete documentation for Metview's Python interface is now available on readthedocs! |
Metview's Python interface provides access to all of Metview's Macro language functions, with automatic translations between data types. Here's an example that shows how to retrieve model and observation data and compute their difference, and the weighted mean value of that difference, both in Macro and in Python.
...
Fieldsets work much the same as they do in the Macro language, but watch out for these things:
- length of a fieldset can be found with the
len
function:num_fields = len(my_fieldset)
- indexing starts at 0:
first_field = my_fieldset[0]
- slicing works:
my_fields = fs[0:6:2]
- you can pass a numpy array of indexes:
my_fields = fs[np.array([1.0, 2.0, 0.0, 5.0])]
- comparison operators work the same as in Macro, i.e. they return a fieldset of 1s and 0s: comparison operators work the same, i.e. they return a fieldset of 1s and 0s:
smaller = fs1 < fs2
- equality and non-equality operators are
==
and!=
- Fieldsets can be directly constructed either as empty, or with a path to a GRIB file:
f = mv.Fieldset()
f = mv.Fieldset(path='test.grib')
- concatenation can be done like this:
my_fieldset.append(my_other_fieldset)
- length of a fieldset can be found with the
len
function:num_fields = len(my_fieldset)
- slicing works:
my_fields = fs[0:6:2]
_fieldset)
- iteration works:
for f in my_fieldset: #do something
Working with Geopoints
Geopoints also work much the same as they do in Macro, but be aware of these points:
- in Macro, we use
geo_missing_value
to denote missing data values; in Python, we usenumpy.nan
Working with dates
There are several differences between the usage of the date object in Macro and the datetime object in Python. You will find a few examples below to compare the various date manipulation techniques used in Macro and Python, respectively.
Macro | Python | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Additional data export features
...
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 following fieldset functions return numPy arrays:
...