Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

addcyclic problem with grib2 data

未關閉
#287 9 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
matplotlib, numpy, python

研究方向

使用指定的 Basemap 版本執行提供的 Python 指令碼,並檢查 addcyclic 呼叫,接著檢查 Basemap.call 以及回報的 pyproj 轉換。比較 addcyclic 前後 temp、lons 和 lats 的形狀。完成的標準是 GRIB2 範例能夠執行結束,座標陣列彼此相符,並產生預期的等高線圖。

由索引模型根據 Issue 內容生成。

描述

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:
gfs_temperature_2m

Thanks
Andrew

主要語言
Python
星號
817
分支
394
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

matplotlib/basemap 的其他 Issue

查看 matplotlib/basemap 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。