The object returned by from_source

[1]:
import earthkit.data as ekd

from_source returns a data object. This object provides some basic information about the data but its primary goal is to convert it to a given representation for further work. The actual data loading is deferred as much as possible, until the data is converted into a given type.

File sources

[2]:
d = ekd.from_source("file", "test.grib")
d
[2]:
GRIB file

pathtest.grib
size720
typesfieldlist, pandas, xarray, numpy, array

The “available types” tells us the types we can comvert the data into. This list is also available as a property on the data object.

[3]:
d.available_types
[3]:
['fieldlist', 'pandas', 'xarray', 'numpy', 'array']

To convert the data we need to call one of the “to_” methods. E.g we can convert our data into a fieldlist.

[4]:
fl = d.to_fieldlist()
fl.ls()
[4]:
parameter.variable time.valid_datetime time.base_datetime time.step vertical.level vertical.level_type ensemble.member geography.grid_type
0 2t 2020-05-13 12:00:00 2020-05-13 12:00:00 0 days 0 surface 0 regular_ll
1 msl 2020-05-13 12:00:00 2020-05-13 12:00:00 0 days 0 surface 0 regular_ll

Some conversions may involve other conversions under the hood. For example, when GRIB is converted to Xarray, first it is always loaded into a fieldlist then converted to Xarray.

[5]:
# this first loads the GRIB data into a fieldlist and converts that into Xarray
ds = d.to_xarray()
ds
[5]:
<xarray.Dataset> Size: 2kB
Dimensions:    (latitude: 8, longitude: 13)
Coordinates:
  * latitude   (latitude) float64 64B 70.0 65.0 60.0 55.0 50.0 45.0 40.0 35.0
  * longitude  (longitude) float64 104B -20.0 -15.0 -10.0 ... 30.0 35.0 40.0
Data variables:
    2t         (latitude, longitude) float64 832B ...
    msl        (latitude, longitude) float64 832B ...
Attributes:
    Conventions:  CF-1.8
    institution:  ECMWF
[ ]: