Versions Compared

Key

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

...

 

Section
Column

Model output

Excerpt

The instructions in this article show how to convert OpenIFS GRIB output to netCDF for use in other analysis and visualisation software.

The OpenIFS model outputs files in GRIB format. These files are a mix of GRIB 1 & GRIB 2 format messages. They also contain multiple vertical coordinates: pressure levels, sub-surface levels etc, as well as fields on reduced Gaussian grids. 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.

The ICMGG files contain all the gridpoint fields. The ICMSH files are the spherical harmonics of the wind fields, pressure and temperature.

Grib-api tools

grib_to_netcdf

This command will convert one or more GRIB files to netCDF and is available with the ECMWF grib_api software (versions above 1.11.0 are recommended. It is not available in versions less than 1.10.0).

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
titleSplit 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 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 ...etc.

The same square bracket syntax is also understood by the grib_filter command.

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

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

Column
width320px
Panel
bgColorwhite
titleBGColorlightlightgrey
titleOn this page

Table of Contents
indent10px

Info
The MetView application is available for analysis and visualisation of OpenIFS output.
Please see 'Using Metview with OpenIFS' for more details.

 

NCAR command language (NCL)

NCL provides a tool to convert both GRIB1 & GRIB2 to netCDF called ncl_convert2nc.

NCL example scripts to convert to netCDF are also available.

CDO commands

These instructions assume the use of a recent version of Climate Data Operators (CDO) (available from Max-Planck-Institut, Germany).

...

Code Block
titleExample cdo command for inspecting GRIB file
$ cdo sinfo ICMSHfrq2+000000.grb 
   File format: GRIB
    -1 : Institut Source   Param       Time Typ  Grid Size Num  Levels Num
     1 : ECMWF    unknown  11.3        var  P16     65792   1      60   1
     2 : ECMWF    unknown  39.3        var  P16     65792   1      60   1
     3 : ECMWF    unknown  43.3        var  P16     65792   1      60   1
     4 : ECMWF    unknown  44.3        var  P16     65792   1      60   1
     5 : ECMWF    unknown  152.128     var  P16     65792   1       1   2
     6 : ECMWF    unknown  6.3         var  P16     65792   1       1   2
   Horizontal grids :
     1 : spectral     > size      : dim = 65792  truncation = 255  spc = 32896
                                    complexPacking = 1
   Vertical grids :
     1 : hybrid            level : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
                                   20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 
                                   36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 
                                   52 53 54 55 56 57 58 59 60 
     2 : hybrid            level : 1 
   Time axis :  1 step
     RefTime =  1999-12-24 12:00:00  Units = hours  Calendar = PROLEPTIC
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  1999-12-24 12:00:00
cdo sinfo: Processed 6 variables over 1 timestep. ( 0.04s )

Example 1 - Converting a single file

In this example a single GRIB file with model level data, on a regular Gaussian grid is converted to netCDF with vorticity & divergence replaced by u & v and model level data interpolated to pressure levels.

Code Block
grib_set -s editionNumber=1 file file.grb
cdo -t ecmwf -f nc copy file.grb file.nc
cdo -t ecmwf dv2uvl file.nc file_uv.nc
cdo -t ecmwf sp2gpl file_uv.nc file_uv_gg.nc
cdo -t ecmwf ml2pl,92500,85000,50000,20000 file_uv_gg.nc file_uv_gg_pl.nc

Example 2 - Converting series of files

The following script shows how to loop over several output files using the steps above to convert to netCDF. Note the spherical harmonic files are also converted but the extra command using the sp2gpl operator is first used to convert the variables from spherical harmonics to gridpoint.

...