"2-dimensional boolean indexing" , the error of ax.quiver() function when use cartopy

Viewed 357

An error: 2-dimensional boolean indexing is not supported. It appears when I want to draw wind field. I use ax.quiver() function of cartopy.

Here is the code:

dpath=r'E:\Data\Wind\era5wind2019.nc'
d=xr.open_dataset(dpath)
uw=d['u']
vw=d['v']
u=uw.loc['2019-01-01',:,:]
v=vw.loc['2019-01-01',:,:]
lat=uw.latitude
lon=uw.longitude

fig=plt.figure()
ax=fig.add_subplot(111,projection=ccrs.PlateCarree(180))
proj=ccrs.PlateCarree()
Q = ax.quiver(
        lon, lat, u, v, transform=proj,
        regrid_shape=20, angles='uv',
        scale=12, scale_units='xy',
        units='width', width=0.002
    )
2 Answers

I was having similar issues with ERA5 data, and found that the error disappears if you replace u and v in your call to ax.quiver with u.values and v.values.

When I tried it with ERA5 wind files of my own, I get the following warning, which vanishes if ccrs.PlateCarree() is given to both projection and transform.

~/.conda/envs/work/lib/python3.8/site-packages/cartopy/vector_transform.py:140: UserWarning: Some vectors at source domain corners may not have been transformed correctly
#   u, v = target_proj.transform_vectors(src_crs, x, y, u, v)

I suspect that some or all of the relevant data: lon, lat, u, v are not in single dimension and of the same length.

You can use .ravel() to convert them to use in .quiver():

Q = ax.quiver(lon.ravel(), lat.ravel(), u.ravel(), v.ravel(), ... )

This should work if the results have the same length.

Related