3

我正在尝试加载 grib2 文件,但我不确定这些文件是否是问题所在,或者我尝试加载它们的方式。

这些文件是从这里提取的(我没有从这里下载它们,而是从一个从这里获取它们的同事的文件夹中复制它们 - 所以它们实际上应该是相同的文件......,但我也尝试插入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

有什么建议吗?

4

1 回答 1

1

我有这个问题pygrib。问题的根源在于JPEG支持,openjpeg或者jasper库有问题,经过多次尝试,我采取了以下步骤通过重新安装 pygrib 来解决这个问题:

  • 删除此库:

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

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

    yum install openjpegyum install jasper

  • 确保grib_api或他的替代品eccodes不再安装。之后,eccodes从源代码安装,按照此说明进行操作。安装目录对于下一步至关重要,在我的情况下,我将其安装在(我创建了一个名为in/usr/local/lib/eccodes的空目录),该目录在使用参数时指定。eccodes/usr/local/libcmake-DCMAKE_INSTALL_PREFIX=/path/to/where/you/install/eccodes

  • 最后pygrib按照这个步骤从源安装,我只取消了setup.cfgand设置 中的第15行grib_api_dir = /usr/local/lib/eccodes(这里是安装目录的重要性)。如果安装没有问题,test.py则问题已经解决。

于 2019-03-05T16:00:15.337 回答