matplotlib / matplotlib/basemap

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

オープン
#492 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
817
フォーク
395
PR マージ指標
30日以内にマージされた PR はありません

説明

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
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](https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/__init__.py), 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!

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

lib/mpl_toolkits/basemap/__init__.py から始め、contourf ラッパーをたどって shiftdata と traceback に示されている itemindex チェックを確認します。円筒図法、不規則な 1D 配列、tri=True、latlon=True を使って例を再現し、その後、正射図法の場合と比較します。完了条件は、円筒図法の場合に ambiguous-array の ValueError が発生しなくなり、規則格子の動作が維持されることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
matplotlib, python
領域
data-visualization
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。