Versions Compared

Key

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

...

Section
Column

What are GRIB files

Excerpt

This article show different approaches to convert GRIB to netCDF for use in other analysis and visualisation software.

It also describes different methods to interpolate the reduced Gaussian grid to regular grids.

GRIB files are the file format used at ECMWF.  GRIB is a WMO standard and consists of GRIB Edition 1 and Edition 2.

The OpenIFS/IFS models output in GRIB format. These files are a mix of GRIB-1 & GRIB-2 messages, the multi-level fields are encoded as GRIB-2, whereas surface fields are GRIB-1. GRIB files can also contain multiple vertical coordinates: pressure levels, model levels, sub-surface levels etc. This can cause a problem with some 3rd party tools, as the same GRIB variable code is used for each axis. The instructions below show how to work around this by splitting the file to separate fields on different vertical axes.

OpenIFS model output

The OpenIFS model outputs two types of files: those beginning with ICMSH contain fields represented as spherical harmonics, those that begin ICMGG contain gridpoint fields.  The ICMSH files are the spherical harmonics of the wind fields, pressure and temperature and require a spectral transform to convert to gridded data. Also see controlling the OpenIFS output for more details of output fields and options.

Retrieving data from MARS archive

Please note that if using the MARS archive (apps.ecmwf.int) (e.g. for reanalysis products such as ERA-Interim/ERA-5), it is possible to download the files in netCDF format as well as GRIB.

ecCodes/grib-api tools

Info

Please note that grib-api is being phased out in preference for ecCodes. All the grib_* commands shown below are still available with ecCodes.

grib_to_netcdf

This command will convert one or more GRIB files to netCDF and is available with the ECMWF ecCodes/grib-api software (for grib-api, versions above 1.11.0 are recommended). For more details please see: grib_to_netcdf description.

grib_to_netcdf only works correctly when a single level coordinate is present in the GRIB file. Often the model output files have fields on multiple level types (ie. hybrid model levels and pressure levels).

Code Block
titleHow to split GRIB file into separate level types
grib_copy ICMGGftkm+001440 ICMGG_[typeOfLevel].grb

In this example, the GRIB model output file ICMGGftkm+001440 contains a number of different model level types. The special square bracket "[ ]" syntax is recognised by grib_copy (and other grib commands such as grib_filter) and can contain any valid GRIB key.

This example will copy the original file, separating the level types into their own file: ICMGG_hybrid.grb, ICMGG_isobaricInhPA.grb, ICMGG_surface ...and so on.

grib_to_netcdf can then be used on the individual files:

Code Block
titleConvert GRIB file to netCDF
grib_to_netcdf ICMGG_hybrid.grb -o ICMGG_hybrid.nc

By default, grib_to_netcdf will pack the data into scaled integers with an offset to optimize space.

If you prefer data stored as floats then use:

Code Block
languagebash
titleConvert GRIB to netCDF storing values as floats rather than scaled integers...
grib_to_netcdf -D NC_FLOAT ICMGG_hybrid.grb -o ICMGG_hybrid.nc

To convert from vorticity and divergence to wind u and v, please see CDO instructions below.

Note that grib_to_netcdf does not do any regridding. If the fields use a reduced Gaussian latitude grid, they will not be converted to a regular grid. Use CDO instead to do this as described below.

Column
width350px
Panel
bgColorwhite
titleBGColorlightlightgrey
titleOn this page

Table of Contents
indent10px

Info
The MetView application is available for analysis and visualisation of OpenIFS output and will both convert spectral to gridded parameters and plot reduced Gaussian grid directly.
Please see 'Using Metview with OpenIFS' for more details.
Panel
titleSee also...

ecCodes - grib tools

MARS user documentation

...

Both produce a regular Gaussian grid with equal number of longitudes on each latitude row. Remember that a Gaussian grid has irregularly spaced latitudes (but nearly regular). For more details please see the description of these operators on the CDO homepage.

Code Block
cdo -f nc -sp2gpl <input spectral coefficent grib>  <output gridded netcdf>

Convert the resulting output files to netcdf

After any operation converting a GRIB file to any other GRIB file, the conversion to netCDF is just:

Code Block
titleConvert GRIB file to netCDF file
cdo -f nc copy <input grib> <output netcdf>

Convert vorticity and divergence to wind

To convert If you prefer wind components u & v instead of vorticity and divergence, use the cdo command:

Code Block
titleConvert vorticity & divergence to u & v
cdo dv2uvl <input file> <output file>

Interpolate to pressure from model levels

To interpolate to pressure levels from model levels, use this cdo command, for example:

Code Block
titleInterpolate model levels to pressure levels
cdo ml2pl,92500,85000,50000,20000 <input file> <output file>

...

Note

cdo commands can be combined into a single command for greater efficiency.

 

Possible problems and solutions

 

...

Using EMOSLIB to interpolate to regular grid

The ECMWF interpolation software library EMOSLIB also provides the capability to interpolate spectral data to regular gaussian grids or regular lat-lon grids, and interpolate regular gaussian grids to regular lat-lon grids.

The EMOSLIB library provides a Fortran library to enable users to write their own interpolation software. Please see the EMOSLIB website for more details and examples.

EMOSLIB also provides two command-line tools for using interpolation.

Assuming a recent version of the EMOS library, there are two tools that can be used.

In the 'bin' directory there is a command 'emos_tool' which can be used as:

bin/emos_tool example

emos_tool --regular=256 [--area="40/-10/31/20"in.grib out.grib

The grid specified for the --regular option follows the grid naming convention for EMOSLIB here: Reduced Gaussian Grids.

Another command can be found in the 'tools' directory. This allows the interpolation function to be specified:

tools/int example

tools/int --INTOUT:gridname=F256 --INTOUT:area="40/-10/31/20" --input=1.grib --output=2.grib --intf2

 

Here 'F256' means 'full-grid' not reduced, and --intf2 is the EMOSLIB interpolation function to be used.

Possible problems and solutions

 

cdo -R option does not work with GRIB-2 fields to convert to regular grid

CDO's -R option, to convert from CDO's -R option, to convert from reduced Gaussian grid to regular Gaussian grid, only works with GRIB 1 format as the CGRIBEX decoder this uses does not work with GRIB-2 (see cdo man page). This is a problem as multi-level output from OpenIFS is encoded as GRIB-2 data.

...

Warning

Do not use this option for GRIB-2 fields. It sets the GRIB table default to be specific to the GRIB-1 ECMWF tables. If problems persist, we recommend using grib_to_netcdf to convert to netCDF.

...

 

Acknowledgements

Thanks to Paul Dando of User Support for help with the contents of this page.

...