import numpy as np
import pandas as pd
import geopandas as gpd
import xarray as xr
from matplotlib import pyplot as plt
import datashader as ds
import imageio
Wind Data Visualization
Wind Data Source: ERA5 climate data from Climate Data Store
The wind data in this project comes from the ‘ERA5 monthly averaged data on single levels from 1940 to present’ dataset, specifically the 10m u-component of wind and 10m v-component of wind.
The time period will be 2022 yearly data, and the area of interest will be Lake Erie.
Even though during downloading process, it says the data is in a 10 meters resolution, the actual resolution of the .nc file is much larger than that.
Step 1: Read the .nc file downloaded from the ERA5 website and calculate wind strength
Read .nc file downloaded from Climate Data Store
= xr.open_dataset('./data/ERA5climate4.nc') windnc
Extract latitude and longitude data of each point
= windnc.latitude
lat = windnc.longitude lon
Extract wind uv data
= windnc.u10
wind_u = windnc.v10 wind_v
Calculate wind strength (m/s) based on wind uv data
= np.sqrt(wind_u**2 + wind_v**2) WS
Step 2: plot wind field map for each month in 2022 and generate a gif
Read the Lake Erie shapefile extracted from USGS National Hydrography Dataset and change it to the same projection as wind data (CRS 4326)
= gpd.read_file("./data/LakeErie") lake
= lake.to_crs(epsg=4326) lake4326
Define a function to collect the plot for each month
The plot contains three components: the wind field map (array array), the wind strength map (color), and Lake Erie location (shape).
The wind field map is generated through vector calculation.
The wind strength map is generated through each point’s relationship to its neighbors.
# Have a list of month names for the function to use
= ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] monthlist
def plot_wind_by_month(month):
"""Plot wind field map for each month in 2022"""
= plt.subplots(figsize=(10,6))
fig, ax
# Wind strength map
= plt.contourf(lon,lat,WS[month,:,:], levels=15, cmap='rainbow', alpha=0.8)
cf
# lake Erie shape
=plt.gca(), edgecolor='#25408F', facecolor='none', linewidth=0.5)
lake4326.plot(ax
# Wind field map with labels
= plt.quiver(lon,lat,wind_u[month,:,:],wind_v[month,:,:], scale_units='xy', scale=4, width=0.0014, color='white')
Q = plt.quiverkey(Q,
qk 1, 1.02,
1,str(1)+' m/s',
='E',
labelpos='axes',
coordinates='black'
color
)
# style adjustments
= plt.colorbar(cf, fraction=0.0235, pad=0.03)
cb 'm/s', fontsize=11)
cb.set_label('Longitude')
plt.xlabel('Latitude')
plt.ylabel(f'Wind Field Map of {monthlist[month]}')
plt.title(
# prepare for imageio
fig.canvas.draw()= np.frombuffer(fig.canvas.tostring_rgb(), dtype="uint8")
image = image.reshape(fig.canvas.get_width_height()[::-1] + (3,))
image
return image
Use the function above to see the wind strenghth for each month and generate a gif for the wind visualization
= []
imgs for month in range(12):
= plot_wind_by_month(month)
img
imgs.append(img)
# Combing the images for each month into a single GIF
"wind-field.gif", imgs, duration=1000) imageio.mimsave(
The gif generated above does not have infinite loop, so Onlinegiftools can help change that property
The final visualization is below:
Step 3: Analyze the result
Result:
The gif works smoothly and clearly displays the wind change within 2022. The prevailing wind for Lake Erie is southwest, which is because of the typical seiche pattern. Because all the vectors of the wind field map are on the same scale, we can see that Lake Erie has severely larger wind in the winter.
Event:
The dominant southwest wind usually causes much damage to residents near the coastline in winter. Historic winter storms dumped 50 inches of snow per year in the region. In December 2022, blizzards and seiche killed 50 people, including 27 in Buffalo, and created a catastrophic blanket of ice across the city.
Compare:
The gif result can reflect the event above. In November and December, the wind field arrays are much longer than the arrays in other months.