...
Section | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
NCAR command language (NCL)
NCL provides a tool to convert both GRIB-1 & GRIB-2 to netCDF called ncl_convert2nc.
|
NCAR command language (NCL)
NCL provides a tool to convert both GRIB-1 & GRIB-2 to netCDF called ncl_convert2nc.
NCL NCL example scripts to convert to netCDF are also available.
...
CDO supports GRIB-2 but needs either the GRIBgrib_API api or ecCodes library from ECMWF to be included. This is necessary in order to work correctly with OpenIFS model output.
...
CDO can be used to interpolate from the reduced Gaussian grid to a regular Gaussian grid (IFS/OpenIFS resolutions T21 & T42 use a regular Gaussian grid):
Code Block | ||
---|---|---|
| ||
cdo -R copy <input grib> <output grib> |
Info |
---|
If the -R option does not work, use ' |
If this step does not work, see workarounds below.
Steps to convert GRIB to netCDF
...
This will ensure the following steps work correctly.:
Code Block | ||
---|---|---|
| ||
cdo splitzaxis ICMSHg4a4+000000.grb ICMSHg4a4+000000_split ls ICMSH*split* ICMSHg4a4+000000_split01.grb ICMSHg4a4+000000_split02.grb ICMSHg4a4+000000_split03.grb ICMSHg4a4+000000_split04.grb |
In this example, the different files might contain: '01' - fields on pressure levels, '02' - fields on model levels, '03' - hybrid levels, '04' - surface and so on. The number of files created depends on the number of different types of levels. Use the command 'grib_ls
' to inspect the contents of each split file.
...
Another way to split the file would be using the grib_copy command from the ecCodes (or grib-_api (or ecCodes) library software as shown above:
Code Block |
---|
grib_copy ICMSHg4a4+000000.grb ICMSHg4a4+000000_[typeOfLevel].grb |
In this case 'typeOfLevel' is a GRIB key. The square brackets is a special syntax to the the grib_copy
command. This approach works with any GRIB key.
...
CDO supports two options for converting spectral to gridpoint data:
- sp2gp - converts spectral to a quadratic Gaussian grid.
- sp2gpl - converts spectral to a linear Gaussian grid, appropriate for IFS data.
- sp2gp - converts spectral to a quadratic Gaussian grid (only use this for T21/42 resolutions)
Both 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.
Convert the resulting output files to netcdf
...
Code Block | ||
---|---|---|
| ||
cdo -f nc copy <input grib> <output netcdf> |
...
Code Block | ||
---|---|---|
| ||
for i in 000 024 048 072
do
cdo -R copy ICMGGfpp4+000${i}.grb ICMGGfpp4+000${i}_R.grb
cdo splitzaxis ICMGGfpp4+000${i}_R.grb ICMGGfpp4+000${i}
cdo -f nc copy ICMGGfpp4+000${i}01.grb ICMGGfpp4+000${i}_PL_GP.nc # pressure level gridpoint fields
cdo -f nc copy ICMGGfpp4+000${i}02.grb ICMGGfpp4+000${i}_ML_GP.nc # model level gridpoint fields
cdo splitzaxis ICMSHfpp4+000${i}.grb ICMSHfpp4+000${i}
cdo -f nc copy -sp2gpl ICMSHfpp4+000${i}01.grb ICMSHfpp4+000${i}01_PL_GP.grb # spectral fields on press levels transformed to gridpoint
cdo -f nc copy -sp2gpl ICMSHfpp4+000${i}03.grb ICMSHfpp4+000${i}03_ML_GP.grb # spectral fields on model levels transformed to gridpoint
cdo -f nc copy -sp2gpl ICMSHfpp4+000${i}04.grb ICMSHfpp4+000${i}04_surf_GP.grb # spectral fields on surface levels transformed to gridpoint
done |
Possible problems and solutions
CDO does not understand GRIB-2 messages
If you are using an old version of CDO, it may not understand GRIB-2 messages. CDO must be compiled with either grib-api or ecCodes library in order to handle GRIB-2.
A workaround is to use the grib_set
command (from the grib_api/ecCodes installation) to change the GRIB edition number for all messages.
Code Block | ||
---|---|---|
| ||
grib_set -s editionNumber=1 <input grib2 file> <output grib1 file>
|
_surf_GP.grb # spectral fields on surface levels transformed to gridpoint
done |
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 reduced Gaussian grid to regular Gaussian grid, only works with GRIB 1 format (cgribex only) (see cdo man page). This is a problem as multi-level output from OpenIFS is encoded as GRIB-2 data.
A workaround is to temporarily change the edition number to 1. Use the grib_set
command (from ecCodes or grib_api) to change the GRIB edition number for all messages:
Code Block | ||
---|---|---|
| ||
grib_set -s editionNumber=1 in.grb in_1.grb
cdo -R copy in_1.grb in_1_R.grb
grib_set -s editionNumber=2 in_1_R.grb in_2_R.grb |
This does not actually convert the message to GRIB-1, it only changes the editionNumber. Any GRIB-2 specific elements are unaltered.
It's recommended that the editionNumber
is changed back to 2 to ensure that the parameter names remain correct in any subsequent cdo / grib commands.
Workaround if using more than 128 levels
The workaround above will fail if the grib file contains field with more than 128 levels. This is because there are not enough bits available in the GRIB-1 parameter to encode the total number of model half levels (which would exceed 255).
In this case, the 'pv' GRIB parameter causes the problem (nothing to do with potential vorticity!). This is an array holding the half level values of the model's A & B coefficients that define the location of the levels.
The workaround above can be extended to delete this array while setting the edition number to 1, like this:
Code Block |
---|
grib_set -s deletePV=1,editionNumber=1 in.grb in_1.grb
cdo -R copy in_1.grb in_1_R.grb
grib_set -s editionNumber=2 in_1_R.grb in_2_R.grb |
The deletePV option is known as a 'concept' rather than a parameter contained in the GRIB file itself. It ensures the PV array is deleted correctly by grib_set. Now the cdo regridding will work correctly, but remember to reset the editionNumber back to 2.
The A & B half level coefficients can be recovered from the original file by:
Code Block |
---|
cdo vct in.grb > pv.txt |
Note |
Note this will only work if you are using less than 128 model levels as it does not actually convert the message to GRIB-1 if there are any GRIB-2 specific elements in the messages. |
Parameter names are lost for GRIB-1 fields
...
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.
...