matplotlib / matplotlib/basemap
addcyclic problem with grib2 data
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 817
- 派生
- 395
- PR 合并指标
- 30 天内没有已合并 PR
描述
I have some problems to use add cyclic with data from grib2 file.
This is my code:
# -*- coding: utf-8 -*-
import pygrib
import numpy as np
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from mpl_toolkits.basemap import Basemap, addcyclic
fig = Figure((4, 3))
canvas = FigureCanvas(fig)
ax = fig.add_axes([0.05, 0.05, 0.9, 0.9])
# File download from http://para.nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/para/gfs.2016041918/gfs.t18z.pgrb2.0p25.f000
grbindx = pygrib.index('gfs.t18z.pgrb2.0p25.f000', 'shortName', 'typeOfLevel', 'level')
grb = grbindx.select(shortName='2t', typeOfLevel='heightAboveGround', level=2)[0]
lats, lons = grb.latlons()
temp = grb.values
temp, lons = addcyclic(temp, lons)
bm = Basemap(projection='mill', resolution='l', ax=ax,
llcrnrlat=32, urcrnrlat=70, llcrnrlon=-25,
urcrnrlon=40.5, lat_ts=20)
x, y = bm(lons, lats)
bm.contourf(x, y, temp)
bm.drawcoastlines()
canvas.print_figure('gfs_temperature_2m.png', dpi=100)
With python 2.7.11 and basemap 1.0.7 this is the result:
Traceback (most recent call last):
File "addcyclic.py", line 21, in <module>
temp, lons = addcyclic(temp, lons)
File "/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 5062, in addcyclic
lonsout[0:nlons] = lonsin[:]
ValueError: could not broadcast input array from shape (721,1440) into shape (1440)
With python 2.7.11 and basemap 1.0.8 (from latest github commit) this is the result:
Traceback (most recent call last):
File "addcyclic.py", line 27, in <module>
x, y = bm(lons, lats)
File "/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py", line 1175, in __call__
xout,yout = self.projtran(x,y,inverse=inverse)
File "/usr/local/lib/python2.7/site-packages/mpl_toolkits/basemap/proj.py", line 286, in __call__
outx,outy = self._proj4(x, y, inverse=inverse)
File "/usr/local/lib/python2.7/site-packages/pyproj/__init__.py", line 399, in __call__
_proj.Proj._fwd(self, inx, iny, radians=radians, errcheck=errcheck)
File "_proj.pyx", line 128, in _proj.Proj._fwd (_proj.c:1678)
RuntimeError: Buffer lengths not the same
Where is the problem?
Some bug in basemap? Or in my code?
Without addcycle this is the result:

Thanks
Andrew
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用指定的 Basemap 版本运行提供的 Python 脚本,并检查 addcyclic 调用,随后检查 Basemap.call 以及报告的 pyproj 转换。比较 addcyclic 前后 temp、lons 和 lats 的形状。完成的标准是 GRIB2 示例能够运行结束,坐标数组彼此匹配,并生成预期的等高线图。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- matplotlib, numpy, python
- 领域
- data-visualization
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100