问题描述
我知道有像 wgrib2 这样的软件可以转换grib
和grib2
格式的文件转换为NetCDF
文件,但我需要采取另一种方式:从NetCDF
到grib2
,因为这里的本地气象局只能使用grib2
格式的栅格数据
I know there is software like wgrib2 that will convert files in grib
and grib2
format to NetCDF
files, but I need to go the other way: from NetCDF
to grib2
, because the local weather offices here can only consume gridded data in grib2
format.
NetCDF
文件,并使用 pygrib 编写grib2
.It appears that one solution could be in Python, using the NetCDF4-Python library (or other) to read the NetCDF
files and using pygrib to write grib2
.
有更好的方法吗?
推荐答案
经过更多研究,我最终使用了英国气象局的虹膜"包装( http://scitools.org.uk/iris/docs/latest/index.html ),它可以读取NetCDF以及OPeNDAP,GRIB以及其他几种格式,并允许另存为NetCDF或GRIB.
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.
基本上,代码如下:
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
但是,如果您的netcdf文件没有足够的元数据,则可能需要添加它,您也可以使用Iris进行添加.这是一个完整的工作示例:
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
这篇关于将NetCDF转换为GRIB2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!