【问题标题】:pygrib GRIB2 segmenation fault while reading data读取数据时pygrib GRIB2分段错误
【发布时间】:2015-03-21 22:38:54
【问题描述】:

我遇到了一个 Python 脚本问题,该脚本从 grib2 格式的天气模型 (GFS) 下载最近的天气数据。它曾经可以工作,但现在不再有效(即在 GFS 服务器上下载最近的文件)。 尝试访问数据时,我遇到了分段错误,我什至不知道从哪里开始。 下面是两个示例(工作和不工作)。我运行 linux mint cinnamon。我安装了 python-grib 和 python3-grib(版本:1.9.8-1build2,通过软件管理器)。

任何建议将不胜感激。

Ps:给出分段错误的文件示例如下: http://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs.2015013000/ 文件名:gfs.t00z.master.grbf003.10m.uv.grib2

我认为旧文件不会保存在该服务器上。不过,可以在此处找到一个示例: http://grib.virtual-loup-de-mer.org/archives/2014/0130/ 文件名:gfs.t00z.master.grbf03.10m.uv.grib2

Pps:抱歉拖了这么久。我已经从 1.98 安装了 pygrib 2.0 版,它现在可以工作了。 Arghh,我花了很长时间来尝试这个(并实际正确安装它)。但就是这样。 无论如何,对所有答案的每个人都表示“感谢”, 拉提亚

/usr/bin/python3.4:

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

工作脚本:

import pygrib

grbs = pygrib.open('winddata1.grib2')

for grb in grbs:

...     grb

... 

1:10 metre U wind component:m s**-1 (instant):regular_ll:heightAboveGround:level 10 m:fcst time 0 hrs:from 201411041200
2:10 metre V wind component:m s**-1 (instant):regular_ll:heightAboveGround:level 10 m:fcst time 0 hrs:from 201411041200

grb = grbs.message(1)

wind = grb.data(lat1=20,lat2=70,lon1=220,lon2=320)

quit()

/usr/bin/python3.4:

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

失败的脚本:

import pygrib

grbs = pygrib.open('winddata2.grib2')

for grb in grbs:
...     grb
... 
1:10 metre U wind component:m s**-1 (instant):regular_ll:heightAboveGround:level 10 m:fcst time 0 hrs:from 201501220600

2:10 metre V wind component:m s**-1 (instant):regular_ll:heightAboveGround:level 10 m:fcst time 0 hrs:from 201501220600

grb = grbs.message(1)

wind = grb.data(lat1=20,lat2=70,lon1=220,lon2=320)

错误:

Segmentation fault

编辑(希望这是有道理的)

运行(作为脚本 testing.py)给了我:

gdb -ex r --args /usr/bin/python3.4 testing.py

GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/bin/python3.4...(no debugging symbols found)...done.
Starting program: /usr/bin/python3.4 testing.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
1:10 metre U wind component:m s**-1    (instant):regular_ll:heightAboveGround:level 10 m:fcst time 0 hrs:from 201501220600
2:10 metre V wind component:m s**-1 (instant):regular_ll:heightAboveGround:level 10 m:fcst time 0 hrs:from 201501220600

Program received signal SIGSEGV, Segmentation fault.
0x000000000053b684 in PyLong_AsVoidPtr ()
(gdb) bt
#0  0x000000000053b684 in PyLong_AsVoidPtr ()
#1  0x00007ffff5968da7 in ?? () from /usr/lib/python3/dist-packages/numpy/core/multiarray.cpython-34m-x86_64-linux-gnu.so
#2  0x0000000000533cd2 in PyObject_AsReadBuffer ()
#3  0x00007ffff21c9f00 in ?? () from /usr/lib/python3/dist-packages/g2clib.cpython-34m-x86_64-linux-gnu.so
#4  0x000000000057bf33 in PyEval_EvalFrameEx ()
#5  0x000000000057d3d3 in PyEval_EvalCodeEx ()
#6  0x000000000057df80 in ?? ()
#7  0x000000000043810a in PyObject_Call ()
#8  0x00000000004d3745 in ?? ()
#9  0x000000000043810a in PyObject_Call ()
#10 0x00007ffff677669c in ?? () from /usr/lib/python3/dist-packages/pygrib.cpython-34m-x86_64-linux-gnu.so
#11 0x000000000043810a in PyObject_Call ()
#12 0x00007ffff675788a in ?? () from /usr/lib/python3/dist-packages/pygrib.cpython-34m-x86_64-linux-gnu.so
#13 0x00007ffff6762ece in ?? () from /usr/lib/python3/dist-packages/pygrib.cpython-34m-x86_64-linux-gnu.so
#14 0x000000000057bf33 in PyEval_EvalFrameEx ()
#15 0x000000000057d3d3 in PyEval_EvalCodeEx ()
#16 0x000000000060ba83 in PyRun_FileExFlags ()
#17 0x000000000060bc85 in PyRun_SimpleFileExFlags ()
#18 0x000000000060d3ac in Py_Main ()
#19 0x000000000041ec0d in main ()

【问题讨论】:

  • 如果您将这两个 winddata 文件共享/链接给我们,也许有助于发现问题?
  • gdb 下运行它并发布堆栈跟踪。
  • 之前没用过gdb。我仍在研究如何获取堆栈跟踪 - 将在我管理后立即发布(但可能需要一段时间)。谢谢,L。
  • 您能描述一下您是如何运行脚本的吗?从你的帖子来看,对我来说,看起来你是在交互模式下运行它,而不是脚本。无论如何,如果我的记忆是正确的 pygrib 是用 pyrex 编写的 ac 模块,所以如果你想调试 pygrib,你应该使用 sys. settrace,比 gdb 容易得多。

标签: python grib


【解决方案1】:

您正在运行什么版本的 pygrib 库? http://pygrib.googlecode.com/svn/trunk/Changelog 的发行说明描述了几种情况,其中制作了新版本来处理导致段错误错误的问题。我会拉下最新的,看看错误是否仍然存在。

【讨论】:

  • 嗨,很抱歉回复晚了。最后,使用 2.x 版成功了。
猜你喜欢
  • 2017-02-16
  • 2021-03-13
  • 2017-10-29
  • 1970-01-01
  • 2016-10-05
  • 1970-01-01
  • 2017-09-18
  • 2011-11-14
  • 1970-01-01
相关资源
最近更新 更多