SciTools / cartopy

Cartopy - a cartographic python library with matplotlib support
https://scitools.org.uk/cartopy/docs/latest
BSD 3-Clause "New" or "Revised" License
1.4k stars 359 forks source link

Request to add transform_first keyword to barbs #2395

Open greglucas opened 2 months ago

greglucas commented 2 months ago

Would it be possible to implement something similar to #1291 with barbs? I am experiencing significant slowdowns with the barb transformation with high-resolution data. Appears I'm not the only one: https://stackoverflow.com/questions/71578820/use-transform-first-keyword-in-barbs

Originally posted by @karlwx in https://github.com/SciTools/cartopy/issues/1291#issuecomment-2140829116

greglucas commented 2 months ago

@karlwx I think it would be a little trickier because you need to transform vectors instead of just scalars, but it should in principle be doable. We do have a decorator that you could try playing around with to see whether it would work for your use-case and/or modifying it for the vector transform paths. https://github.com/SciTools/cartopy/blob/ea946a1d47e110d9274833d803eb068ab394c77c/lib/cartopy/mpl/geoaxes.py#L311 used in Contour here: https://github.com/SciTools/cartopy/blob/ea946a1d47e110d9274833d803eb068ab394c77c/lib/cartopy/mpl/geoaxes.py#L1572-L1574

karlwx commented 2 months ago

Thanks @greglucas. Maybe an easier solution would be to add a keyword argument that would automatically thin the arrays of x, y, and data based on the number of data points within the map extent and the value of regrid_shape before transforming?

greglucas commented 2 months ago

Possibly, I'm not sure what that would look like though... Would you be able to do that yourself beforehand something like barbs(x[::3, ::3], y[::3, ::3], ...)?

The regridding is located here if you want to dig in and try things out: https://github.com/SciTools/cartopy/blob/ea946a1d47e110d9274833d803eb068ab394c77c/lib/cartopy/vector_transform.py#L19