将NetCDF转换为GRIB2 [英] Converting NetCDF to GRIB2

查看:1414
本文介绍了将NetCDF转换为GRIB2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有像 wgrib2 这样的软件可以转换gribgrib2格式的文件转换为NetCDF文件,但我需要采取另一种方式:从NetCDFgrib2,因为这里的本地气象局只能使用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.

使用 NetCDF4-Python库

(或其他)读取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.

有更好的方法吗?

推荐答案

经过更多研究,我最终使用了英国气象局的虹膜"包装(

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆