addcyclic problem with grib2 data

Open
#287 9 comments 0 reactions 0 assignees View on GitHub

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

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

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from matplotlib/basemap

All issues in matplotlib/basemap

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.