From 65cdebd8d191cd48a732ab0136a4cc674e15afc4 Mon Sep 17 00:00:00 2001 From: Steve Decker Date: Thu, 10 Nov 2022 16:30:29 -0500 Subject: [PATCH] Add check before plotting wind barbs Fixes #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. --- src/metpy/plots/declarative.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/metpy/plots/declarative.py b/src/metpy/plots/declarative.py index 02585eb53d9..01da71db92e 100644 --- a/src/metpy/plots/declarative.py +++ b/src/metpy/plots/declarative.py @@ -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)