Vector data - plotting wind flags¶
This notebook introduces how to plot vector data, such as wind fields, as flags/barbs.
Example: Wind from Storm Ophelia (October 2017)¶
In this example, we will use sample wind data from Storm Ophelia, which impacted the UK in October 2017.
[1]:
import earthkit.data as ekd
import earthkit.plots as ekp
data = ekd.from_source("sample", "storm_ophelia_wind_850.grib").to_fieldlist()
data.ls()
[1]:
| parameter.variable | time.valid_datetime | time.base_datetime | time.step | vertical.level | vertical.level_type | ensemble.member | geography.grid_type | |
|---|---|---|---|---|---|---|---|---|
| 0 | u | 2017-10-16 | 2017-10-16 | 0 days | 850 | pressure | 0 | regular_ll |
| 1 | v | 2017-10-16 | 2017-10-16 | 0 days | 850 | pressure | 0 | regular_ll |
This dataset contains U (zonal wind) and V (meridional wind) components, which earthkit-plots can automatically detect and extract. To plot this data as wind flags, we can use the barbs method:
[2]:
# Create a map of the region around the UK
chart = ekp.Map(domain=[-20, 5, 40, 60])
# Automatically detect U and V fields and plot vectors
chart.barbs(data)
# Add map features
chart.coastlines()
chart.land()
chart.gridlines()
chart.legend()
# Show the plot
chart.show()
Or using the high-level API:
[3]:
ekp.geo.barbs(data, domain=[-20, 5, 40, 60])
[3]:
<earthkit.plots.components.maps.Map at 0x156d74f10>
Alternatively, you can explicitly provide U and V components as u and v arguments. This can be useful when working with datasets that store U and V components separately or which use non-standard metadata.
[4]:
# Create a map of the region around the UK
chart = ekp.Map(domain=[-20, 5, 40, 60])
# Pass U and V components separately
chart.barbs(u=data.sel({"parameter.variable": "u"}), v=data.sel({"parameter.variable": "v"}))
# Add map features
chart.coastlines()
chart.land()
chart.gridlines()
# Show the plot
chart.show()
Next Steps¶
Continue exploring the topics in this section to expand your knowledge of vector plotting, including:
Wind arrows: Learn how to plot vectors using wind arows.
Resampling and Regridding: Discover how to manage vector density for clearer plots.
Applying Styles: Customise vector colours, lengths, and arrow styles.