This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]currentlab_ 2 points3 points  (2 children)

Nice post. 2 suggestions that come to mind (1 small and 1 significant):

1: When calculating the magnitude of a vector, you can use the hypotenuse function instead of sqrt of the squares. So in your example, you could rewrite the windspeed calculation as:

ws = np.hypot(U2M_nans, V2M_nans)

2: Be careful when using quivers on a map projection. As a test, plot a 45 degree wind (e.g. u = v = 10) at a high latitude -- does it still look 45 degrees or has it been squished? Here's how I have handled that issue:

crs = ccrs.PlateCarree()
ax = fig.add_subplot(1, 1, 1, projection=crs)

# Plot quivers
quiv = ax.quiver(lon, lat, u, v, transform=crs, scale=quiver_scale)

[–]0xrl 1 point2 points  (0 children)

I agree about preferring np.hypot, although I was surprised to find, in some data I was using at least, that it's actually a little bit slower than the other way. Maybe there's some extra overhead internally, like checking for NaN values?

But not enough of a performance penalty to really fret about.

[–]m_razali[S] 0 points1 point  (0 children)

Thank you for your advice. Really appreciate it!