Monthly Archives: June 2017

GRIB command line tools from ECMWF

ECMWF supplies some useful command line tools for handling GRIB files: grib_get, grib_ls and grib_dump and several others. The tools are supplied as part of the latest version of the GRIB API.

To use the tools, you have to install the GRIB API from ECMWF:

Recent versions weren’t available from any of the remote repositories in my system’s default list. Therefore I had to download the installation package of a recent version of the grib-api (v. 1.14.0 or later) manually and then install it from a local repository using the Synaptic package manager in Ubuntu. See here for details of how to do this. Also, make sure you know whether your system is 32-bit or 64-bit and download the appropriate package. For my 32-bit Ubuntu system I used the 32-bit Debian package from the ECMWF GRIB-API Releases list.

With the API installed I was able to examine the contents of the files using grib_dump. After figuring out what was inside the files, I then extracted a time series for a specific location (specified as a latitude,longitude pair) using :

# u component, all validity times
grib_ls -w shortName:s=”u”,stepRange=3 -l 51.8483,-8.483543 -p dataDate,dataTime,validityDate,validityTime MERA_PRODYEAR_2015_06_33_105_10_0_FC3hr.grb > test33.txt
# v component, all validity times
grib_ls -l 51.8483,-8.483543 -p dataDate,dataTime,validityDate,validityTime -w shortName:s=”v” MERA_PRODYEAR_2015_06_34_105_10_0_FC3hr.grb > test34.txt

This extracted values for the four nearest grid cells to the specified location, for all forecast validity times (1h, 2h, 3h). There is a ‘grib_filter’ tool also provided which looks very useful as it can be used to match data based on a set of rules specified in a separate file. This looks better than the approach I took, but for now was just happy to get some data out of the GRIB files.

Handling data in Lambert Conformal Conic projections

I want to extract a time series of wind forecast values for a specific location from a GRIB file issued by Met Eireann as part of the MERA reanalysis project. In a previous post I listed several software tools for interrogating GRIB files. For various reasons, I wasn’t able to persuade any of those tools to do what I needed.

NASA GISS’ Panoply viewer was useful for visualisation, and it does have a facility for bulk export of data to CSV files. However, as the files are exported as “flat” CSV, they are very large. Furthermore, without knowing the details of how the CSV files are structured, the file layout is difficult to interpret. There is the additional problem of georeferencing the exported data to given latitude/longitude pairs, as the values are exported on the model’s Easting-Northing grid.

Before going further, some details of the MERA dataset are relevant: the projection is Lambert Conic Conformal. The GRIB file format is GRIB-1. The data are provided on an x-y (Easting-Northing) grid.

I wrote some Matlab routines based on the formulae provided in [1] and [2] to calculate latitudes and longitudes for the MERA grid cells for the Lambert Conformal Conic projection (code available on github). I could use those to find the co-ordinates of MERA grid cells corresponding to the latitude and longitude of particular locations of interest. But I still wasn’t able to extract the data from the GRIB file even when the grid cell co-ordinates were known. CDO appears to have difficulty with Lambert Conformal Conic projections. The NCL tools could not be persuaded to extract data.

In the end, following a tip from Met Eireann, I turned to the GRIB_API provided by ECMWF. Some useful command-line tools are provided with the API package and I was able to use these to query and “slice and dice” the MERA GRIB files. I’ll provide the details in another post.

[1] European Petroleum Survey Group. Guidance Note Number 7 on “POSC literature pertaining to Coordinate Conversions and Transformations including Formulas”, pp. 17-18.
[2] US Geological Survey Professional Paper 1394, “Map projections -a working manual”. Snyder, J. P. (1987) pp. 107-108.