matplotlib / matplotlib/basemap

contourf on cylindrical projection with irregular latlon grid (tri=True) is calling shiftdata when it shouldn't

Ouverte
#492 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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 ran into this problem while trying to plot interpolated data NOT on a regular latlon grid. Orthographic projection works but cylindrical does not.

Relevant code:

fig = plt.figure()
ax = fig.add_subplot(111)
levels = 20
m = Basemap(projection="cyl")  # causes ValueError
# m = Basemap(projection="ortho", lat_0=0., lon_0=0., resolution='l')  # works, does not cause ValueError
MC = m.contourf(lons_deg, lats_deg, vals, levels, ax=ax, tri=True, latlon=True)  # latlon=True interprets first two args as lon and lat respectively

Note that lats_deg, lons_deg, and vals are 1d np arrays with irregular point spacing (no meshgrid). I used tri=True to allow interpolation. This works fine on orthographic projection. But with cylindrical I get the following error:

Traceback (most recent call last):
  File "IcosahedralGeodesicLattice.py", line 146, in <module>
    test_lattice.plot_data(data)
  File "/home/wesley/programming/Mapping/Lattice.py", line 86, in plot_data
    MC = m.contourf(lons_deg, lats_deg, vals, levels, ax=ax, tri=True, latlon=True)  # latlon=True interprets first two args as LON and LAT RESPECTIVELY
  File "/home/wesley/.local/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py", line 544, in with_transform
    fix_wrap_around=plotfunc.__name__ not in ["scatter"])
  File "/home/wesley/.local/lib/python3.5/site-packages/mpl_toolkits/basemap/__init__.py", line 4797, in shiftdata
    if fix_wrap_around and itemindex:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Looking at the relevant file, the docstring for shiftdata says "Only valid for cylindrical/pseudo-cylindrical global projections and data on regular lat/lon grids. longitudes and data can be 1-d or 2-d, if 2-d it is assumed longitudes are 2nd (rightmost) dimension."

So should it not be being called with tri=True? Sorry if I have misunderstood something, let me know. Thanks!

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez dans lib/mpl_toolkits/basemap/init.py, en suivant le wrapper contourf jusqu’à shiftdata et au contrôle de itemindex indiqué dans le traceback. Reproduisez l’exemple avec une projection cylindrique, des tableaux 1D irréguliers, tri=True et latlon=True, puis comparez-le à la projection orthographique ; le travail est terminé lorsque le cas cylindrique ne déclenche plus le ValueError de tableau ambigu et que le comportement sur une grille régulière reste intact.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
matplotlib, 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
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.