在python中加载grib2文件

时间:2016-06-23 22:38:16

标签: python grib python-xarray

我正在尝试加载grib2文件,我不确定文件是否是问题,或者我是否尝试加载它们。

这些文件是从here中提取的(我没有从这里下载它们,但是从一个从这里获取它们的同事的文件夹中复制它们 - 所以它们应该是相同的文件.. 。,但我还试图插入ftp地址并得到相同的错误。)

我累了pygrib

grbs = pygrib.open('pgbf2016060100.01.2016053100.grib2')

出现此错误:

---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-20-674763ffdd1f> in <module>()
----> 1 grbs = pygrib.open('pgbf2016060100.01.2016053100.grib2')

pygrib.pyx in pygrib.open.__cinit__ (pygrib.c:2772)()

IOError: [Errno could not open %s] pgbf2016060100.01.2016053100.grib2

我尝试了xarray

ds = xr.open_dataset("pgbf2016060100.01.2016053100.grb2",engine='pynio')

我收到此错误

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/software/centos6/x86_64/canopy-1.5.2/Canopy_64bit/User/lib/python2.7/site-    packages/IPython/core/interactiveshell.pyc in run_code(self, code_obj, result)
   3081             if result is not None:
   3082                 result.error_in_exec = sys.exc_info()[1]
-> 3083             self.showtraceback()
   3084         else:
   3085             outflag = 0

/software/centos6/x86_64/canopy-1.5.2/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in showtraceback(self, exc_tuple,     filename, tb_offset, exception_only)
   1858                 return
   1859 
-> 1860             if issubclass(etype, SyntaxError):
   1861                 # Though this won't be called by syntax errors in the input
   1862                 # line, there may be SyntaxError cases with imported code.

TypeError: issubclass() arg 1 must be a class

我直接尝试了NIO

f = nio.open_file("pgbf2016060100.01.2016053100.grb2")

我得到与xarray中的错误相同的错误。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我遇到pygrib这个问题。问题的根源是对JPEG的支持,openjpegjasper库出了点问题,经过多次尝试,我采取了以下步骤来重新安装pygrib来解决此问题:< / p>

  • 使用以下方法删除此库:

    yum remove openjpegyum remove jasper(我使用RHEL 7)

  • 使用以下命令重新安装此库之后:

    yum install openjpegyum install jasper

  • 确保不再安装grib_api或他的替代品eccodes。之后,从源代码安装eccodes,然后遵循此instructions。安装目录对于下一步至关重要,在我的情况下,我将其安装在/usr/local/lib/eccodes中(在eccodes中创建了一个名为/usr/local/lib的空目录),该目录在{{ 1}},参数为cmake

  • 最后在此steps之后从源代码安装-DCMAKE_INSTALL_PREFIX=/path/to/where/you/install/eccodes,我只取消注释pygrib中的第15行并设置setup.cfg(以下是安装目录)。如果安装顺利完成,grib_api_dir = /usr/local/lib/eccodes问题就解决了。