Skip to content

Wind Barbs

WindBarbsPlot

Bases: SpatialPlot

Create a barbs plot of wind on a map.

This plot shows wind speed and direction using barbs.

Source code in src/monet_plots/plots/wind_barbs.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class WindBarbsPlot(SpatialPlot):
    """Create a barbs plot of wind on a map.

    This plot shows wind speed and direction using barbs.
    """

    def __init__(self, ws: Any, wdir: Any, gridobj, *args, **kwargs):
        """
        Initialize the plot with data and map projection.

        Args:
            ws (np.ndarray, pd.DataFrame, pd.Series, xr.DataArray): 2D array of wind speeds.
            wdir (np.ndarray, pd.DataFrame, pd.Series, xr.DataArray): 2D array of wind directions.
            gridobj (object): Object with LAT and LON variables.
            **kwargs: Keyword arguments passed to SpatialPlot for projection and features.
        """
        super().__init__(*args, **kwargs)
        self.ws = np.asarray(ws)
        self.wdir = np.asarray(wdir)
        self.gridobj = gridobj

    def plot(self, **kwargs):
        """Generate the wind barbs plot."""
        barb_kwargs = self.add_features(**kwargs)
        barb_kwargs.setdefault("transform", ccrs.PlateCarree())

        lat = self.gridobj.variables["LAT"][0, 0, :, :].squeeze()
        lon = self.gridobj.variables["LON"][0, 0, :, :].squeeze()
        u, v = tools.wsdir2uv(self.ws, self.wdir)
        # Subsample the data for clarity
        skip = barb_kwargs.pop("skip", 15)
        self.ax.barbs(
            lon[::skip, ::skip],
            lat[::skip, ::skip],
            u[::skip, ::skip],
            v[::skip, ::skip],
            **barb_kwargs,
        )
        return self.ax

__init__(ws, wdir, gridobj, *args, **kwargs)

Initialize the plot with data and map projection.

Parameters:

Name Type Description Default
ws (ndarray, DataFrame, Series, DataArray)

2D array of wind speeds.

required
wdir (ndarray, DataFrame, Series, DataArray)

2D array of wind directions.

required
gridobj object

Object with LAT and LON variables.

required
**kwargs

Keyword arguments passed to SpatialPlot for projection and features.

{}
Source code in src/monet_plots/plots/wind_barbs.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def __init__(self, ws: Any, wdir: Any, gridobj, *args, **kwargs):
    """
    Initialize the plot with data and map projection.

    Args:
        ws (np.ndarray, pd.DataFrame, pd.Series, xr.DataArray): 2D array of wind speeds.
        wdir (np.ndarray, pd.DataFrame, pd.Series, xr.DataArray): 2D array of wind directions.
        gridobj (object): Object with LAT and LON variables.
        **kwargs: Keyword arguments passed to SpatialPlot for projection and features.
    """
    super().__init__(*args, **kwargs)
    self.ws = np.asarray(ws)
    self.wdir = np.asarray(wdir)
    self.gridobj = gridobj

plot(**kwargs)

Generate the wind barbs plot.

Source code in src/monet_plots/plots/wind_barbs.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def plot(self, **kwargs):
    """Generate the wind barbs plot."""
    barb_kwargs = self.add_features(**kwargs)
    barb_kwargs.setdefault("transform", ccrs.PlateCarree())

    lat = self.gridobj.variables["LAT"][0, 0, :, :].squeeze()
    lon = self.gridobj.variables["LON"][0, 0, :, :].squeeze()
    u, v = tools.wsdir2uv(self.ws, self.wdir)
    # Subsample the data for clarity
    skip = barb_kwargs.pop("skip", 15)
    self.ax.barbs(
        lon[::skip, ::skip],
        lat[::skip, ::skip],
        u[::skip, ::skip],
        v[::skip, ::skip],
        **barb_kwargs,
    )
    return self.ax