Using NetCDF¶
In this notebook you will see how to:
convert NetCDF to Xarray
convert NetCDF to a fieldlist
Getting the data¶
First we read some NetCDF from the remote samples with from_source. The returned object provides some basic information but its primary goal is to convert the data into the required representation for further work. The actual data loading is deferred as much as possible, until the data is converted into a given type.
import earthkit.data as ekd
d = ekd.from_source("sample", "era5_tquv_pl_subarea.nc")
dd.available_types['xarray', 'pandas', 'fieldlist', 'numpy', 'array']Conversion to Xarray¶
The easiest way to work with NetCDF data is to convert it into Xarray.
d.to_xarray()Conversion to fieldlist¶
It is also possible to load NetCDF data into a FieldList, which might be necessary for fieldlist based workflows. This is done by slicing the dataarrays along the relevant dimensions to form the fields.
fl = d.to_fieldlist()The fieldlist contains 48 fields.
len(fl)48# first 5 fields
fl.head()A field generated from NetCDF/Xarray behaves just like as if it was loaded from GRIB (as far as the components and high level metadata is concerned).
f = fl[0]
ff.get("time.base_datetime")datetime.datetime(2016, 9, 26, 0, 0)f.time.base_datetime()datetime.datetime(2016, 9, 26, 0, 0)f.vertical.level_type()'pressure'