matplotlib / basemap

Plot on map projections (with coastlines and political boundaries) using matplotlib
MIT License
780 stars 392 forks source link

addcyclic: TypeError: invalid indexer array #427

Closed am-thyst closed 6 years ago

am-thyst commented 6 years ago
lon = dataset.longitude
lat = dataset.latitude
print(dataset.shape)
(241, 480)
print(lon.shape)
(480,)
print(lat.shape)
(241,)

fig = plt.figure()
ax = fig.add_axes([0.1,0.1,0.8,0.8])
m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,\
            llcrnrlon=-180,urcrnrlon=180, resolution='c')

dataset, lona = addcyclic(dataset, lon)
TypeError: invalid indexer array, does not have integer dtype: array([slice(None, None, None), slice(0, 1, None)], dtype=object)

I can't understand why I'm getting this TypeError?

WeatherGod commented 6 years ago

This is not a fully self-contained example. It would also be useful to know which version of basemap you are using, and where you installed it from. Also, could you include the full traceback, please?

On Tue, Oct 9, 2018 at 12:36 PM Amethyst notifications@github.com wrote:

lon = dataset.longitude lat = dataset.latitudeprint(dataset.shape) (241, 480)print(lon.shape) (480,)print(lat.shape) (241,)

fig = plt.figure() ax = fig.add_axes([0.1,0.1,0.8,0.8]) m = Basemap(projection='cyl',llcrnrlat=-90,urcrnrlat=90,\ llcrnrlon=-180,urcrnrlon=180, resolution='c')

dataset, lona = addcyclic(dataset, lon)TypeError: invalid indexer array, does not have integer dtype: array([slice(None, None, None), slice(0, 1, None)], dtype=object)

I can't understand why I'm getting this TypeError?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/matplotlib/basemap/issues/427, or mute the thread https://github.com/notifications/unsubscribe-auth/AARy-G7ZDFN5MVSBedsaWiekYb-sVD56ks5ujNCEgaJpZM4XTrjQ .

am-thyst commented 6 years ago

@WeatherGod It says my version of Basemap is 1.0.8.dev0, I think I saw that there is a 1.1.0? But conda says it is already up to date. I used conda-forge to install it. Here's the full traceback:

Traceback (most recent call last):
  File "/var/spool/torque/mom_priv/jobs/63449.rdf-xcat.SC", line 46, in <module>
    pa2, lona = addcyclic(pa, lon)
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py", line 5145, in addcyclic
    return list(map(_addcyclic,arr[:-1])) + [_addcyclic_lon(arr[-1])]
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py", line 5130, in _addcyclic
    return npsel.concatenate((a,a[slicer]),axis=axis)
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/dataarray.py", line 474, in __getitem__
    return self.isel(indexers=self._item_key_to_dict(key))
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/dataarray.py", line 819, in isel
    ds = self._to_temp_dataset().isel(drop=drop, indexers=indexers)
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/dataset.py", line 1539, in isel
    new_var = var.isel(indexers=var_indexers)
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 907, in isel
    return self[tuple(key)]
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 616, in __getitem__
    dims, indexer, new_order = self._broadcast_indexes(key)
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 487, in _broadcast_indexes
    return self._broadcast_indexes_outer(key)
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 539, in _broadcast_indexes_outer
    return dims, OuterIndexer(tuple(new_key)), None
  File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/indexing.py", line 378, in __init__
    'integer dtype: {!r}'.format(k))
TypeError: invalid indexer array, does not have integer dtype: array([slice(None, None, None), slice(0, 1, None)], dtype=object)
WeatherGod commented 6 years ago

Ah, you are using xarray.DataArray objects. They don't behave quite like numpy arrays. Try converting them into numpy arrays before passing them into addcyclic. This is usually done by accessing the DataArray's .values attribute.

When calling conda update on a package that came from conda-forge, you should specify -c conda-forge. The basemap that is in the default channel hasn't been updated in forever (I have no control over that).

On Tue, Oct 9, 2018 at 1:27 PM Amethyst notifications@github.com wrote:

@WeatherGod https://github.com/WeatherGod It says my version of Basemap is 1.0.8.dev0, I think I saw that there is a 1.1.0? But conda says it is already up to date. I used conda-forge to install it. Here's the full traceback:

Traceback (most recent call last): File "/var/spool/torque/mom_priv/jobs/63449.rdf-xcat.SC", line 46, in pa2, lona = addcyclic(pa, lon) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/mpl_toolkits/basemap/init.py", line 5145, in addcyclic return list(map(_addcyclic,arr[:-1])) + [_addcyclic_lon(arr[-1])] File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/mpl_toolkits/basemap/init.py", line 5130, in _addcyclic return npsel.concatenate((a,a[slicer]),axis=axis) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/dataarray.py", line 474, in getitem return self.isel(indexers=self._item_key_to_dict(key)) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/dataarray.py", line 819, in isel ds = self._to_temp_dataset().isel(drop=drop, indexers=indexers) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/dataset.py", line 1539, in isel new_var = var.isel(indexers=var_indexers) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 907, in isel return self[tuple(key)] File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 616, in getitem dims, indexer, new_order = self._broadcast_indexes(key) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 487, in _broadcast_indexes return self._broadcast_indexes_outer(key) File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/variable.py", line 539, in _broadcast_indexes_outer return dims, OuterIndexer(tuple(new_key)), None File "/nerc/n02/n02/amethyst/.conda/envs/my_root/lib/python3.4/site-packages/xarray/core/indexing.py", line 378, in init 'integer dtype: {!r}'.format(k))TypeError: invalid indexer array, does not have integer dtype: array([slice(None, None, None), slice(0, 1, None)], dtype=object)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/matplotlib/basemap/issues/427#issuecomment-428279672, or mute the thread https://github.com/notifications/unsubscribe-auth/AARy-EYPwQOg9juESxfPFPNXMUHAl1kIks5ujNyHgaJpZM4XTrjQ .

am-thyst commented 6 years ago

Thanks @WeatherGod, this worked