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:
The next example shows Metview doing some processing on the data before converting to a dataset - note that the result does not need to be explictly written to disk before the conversion takes place:
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:
Now, the following Python script should run: