matplotlib / matplotlib/basemap

addcyclic problem with grib2 data

Open
#287 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
817
Forks
395
PR merge metrics
No merged PRs in 30d

Description

I have some problems to use add cyclic with data from grib2 file.

This is my code:

``` python
# -*- 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
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
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](https://cloud.githubusercontent.com/assets/206782/14710978/d8246144-07d7-11e6-8467-13c2718886c4.png)

Thanks
Andrew

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

Tech stack
matplotlib, numpy, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.