Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Using NetCDF

earthkit-data-logo

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")
d
d.available_types

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)
# 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]
f
f.get("time.base_datetime")
f.time.base_datetime()
f.vertical.level_type()