- Created by Paul Dando, last modified on Nov 15, 2023
1. Experiment with using the different grib_dump options
(-O, -a and –t). Inspect the GRIB message in the files file1.grib1 and file1.grib2 and identify:
the GRIB edition used to encode the messages
the (MARS) parameter ID, date, time, forecast step and the grid geometry
What are the maximum, minimum and average values of the fields?
To view the keys available for GRIB1 and GRIB2 have a look at the parameter database at http://apps.ecmwf.int/codes/grib/
To use grib_dump to inspect the contents of file1.grib1:% grib_dump file1.grib1
By using grib_dump on its own and with the various options, (-O, -a, etc), you should find:
- the message is encoded using GRIB edition 1 (editionNumber=1);
- it contains the 2 metre temperature field (shortName=2t, marsParam=167.128, paramId=167);
- the dataDate= 20190201, the dataTime=00 and the forecast step=12;
- the data is on an octahedral reduced Gaussian grid (typeOfGrid=reduced_gg) with N=640 (Nj=1280) and gridName=0640.
Similarly for the file file2.grib2% grib_dump file1.grib2
By using grib_dump on its own and with various options, (-O, -a etc), you should find:
- the message is encoded using GRIB edition 2 - editionNumber=2;
- it contains the temperature field on a specified height of 2 m above ground (shortName=2t, paramId = 167, discipline = 0, parameterCategory = 0, parameterNumber = 0, typeOfFirstFixedSurface = 103);
- the dataDate=20190201, the dataTime=00 and the forecast step=12;
- the data is on an octahedral reduced Gaussian grid (typeOfGrid=reduced_gg) with N=640 (Nj=1280) and gridName=0640.
To quickly find the maximum, minimum and average values of the field, look for the computed keys max, min, and average.
For both files you should find:
- maximum = 315.501
- minimum = 222.528
- average = 287.703
2. Use grib_ls to print the centre, dataDate, stepRange, levelType, shortName and paramId for msl.grib1 and msl.grib2 and order by ascending stepRange.
Experiment with both –P and –p options and ‘key:i’, ‘key:s’
Which keys does grib_ls show by default for the two files ?
What fields do they contain
To list the GRIB messages in msl.grib1, use:
% grib_ls msl.grib1
edition centre typeOfLevel level dataDate stepRange dataType shortName packingType gridType
1 ecmf surface 0 20190201 6 cf msl grid_simple regular_gg
1 ecmf surface 0 20190201 12 cf msl grid_simple regular_gg
1 ecmf surface 0 20190201 18 cf msl grid_simple regular_gg
1 ecmf surface 0 20190201 24 cf msl grid_simple regular_gg
4 of 4 grib messages in msl.grib1
The file contains mean sea-level pressure (shortName=msl) from the ECMWF ENS control forecast (dataType=cf) for 6-hourly steps from 6 to 24 hours for dataDate=20190201. The messages are encoded in GRIB edition 1.
To list the GRIB messages in msl.grib2% grib_ls msl.grib2
edition centre date dataType gridType stepRange typeOfLevel level shortName packingType
2 ecmf 20190201 cf regular_gg 6 meanSea 0 msl grid_simple
2 ecmf 20190201 cf regular_gg 12 meanSea 0 msl grid_simple
2 ecmf 20190201 cf regular_gg 18 meanSea 0 msl grid_simple
2 ecmf 20190201 cf regular_gg 24 meanSea 0 msl grid_simple
4 of 4 grib messages in msl.grib2
The file also contains mean sea-level pressure (shortName=msl) from the ECMWF ENS control forecast (dataType=cf) for 6-hourly steps from 6 to 24 hours for dataDate=20190201. In this file the messages are encoded in GRIB edition 2.
The lists show the default keys printed by grib_ls for GRIB 1 and GRIB 2. The same keys are listed but the order in which they appear differs between GRIB edition 1 and GRIB edition 2.
Using the "key:i
" for centre and levelType prints these keys as their integer values rather than strings:
% grib_ls -p centre:i,dataDate,stepRange,levelType:i,shortName,paramId msl.grib1
centre dataDate stepRange levelType shortName paramId
98 20190201 6 1 msl 151
98 20190201 12 1 msl 151
98 20190201 18 1 msl 151
98 20190201 24 1 msl 151
4 of 4 grib messages in msl.grib1
Similarly for msl.grib2:% grib_ls -p centre:i,dataDate,stepRange,levelType:i,shortName,paramId msl.grib2
centre dataDate stepRange levelType shortName paramId
98 20190201 6 101 msl 151
98 20190201 12 101 msl 151
98 20190201 18 101 msl 151
98 20190201 24 101 msl 151
4 of 4 grib messages in msl.grib2
3. Find the value of the MSLP at the grid point nearest to ECMWF (Lat 51.42°N, Lon 0.95° W) at each forecast step
What is the lat-lon value of the grid point nearest to ECMWF ?
How far is the chosen grid point from ECMWF ?
Use the file lsm.grib1 to provide a land-sea mask - are all four nearest grid points land points (mask ≥ 0.5) ?
To list the nearest points to ECMWF (Lat 51.42 N, Lon 0.95 W) use% grib_ls -l 51.42,-0.95 msl.grib1
…
4 of 4 messages in msl.grib1
4 of 4 total messages in 1 files
Input Point: latitude=51.42 longitude=-0.95
Grid Point chosen #2 index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
Other grid Points
- 1 - index=156198 latitude=51.38 longitude=359.35 distance=21.64 (Km)
- 2 - index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
- 3 - index=155082 latitude=51.52 longitude=359.35 distance=23.65 (Km)
- 4 - index=155081 latitude=51.52 longitude=359.03 distance=11.09 (Km)
Note we specify the longitude of 0.95 W with -0.95 !
The nearest grid point is at latitude=51.38 longitude=359.03 (=0.97 W) and is 4.79 km from ECMWF.
To output only the forecast step and MSLP value at the nearest grid point use:% grib_ls -l 51.42,-0.95,1 -p stepRange msl.grib1
msl.grib1
stepRange value
6 98263.5
12 98621.1
18 99085.2
24 99593.2
4 of 4 messages in msl.grib1
4 of 4 total messages in 1 files
Input Point: latitude=51.42 longitude=-0.95
Grid Point chosen #2 index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
Other grid Points
- 1 - index=156198 latitude=51.38 longitude=359.35 distance=21.64 (Km)
- 2 - index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
- 3 - index=155082 latitude=51.52 longitude=359.35 distance=23.65 (Km)
- 4 - index=155081 latitude=51.52 longitude=359.03 distance=11.09 (Km)
stepRange value
0 102527
6 102365
12 102456
18 102289
24 101862
5 of 5 grib messages in msl.grib1
Input Point: latitude=51.42 longitude=-0.95
Grid Point chosen #3 index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
Other grid Points
- 1 - index=17599 latitude=50.72 longitude=359.10 distance=77.54 (Km)
- 2 - index=17598 latitude=50.72 longitude=358.20 distance=97.59 (Km)
- 3 - index=17199 latitude=51.62 longitude=359.10 distance=22.57 (Km)
- 4 - index=17198 latitude=51.62 longitude=358.20 distance=62.87 (Km)
Note it is necessary to specify MODE=1 in order to print the value of the nearest grid point only.
To output the values at the four grid points nearest to ECMWF, use MODE=4 which is the default:% grib_ls -l 51.42,-0.95 -p stepRange msl.grib1
msl.grib1
stepRange value1 value2 value3 value4
6 98236.5 98263.5 98293.5 98319.2
12 98596.1 98621.1 98644.4 98666.1
18 99043 99085.2 99074.5 99116
24 99547 99593.2 99561.5 99612.2
4 of 4 messages in msl.grib1
4 of 4 total messages in 1 files
Input Point: latitude=51.42 longitude=-0.95
Grid Point chosen #2 index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
Other grid Points
- 1 - index=156198 latitude=51.38 longitude=359.35 distance=21.64 (Km)
- 2 - index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
- 3 - index=155082 latitude=51.52 longitude=359.35 distance=23.65 (Km)
- 4 - index=155081 latitude=51.52 longitude=359.03 distance=11.09 (Km)
To specify the land-sea mask, use:% grib_ls -l 51.42,-0.95,1,lsm.grib1 -p stepRange msl.grib1
msl.grib1
stepRange value
6 98263.5
12 98621.1
18 99085.2
24 99593.2
4 of 4 messages in msl.grib1
4 of 4 total messages in 1 files
Input Point: latitude=51.42 longitude=-0.95
Grid Point chosen #2 index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km)
Mask values:
- 1 - index=156198 latitude=51.38 longitude=359.35 distance=21.64 (Km) value=1.00
- 2 - index=156197 latitude=51.38 longitude=359.03 distance=4.79 (Km) value=0.99
- 3 - index=155082 latitude=51.52 longitude=359.35 distance=23.65 (Km) value=0.99
- 4 - index=155081 latitude=51.52 longitude=359.03 distance=11.09 (Km) value=0.99
Here the mask value at the end of the line showing the four nearest grid points indicates which are land points: Land points have mask ≥ 0.5; sea points have mask<0.5.
This works in the same way for msl.grib2. Note that you can pass the land-sea mask file as either GRIB edition 1 or GRIB edition 2.