DocumentationThe ecCodes GRIB tools are documented at: There are examples of how to use them at: Other useful resources: |
If you have already followed the Introduction Tutorial on GRIB decoding with ecCodes GRIB tools: inspecting GRIB files there is no need to redo these preliminary steps. |
Login to ecs-login and work in your $SCRATCH:
$> cd $SCRATCH |
Make a copy of the practicals directory in your $SCRATCH to Atos:
$> tar –xvf /home/trx/grib_practicals.tar |
This will create a directory in your $SCRATCH called grib_practicals containing the GRIB data files for this tutorial.
There are sub-directories for each practical:
$> ls $SCRATCH/grib_practicals inspect modify python |
For this tutorial, cd to the modify directory:
$> cd $SCRATCH/grib_practicals/modify |
Remember to load the ecmwf-toolbox !
|
This tutorial covers the following topics:
Using grib_copy to copy selected messages from a GRIB file |
The file tz_an_pl.grib1 contains parameters T and Z on six pressure levels.
To copy only those messages for parameter T from the GRIB file tq_an_pl.grib2 use grib_copy with the -w option to specify a shortName=t:
Similarly to copy only those messages for parameter Q, use:
Or, more simply, and because the file contains only parameters T and Q, one can use:
Using grib_ls of the two files confirms that the contents are correct. For example:
You can take this further and split the file tq_an_pl.grib1 into separate files for each parameter/pressure level combination with:
Each file contains one message only, e.g.:
|
Using grib_set to change key values |
The field in the file tp.grib is supposed to contain total precipitation, created using MARS compute to sum the convective and large-scale (stratiform) precipitation.
Use grib_ls to inspect the contents of the file tp.grib2, printing also the paramId with the –P option:
Alternatively, you could inspect the parameter namespace with grib_ls:
The shortName is set to lsp and paramId to 142, i.e., large-scale precipitation.
To change the parameter to total precipitation, use grib_set as follows:
Check with grib_ls:
|
Converting GRIB data to netCDF with grib_to_netcdf |
To convert the GRIB messages in file.grib2 to netCDF with data type NC_SHORT and store in a file named out1.nc use:
|
Load the netcdf4 module and use ncdump to check the values in the netCDF file created in the previous step as follows:
$> module load netcdf4 $> ncdump -v t2m out1.nc |
Using ncdump to print the values for the variable t2m shows:
|
To store the values in the netCDF file as floating point numbers, use the grib_to_netcdf tool with the data format to NC_FLOAT or NC_DOUBLE with the -D option. For example:
Checking with ncdump, we see the values are now stored as floating point values:
In this case, the data values do not need further processing. |
Converting file2.grib2 to netCDF gives the following error:
The conversion fails because the GRIB data is represented on a reduced Gaussian grid (gridType=reduced_gg). Conversion to netCDF is possible only for GRIB data with gridType=regular_ll or gridType=regular_gg. To fix this it would be necessary to re-retrieve the data on a regular grid or interpolate to a regular grid. |