matplotlib / matplotlib/basemap
addcyclic problem with grib2 data
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 817
- Forks
- 395
- Métriques de merge des PR
- Aucune PR mergée en 30 j
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:

Thanks
Andrew
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Exécutez le script Python fourni avec les versions de Basemap indiquées et examinez l'appel à addcyclic, puis Basemap.__call__ et la conversion pyproj signalée. Comparez les dimensions de temp, lons et lats avant et après addcyclic. Le travail est considéré comme terminé lorsque l'exemple GRIB2 s'exécute jusqu'au bout avec des tableaux de coordonnées correspondants et produit le graphique de contours attendu.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- matplotlib, numpy, python
- Domaine
- data-visualization
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100