Time component¶
Every Field carries a time component that describes the
temporal coordinate of the field. The time component is accessible via the time attribute
of a field and is represented by a subclass of
TimeBase.
>>> import earthkit.data as ekd
>>> field = ekd.from_source("sample", "test.grib").to_fieldlist()[0]
>>> field.time.base_datetime()
datetime.datetime(2020, 1, 1, 0, 0)
>>> field.time.step()
datetime.timedelta(0)
>>> field.time.valid_datetime()
datetime.datetime(2020, 1, 1, 0, 0)
The same information is available through the generic get()
interface using the "time." prefix:
>>> field.get("time.base_datetime")
datetime.datetime(2020, 1, 1, 0, 0)
>>> field.get("time.step")
datetime.timedelta(0)
The time component is immutable. Use the
set() method (or
set() on the field) to derive a modified copy:
>>> new_field = field.set({"time.step": 6})
>>> new_field.time.step()
datetime.timedelta(seconds=21600)
Time types¶
The appropriate time subclass is determined automatically from the data:
ForecastTime— standard forecast time defined by a base datetime and a forecast step. The valid datetime is computed asbase_datetime + step.MonthlyForecastTime— monthly forecast time that also carries aforecast_monthvalue.
Accessing time information¶
All time keys are accessible through get() with the
"time." prefix, and can therefore be used in
sel(),
order_by(), and
metadata().
Key |
Description |
|---|---|
|
The base (reference) datetime of the forecast as a |
|
Alias of |
|
The date part of the base datetime as a |
|
The time-of-day part of the base datetime as a |
|
The valid datetime ( |
|
The forecast step as a |
|
Alias of |
|
The forecast month as an integer. Only available for monthly forecast time; returns |
|
The indexing datetime used for ordering within a dataset. Returns |