Converting NetCDF to GRIB2

◇◆丶佛笑我妖孽 提交于 2019-12-04 04:37:25

After some more research, I ended up using the British Met Office "Iris" package (http://scitools.org.uk/iris/docs/latest/index.html) which can read NetCDF as well as OPeNDAP, GRIB and several other formats, and allows to save as NetCDF or GRIB.

Basically the code looks like:

import iris

cubes = iris.load('input.nc')       # each variable in the netcdf file is a cube
iris.save(cubes[0],'output.grib2')  # save a specific variable to grib 

But if your netcdf file doesn't contain sufficient metadata, you may need to add it, which you can also do with Iris. Here's a full working example:

https://github.com/rsignell-usgs/ipython-notebooks/blob/master/files/Iris_CFSR_wave_wind.ipynb

msi_gerva

One can also use climate data operators (cdo's) for the task -https://code.zmaw.de/projects/cdo/wiki

but need to install the software with all additional libraries.

I know CDO is mentioned above, but I thought it would be useful to give the full command

cdo -f grb2 copy in.nc out.grb

ECMWF has a command line based tool to do just this: https://software.ecmwf.int/wiki/display/GRIB/grib_to_netcdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!