我正在尝试加载 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
相同的错误。
有什么建议吗?
最佳答案
我在使用 pygrib
时遇到了这个问题。问题的根源是 JPEG
支持,openjpeg
或 jasper
库有问题,经过多次尝试,我做了这个步骤通过重新安装 pygrib 解决此问题:
删除这个库:
yum remove openjpeg
和yum remove jasper
(我用的是 RHEL 7)重新安装此库后:
yum install openjpeg
和yum install jasper
确保不再安装
grib_api
或他的替代eccodes
。之后,从源安装eccodes
,按照这个instructions .安装目录对于下一步至关重要,在我的例子中,我将其安装在/usr/local/lib/eccodes
中(我在中创建了一个名为
),此目录在eccodes
的空目录>/usr/local/libcmake
期间使用参数-DCMAKE_INSTALL_PREFIX=/path/to/where/you/install/eccodes
.最后从源代码安装
pygrib
steps ,我只取消了setup.cfg
中第15行的注释,设置了grib_api_dir =/usr/local/lib/eccodes
(这里是安装目录的重要性)。如果安装没有问题通过test.py
问题就已经解决了。
关于python - 在 Python 中加载 grib2 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38003037/