Skip to content

Commit

Permalink
Add check before plotting wind barbs
Browse files Browse the repository at this point in the history
Fixes Unidata#2785.

Currently, BarbPlot is happy to attempt to plot very large wind barbs,
but if the size becomes too large, memory usage becomes an issue,
leading to system hangs.  This commit adds a check to make sure the
wind barbs will not consist of so many pennants that memory could be
an issue.
  • Loading branch information
sgdecker committed Nov 10, 2022
1 parent 379fd6c commit 65cdebd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,9 +1660,15 @@ def _build(self):

wind_slice = (slice(None, None, self.skip[0]), slice(None, None, self.skip[1]))

u_vals = u.values[wind_slice]
v_vals = v.values[wind_slice]
speeds = np.hypot(u_vals, v_vals)
if np.median(speeds) > 50000:
raise ValueError('Too many large wind barbs to plot')

self.handle = self.parent.ax.barbs(
x_like[wind_slice], y_like[wind_slice],
u.values[wind_slice], v.values[wind_slice],
u_vals, v_vals,
color=self.color, pivot=self.pivot, length=self.barblength, zorder=2, **kwargs)


Expand Down

0 comments on commit 65cdebd

Please sign in to comment.