DocumentationThe ecCodes GRIB tools are documented at: There are examples of how to use them at: Other useful resources: |
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 |
Remember to load the ecmwf-toolbox !
|
This tutorial covers the following topics:
Using grib_dump and grib_ls to inspect GRIB files |
To list the GRIB messages in t2m.grib1
The file contains 2 metre temperature (shortName=2tl) from the ECMWF Ensemble control forecast (dataType=cf) for 6-hourly steps (stepRange) from 0 to 24 hours for dataDate=20170217. Similarly, for t2m.grib2:
Again, the file contains 2 metre temperature (shortName=2t) from the ECMWF Ensemble control forecast (dataType=cf) for 6-hourly steps (stepRange) from 0 to 24 hours for dataDate=20170217. In fact, they are the same fields as in t2m.grib1 but encoded in GRIB edition 2 and obtained from the TIGGE archive. |
No, grib_ls prints the same set of default keys for the both GRIB edition 1 and GRIB edition2. However, the order of the columns output is different. The only differences seen with grib_ls is for the value of the typeOfLevel and level keys which are
|
To print the mars keys, use either grib_ls -m or grib_ls -n mars. This is the output for the file t2m.grib1:
For t2m.grib2, the same command gives:
|
To print the shortName along with the list of mars keys use the –P option e.g.:
|
Hint: think about stings and integers |
To order the output in descending step order use the –B option:
|
To specify a set of keys to print, use the -p option:
|
To print the keys for forecast step 6 only, use the -p option with the -w option:
Using the same commands with the file t2m.grib2 gives similar output. |
Specifying the key as "centre:i" and “centre:s” prints the centre both as an integer and a string:
As before, using the same commands with the file t2m.grib2 gives similar output. |
To use grib_dump to inspect the contents of the fourth message in t2m.grib1 and t2m.grib2 use the -w option with "count=4" (the count key counts the number of messages starting form count=1 for the first message. To print the output in WMO Octet mode use the -O option:
|
The command may produce many lines of output. You may want to redirect output to a file using, e.g.:
|
To use grib_dump to all of the keys for the fourth message in JSON mode, use the -j option:
Similarly, for t2m.grib2:
|
Using grib_ls to find values at the nearest grid point to a specified latitude-longitude point |
The file t2m.grib1 contains the 2m temperature from the ENS control forecast at 6-hourly time steps for the first 24 hours on the O640 octahedral reduced Gaussian grid. The file lsm.grib1 contains the ENS land-sea mask on the O640 grid.
Be careful to specify the longitude correctly ! |
To list the nearest points to Lat 51.42° N, Lon 0.95° W use:
|
The nearest grid point is at latitude=51.38° longitude=359.03° (0.77° W) and is 4.79 km from ECMWF. |
To output only the forecast step and 2 metre temperature value at the nearest grid point set the MODE option to 1 and specify that the stepRange key only should be printed using the -p option:
|
The output format of the values is specified with the -F option. Here, -F"%.2f" is used to specify decimal format with 2 decimal places. To specify the land-sea mask, pass the name of the file containing the land-sea mask as the FILE option:
Here the value=1.00 (or 0.99) at the end of the line showing the four nearest grid points indicates which are land points (mask=1.0). Land points have mask ≥ 0.5; sea points have mask<0.5.
|
Using grib_get_data to print data values |
To print the data values for surface.grib1 in decimal format with 6 decimal places use grib_get_data with the option -F"%.6f":
|
To output also the latitude and longitude values with 6 decimal places, we need to use the -L option:
|
Missing values can be identified by using grib_get_data with the –m option, for example:
|