Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

There are two ways to use cfgrib to load a GRIB file as an xarray dataset.

1. Using cfgrib through Metview

Metview's Python interface ensures a correct environment, and provides an easy means to convert a Fieldset object into a dataset, using cfgrib behind the scenes to do it. Assuming that the 'python3' and 'metview' modules are loaded, the following code shows a simple example that does this:

...

Code Block
languagepy
import metview as mv

g = mv.read("ERA5_levels.grib")
u = mv.read(data=g, parameter='u')
v = mv.read(data=g, parameter='v')
d = mv.divergence(u, v)
all = mv.merge(g, d) # add divergence to the Fieldset
ds = all.to_dataset()
print(ds)

2. Using cfgrib standalone

cfgrib can also be run as a standalone Python package, but it requires a little more setup. cfgrib is installed with the Metview installation, and requires the location of the ecCodes library. Assuming that the 'python3', 'eccodes' and 'metview' modules are loaded, this, run at ECMWF, will allow cfgrib to be used:

...