...
- 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:
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)
- 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:
...
Macro | Python |
---|
Code Block |
---|
| # Metview Macro
# creating
d = 2000-01-04 09:50:24
today = date(0)
yesterday = date(-1)
# arithmetic
d = d + hour(9) + minute(50) + second(24)
# using an increment of 2 days
for d = 2018-11-01 to 2018-11-10 by 2 do
(...)
end for
# using an increment of 6 hours
for d = 2018-11-01 to 2018-11-10 by hour(6) do
x = retrieve(
date : yymmdd(d),
time : hhmm(d),
...)
(...)
end for |
|
Code Block |
---|
| import metview as mv
import numpy as np
from datetime import datetime, timedelta
# creating
d = datetime(2000, 1, 4, 9, 50, 24)
today = datetime.today()
yesterday = datetime.today() - timedelta(1)
# arithmetic
d = d + timedelta(hours=9, minutes=50, seconds=24)
# using an increment of 2 days
d0 = datetime(2018,11,1)
d1 = datetime(2018,11,10)
dt = timedelta(days = 2)
for d in np.arange(d0, d1, dt):
(...)
# using an increment of 6 hours
d0 = datetime(2018, 11, 1)
d1 = datetime(2018, 11, 10)
dt = timedelta(hours = 6)
for d = np.arange(d0, d1, dt):
x = mv.retrieve(date =d,
time = dmv.hour(d), ...)
(...) |
|
Additional data export features
...