Categories
Uncategorized

Dealing with GRIB2 data

We use python for our data analysis and plotting.

The wonderful xarray package (http://xarray.pydata.org/en/stable/) has no problem with NetCDF, but doesn’t like GRIB2. GFS data are in GRIB2, however, so it would be nicve if we could convert them easily to NetCDF.

We can do this by using the great wgrib2 tool (http://www.cpc.noaa.gov/products/wesley/wgrib2/).

To install wgrib2 (on ORR2 or SONIC, for example), do the following:

  1. Make a directory for wgrib2 and move there:
    cd
    mkdir wgrib2
    cd wgrib2
  2. Get wgrib2 and unpack it:
    wget ftp://ftp.cpc.ncep.noaa.gov/wd51we/wgrib2/wgrib2.tgz
    tar -xzf wgrib2.tgz
  3. Move into the directory, set environment variables and make wgrib2:
    cd grib2/
    export CC=gcc
    export FC=gfortran
    make
  4. Now you can convert a GFS GRIB2 file to NetCDF!
    wgrib2/grib2/wgrib2/wgrib2 gec00.t12z.pgrb2f00 -netcdf GFS.nc

    It’d be a good idea to add the wgrib2 executable directory to your PATH, so you can call it from any directory.