matplotlib / matplotlib/basemap

addcyclic problem with grib2 data

Offen
#287 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
817
Forks
395
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führen Sie das bereitgestellte Python-Skript mit den angegebenen Basemap-Versionen aus und untersuchen Sie den addcyclic-Aufruf, anschließend Basemap.__call__ und die gemeldete pyproj-Konvertierung. Vergleichen Sie die Formen von temp, lons und lats vor und nach addcyclic. Als abgeschlossen gilt die Aufgabe, wenn das GRIB2-Beispiel mit übereinstimmenden Koordinatenarrays abgeschlossen wird und das beabsichtigte Konturdiagramm erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
matplotlib, numpy, python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.