Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 15 additions & 36 deletions docs/gallery_code/meteorology/plot_wind_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,71 +11,50 @@

"""

import cartopy.crs as ccrs
import cartopy.feature as cfeat
import matplotlib.pyplot as plt
import numpy as np

import iris
import iris.coord_categorisation
import iris.plot as iplt
import iris.quickplot as qplt


def main():
# Load the u and v components of wind from a pp file
# Load the u and v components of wind from a pp file.
infile = iris.sample_data_path("wind_speed_lake_victoria.pp")

uwind = iris.load_cube(infile, "x_wind")
vwind = iris.load_cube(infile, "y_wind")

ulon = uwind.coord("longitude")
vlon = vwind.coord("longitude")

# The longitude points go from 180 to 540, so subtract 360 from them
ulon.points = ulon.points - 360.0
vlon.points = vlon.points - 360.0

# Create a cube containing the wind speed
# Create a cube containing the wind speed.
windspeed = (uwind ** 2 + vwind ** 2) ** 0.5
windspeed.rename("windspeed")

x = ulon.points
y = uwind.coord("latitude").points
u = uwind.data
v = vwind.data
# Plot the wind speed as a contour plot.
qplt.contourf(windspeed, 20)

# Set up axes to show the lake
# Show the lake on the current axes.
lakes = cfeat.NaturalEarthFeature(
"physical", "lakes", "50m", facecolor="none"
)
plt.gca().add_feature(lakes)

plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(lakes)

# Get the coordinate reference system used by the data
transform = ulon.coord_system.as_cartopy_projection()

# Plot the wind speed as a contour plot
qplt.contourf(windspeed, 20)

# Add arrows to show the wind vectors
plt.quiver(x, y, u, v, pivot="middle", transform=transform)
# Add arrows to show the wind vectors.
iplt.quiver(uwind, vwind, pivot="middle")

plt.title("Wind speed over Lake Victoria")
qplt.show()

# Normalise the data for uniform arrow size
u_norm = u / np.sqrt(u ** 2.0 + v ** 2.0)
v_norm = v / np.sqrt(u ** 2.0 + v ** 2.0)
# Normalise the data for uniform arrow size.
u_norm = uwind / windspeed
v_norm = vwind / windspeed

# Make a new figure for the normalised plot.
plt.figure()
ax = plt.axes(projection=ccrs.PlateCarree())
ax.add_feature(lakes)

qplt.contourf(windspeed, 20)

plt.quiver(x, y, u_norm, v_norm, pivot="middle", transform=transform)
plt.gca().add_feature(lakes)
iplt.quiver(u_norm, v_norm, pivot="middle")

plt.title("Wind speed over Lake Victoria")
qplt.show()
Expand Down
3 changes: 3 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ This document explains the changes made to Iris for this release
📚 Documentation
================

#. `@rcomer`_ updated the "Plotting Wind Direction Using Quiver" Gallery
example. (:pull:`4120`)

#. `@trexfeathers`_ included `Iris GitHub Discussions`_ in
:ref:`get involved <development_where_to_start>`. (:pull:`4307`)

Expand Down