GRIB -- WMO General Regularly-distributed Information in Binary form

GDAL supports GRIB1 (reading) and GRIB2 (reading and writing) format raster data, with support for common coordinate system, georeferencing and other metadata. GRIB format is commonly used for distribution of Meteorological information, and is propagated by the World Meteorological Organization.

The GDAL GRIB driver is based on a modified version of the degrib application which is written primarily by Arthur Taylor of NOAA NWS NDFD (MDL). The degrib application (and the GDAL GRIB driver) are built on the g2clib grib decoding library written primarily by John Huddleston of NOAA NWS NCEP.

There are several encoding schemes for raster data in GRIB format. Most common ones should be supported including PNG encoding. JPEG2000 encoded GRIB files will generally be supported if GDAL is also built with JPEG2000 support via one of the GDAL JPEG2000 drivers.

GRIB files may a be represented in GDAL as having many bands, with some sets of bands representing a time sequence. GRIB bands are represented as Float64 (double precision floating point) regardless of the actual values. GRIB metadata is captured as per-band metadata and used to set band descriptions, similar to this:

  Description = 100000[Pa] ISBL="Isobaric surface"
    GRIB_UNIT=[gpm]
    GRIB_COMMENT=Geopotential height [gpm]
    GRIB_ELEMENT=HGT
    GRIB_SHORT_NAME=100000-ISBL
    GRIB_REF_TIME=  1201100400 sec UTC
    GRIB_VALID_TIME=  1201104000 sec UTC
    GRIB_FORECAST_SECONDS=3600 sec
GRIB2 files may also include an extract of other metadata, such as the identification section, product definition template number (GRIB_PDS_PDTN, octet 8-9), and the product definition template values (GRIB_PDS_TEMPLATE_NUMBERS, octet 10+) as metadata like this:
    GRIB_DISCIPLINE=0(Meteorological)
    GRIB_IDS=CENTER=7(US-NCEP) SUBCENTER=0 MASTER_TABLE=8 LOCAL_TABLE=1 SIGNF_REF_TIME=1(Start_of_Forecast) REF_TIME=2017-10-20T06:00:00Z PROD_STATUS=0(Operational) TYPE=1(Forecast)
    GRIB_PDS_PDTN=32
    GRIB_PDS_TEMPLATE_NUMBERS=5 7 2 0 0 0 0 0 1 0 0 0 0 1 0 31 1 29 67 140 2 0 0 238 217
    GRIB_PDS_TEMPLATE_ASSEMBLED_VALUES=5 7 2 0 0 0 0 1 0 1 31 285 17292 2 61145

GRIB_DISCIPLINE was added in GDAL 2.3.0 and is the Discipline field of the Section 0 of the message.

GRIB_IDS was added in GDAL 2.3.0 and is the identification section / Section 1 of the message.

GRIB_PDS_TEMPLATE_ASSEMBLED_VALUES was added in GDAL 2.3.0, and use template definitions to assemble several bytes that make a template item into a 16 or 32 bit signed/unsigned integers, whereas GRIB_PDS_TEMPLATE_NUMBERS expose raw bytes

Configuration options

This paragraph lists the configuration options that can be set to alter the default behaviour of the GRIB driver.

GRIB2 write support

GRIB2 write support is available since GDAL 2.3.0, through the CreateCopy() / gdal_translate interface.

Each band of the input dataset is translated as a GRIB2 message, and all of them are concatenated in a single file, conforming to the usual practice.

The input dataset must be georeferenced, and the supported projections are: Geographic Longitude/Latitude, Mercator 1SP/2SP, Transverse Mercator, Polar Stereographic, Lambert Conformal Conic 1SP/2SP, Albers Conic Equal Area and Lambert Azimuthal Equal Area.

A number of creation options are available as detailed in below sections. Those creation options are valid for all bands. But it is possible to override those global settings in a per-band way, by defining creation options that use the same key and are prefixed by BAND_X_ where X is the band number between 1 and the total number of bands. For example BAND_1_PDS_PDTN

Product identification and definition

Users are strongly advised to provide necessary information to appropriately fill the Section 0 / "Indicator", Section 1 / "Identification section" and Section 4 / "Product definition section" with the following creation options. Otherwise, GDAL will fill with default values, but readers might have trouble exploiting GRIB2 datasets generating with those defaults.

Data encoding

In GRIB2, a number of data encoding schemes exist (see Section 5 / "Data representation section"). By default, GDAL will select an appropriate data encoding that will preserve the range of input data. with the DATA_ENCODING, NBITS, DECIMAL_SCALE_FACTOR, JPEG200_DRIVER, COMPRESSION_RATIO and SPATIAL_DIFFERENCING_ORDER creation options.

Users can override those defaults with the following creation options are:

Data units

Internally GRIB stores values in the units of the international system (ie Metric system). So temperatures must be stored as Kelvin degrees. But on the reading side of the driver, fields with temperatures are exposed in Celcius degrees (unless the GRIB_NORMALIZE_UNITS configuration option is set to NO). For consistency, the writing side of the driver also assumed that temperature (detected if the first value of a product definition template, ie the Parameter category is 0=Temperature) values in the input dataset will be in Celcius degrees, and will automatically offset them to Kelvin degrees. It is possible to control that behaviour by setting the INPUT_UNIT creation option to C (for Celcius) or K (for Kelvin). The default is C.

GRIB2 to GRIB2 conversions

If GRIB2 to GRIB2 translation is done with gdal_translate (or CreateCopy()), the GRIB_DISCIPLINE, GRIB_IDS, GRIB_PDS_PDTN and GRIB_PDS_TEMPLATE_NUMBERS metadata items of the bands of the source dataset are used by default (unless creation options override them).

DECIMAL_SCALE_FACTOR and NBITS will also be attempted to be retrieved from the GRIB special metadata domain.

Examples

gdal_translate in.tif out.grb2 -of GRIB \
    -co "IDS=CENTER=8(US-NWSTG) SIGNF_REF_TIME=1(Start_of_Forecast) REF_TIME=2008-02-21T17:00:00Z PROD_STATUS=0(Operational) TYPE=1(Forecast)" \
    -co "PDS_PDTN=8" \
    -co "PDS_TEMPLATE_ASSEMBLED_VALUES=0 5 2 0 0 255 255 1 43 1 0 0 255 -1 -2147483647 2008 2 23 12 0 0 1 0 3 255 1 12 1 0"

See Also:

Credits

Support for GRIB2 write capabilities has been funded by Meteorological Service of Canada.