Wind Barbs Example#

Download this notebook from GitHub (right-click to download).


import numpy as np
import geoviews as gv

gv.extension('bokeh')

Define data#

IMPORTANT:

Unlike the VectorField direction, which follows the mathematical convention:

Reference: 0° = East (positive x-axis) Direction: Counterclockwise Meaning: Direction the vector points to Formula: θ = arctan2(v, u)

        N (90°)
         |
W (180°)-+-E (0°)
         |
        S (270°)

The WindBarbs direction follows the meteorological convention:

Reference: 0° = North Direction: Clockwise Meaning: Direction the wind is coming from Formula: θ = 90° - arctan2(-v, -u)

        N (0°/360°)
         |
W (270°)-+-E (90°)
         |
        S (180°)

For convenience, from_uv can be used to create a WindBarbs directly from U/V components to use the meteorological conventions.

lat = np.arange(60, 37.5, -2.5)
lon = np.arange(270, 292.5, 2.5)
uwnd = np.array(
    [
        [2, 0, -2, -2, -3, -3, -3, -2, -1],
        [2, 0, -2, -2, -2, -2, -2, -1, 1],
        [2, -1, -2, -2, -2, -1, 0, 1, 3],
        [3, 0, -3, -5, -5, -4, -4, -2, 0],
        [8, 4, 0, -3, -5, -6, -6, -6, -5],
        [12, 10, 8, 5, 3, 0, -2, -2, -2],
        [13, 14, 16, 16, 14, 12, 10, 9, 10],
        [13, 18, 22, 24, 25, 24, 23, 22, 23],
        [20, 25, 29, 32, 33, 32, 32, 33, 34],
    ]
)
vwwnd = np.array(
    [
        [3, 1, 0, -1, -1, 0, 1, 3, 4],
        [-2, -3, -3, -2, 0, 2, 4, 6, 8],
        [-6, -6, -4, -1, 2, 5, 7, 10, 12],
        [-12, -10, -6, -1, 4, 7, 10, 12, 14],
        [-17, -15, -10, -4, 2, 6, 9, 12, 16],
        [-20, -18, -14, -8, -2, 2, 5, 10, 16],
        [-17, -16, -13, -9, -6, -3, 1, 7, 15],
        [-11, -10, -8, -6, -6, -5, -2, 6, 15],
        [-5, -3, -2, -2, -4, -5, -2, 6, 15],
    ]
)

# equivalent to metpy.calc.wind_direction(uwnd, vwwnd).to("radian")
wdir = np.pi / 2 - np.arctan2(-vwwnd, -uwnd)
wspd = np.sqrt(uwnd**2 + vwwnd**2)

wind_barbs = gv.WindBarbs((lon, lat, wdir, wspd)).opts(
    width=500, height=500, padding=0.5, title="Wind Barbs from direction/speed"
)
wind_barbs_from_uv = gv.WindBarbs.from_uv((lon, lat, uwnd, vwwnd)).opts(
    width=500, height=500, padding=0.5, title="Wind Barbs from U/V components"
)
coastline = gv.feature.coastline()

Plot#

wind_barbs * coastline + wind_barbs_from_uv * coastline

Alternatively, WindBarbs can be adapted to oceanography convention:

  • Takes the direction the fluid is moving

  • But uses North = 0° and clockwise (like meteorology)

  • It’s 180° opposite from meteorological convention

wind_barbs_ocean = gv.WindBarbs((lon, lat, wdir, wspd)).opts(
    width=500, height=500, padding=0.5, title="Wind Barbs from direction/speed", convention="to"
)
wind_barbs_from_uv_ocean = gv.WindBarbs.from_uv((lon, lat, uwnd, vwwnd)).opts(
    width=500, height=500, padding=0.5, title="Wind Barbs from U/V components", convention="to"
)
wind_barbs_from_uv_ocean * coastline + wind_barbs_ocean * coastline
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).