addcyclic problem with grib2 data
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- matplotlib, numpy, python
- Domain
- data-visualization
Research direction
Run the supplied Python script with the stated Basemap versions and inspect the addcyclic call, followed by Basemap.call and the reported pyproj conversion. Compare the shapes of temp, lons, and lats before and after addcyclic. Done means the GRIB2 example completes with matching coordinate arrays and produces the intended contour plot.
Written by the indexing model from the issue text.
Description
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
- Dominant language
- Python
- Stars
- 817
- Forks
- 395
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from matplotlib/basemap
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
matplotlib/basemap#368 ·
-
Python 3.14 wheels Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
matplotlib/basemap#652 · 2 comments · 5 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
matplotlib/basemap#649 · 2 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
matplotlib/basemap#646 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 48/100
matplotlib/basemap#645 · 2 comments ·
All issues in matplotlib/basemap
Similar issues
-
sponsored
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Diaoul/subliminal#1382 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
triage/confirmed
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
agentscope-ai/agentscope#2775 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100