Monthly Archives: November 2013

Converting NetCDF to Grib

It’s possible to convert NetCDF to grib format using the Climate Data Operators. For example, if you want to use the high resolution SST dataset produced by DMI (refs), as input to WRF, the you need to convert it.

I found some info on a post here. The basic steps needed using CDO are:

Split the NetCDF file into separate variables, one per file:

cdo splitname infile.nc split_

This creates sets of files for each variable in the input, e.g. split_sst.nc and split_mask.nc. Now convert to grib and map the variable to something “grib-like”. CDO uses a parameter identifier to deal with grib codes and tables. GRIB1 parameter identifier has the two components, GRIB2 have three components:

GRIB1 parameter identifier: < code number>.<table number>  e.g. temperature 130.128
GRIB2 parameter identifier: <parameter number>.<parameter category>.<discipline>  e.g temperature 0.0.0

By looking into the WPS Vtables, you can copy sensible parameter values which WRF will recognise:

GRIB1| Level| From |  To  | metgrid  | metgrid | metgrid                                 |GRIB2|GRIB2|GRIB2|GRIB2|
Param| Type |Level1|Level2| Name     | Units   | Description                             |Discp|Catgy|Param|Level|
-----+------+------+------+----------+---------+-----------------------------------------+-----------------------+
  11 | 100  |   *  |      | TT       | K       | Temperature                             |  0  |  0  |  0  | 100 |
  33 | 100  |   *  |      | UU       | m s-1   | U                                       |  0  |  2  |  2  | 100 |
  34 | 100  |   *  |      | VV       | m s-1   | V                                       |  0  |  2  |  3  | 100 |
  52 | 100  |   *  |      | RH       | %       | Relative Humidity                       |  0  |  1  |  1  | 100 |
   7 | 100  |   *  |      | HGT      | m       | Height                                  |  0  |  3  |  5  | 100 |
  11 | 105  |   2  |      | TT       | K       | Temperature       at 2 m                |  0  |  0  |  0  | 103 |
  52 | 105  |   2  |      | RH       | %       | Relative Humidity at 2 m                |  0  |  1  |  1  | 103 |
  33 | 105  |  10  |      | UU       | m s-1   | U                 at 10 m               |  0  |  2  |  2  | 103 |

I need SST, so I guess temperature is what I need, i.e. 0.0.0 . Use the CDO command to convert to grib and set the parameter code at the same time

cdo -f grb2 -setparam,0.0.0 split_temp.nc split_temp.grb2