Skip to content

Commit 65cdebd

Browse files
committed
Add check before plotting wind barbs
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.
1 parent 379fd6c commit 65cdebd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/metpy/plots/declarative.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,15 @@ def _build(self):
16601660

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

1663+
u_vals = u.values[wind_slice]
1664+
v_vals = v.values[wind_slice]
1665+
speeds = np.hypot(u_vals, v_vals)
1666+
if np.median(speeds) > 50000:
1667+
raise ValueError('Too many large wind barbs to plot')
1668+
16631669
self.handle = self.parent.ax.barbs(
16641670
x_like[wind_slice], y_like[wind_slice],
1665-
u.values[wind_slice], v.values[wind_slice],
1671+
u_vals, v_vals,
16661672
color=self.color, pivot=self.pivot, length=self.barblength, zorder=2, **kwargs)
16671673

16681674

0 commit comments

Comments
 (0)