- The following examples use the CDO tool, which is free to download from:
https://code.mpimet.mpg.de/projects/cdo - In the terminal, we will convert the grib file from reduced Gaussian to regular lat/lon. In order to this we need to know the number of regular latitude points correspoding to the linear reduced Gaussian grid (T799~N400), which can be found at:
https://www.ecmwf.int/en/forecasts/documentation-and-support/gaussian_n400 - Given there are 1600 regular latitude points (and 800 longitude points), we can convert our reduced Gaussian grid to regular lat/lon:
module load cdo
- To convert to regular lat/lon
cdo -R remapcon,r1600x800 -setgridtype,regular h14_2019053000.grib h14_2019053000_r.grib
- Then convert the file from grib to netcdf:
cdo -f nc copy h14_2019053000_r.grib h14_2019053000.nc
- Then extract the Italian domain from the global netcdf file (lon0=5, lon1=19, lat0=36, lat1=48):
cdo -sellonlatbox,5,19,36,48 h14_2019053000.nc h14_2019053000_Italy.nc
#Note that the size of the file is vastly reduced (h14_2019053000.nc ~ 25 mb, h14_2019053000_Italy.nc ~ 70 kb)!
- Size of netCDF files can be further reduced by compression e.g.
cdo -f nc4c -z zip_6 copy h14_2019053000_r.grib h14_2019053000_compressed.nc - To convert multiple files from grib to netCDF, you can loop over all the files in the directory and apply the commands above e.g.
for file in *.grib; do cdo -R remapcon,r1600x800 -setgridtype,regular "$file" "$file".reg; done #To convert to regular grid
for file in *.reg; do cdo -f nc copy "$file" "$file".nc; done #To convert regular grib files to netCDF
for file in *.nc; do cdo -sellonlatbox,5,19,36,48 "$file" "$file"_italy; done #To extract Italian domain
- A time series file can be created by stacking multiple daily netcdf files, for example using cdo mergetime:
cdo mergetime h27*.nc time_series.nc