abdulhakeem amer
abdulhakeem amer

Reputation: 31

converting Grib to netcdf4

I downloaded data from ECMWF for Era interim in grib format. Is there a way to convert a grib file with multiple bands to netCDF4, keeping the bands in the NETCDF format?

I tried using the cdo operations, but the output will be only the first band of the grib file.

cdo -f nc copy input.grib output.nc

Upvotes: 3

Views: 11868

Answers (2)

ClimateUnboxed
ClimateUnboxed

Reputation: 8087

For this kind of task using ECMWF data it is usually better to install eccodes. For example on a mac you can do

brew install eccodes

This will give you a lot of useful command line tools and, as long as the input file is on a regular lat/lon grid or a regular Gaussian grid (the key "typeOfGrid" should be "regular_ll" or "regular_gg") you can convert to netcdf

grib_to_netcdf -o output.nc input.grb 

This tool is more powerful than CDO in that it can handle multiple time axes (e.g. seasonal forecasts with multiple start dates) and also extra dimensions such as ensemble member number, which can trip CDO up.

NOTE: The title to the question states netcdf4 is required but you used the -f nc option for cdo. Note that to specify netcdf4 with cdo you should use

cdo -f nc4 

Upvotes: 3

dl.meteo
dl.meteo

Reputation: 1766

Yes there is a very comfortable way using python, xarray and cfgrib (requires ECCODES).

Installing cfgrib as mentioned here on the github page you will have all required grib tables in the eccodes installation.

Afterwards you just have to open your grib file:

import xarray

data = xarray.open_dataset('path_to_grib_file.grib1', engine='cfgrib')
data.to_netcdf('netcdf_file.nc')

Upvotes: 7

Related Questions