A wind rose is a graphic tool used by meteorologists to give a succinct view of how wind speed and direction are typically distributed at a particular location. Historically, wind roses were predecessors of the compass rose, as there was no differentiation between a cardinal direction and the wind which blew from such a direction. Using a polar coordinate system of gridding, the frequency of winds over a time period is plotted by wind direction, with color bands showing wind speed ranges. The direction of the longest spoke shows the wind direction with the greatest frequency (https://en.wikipedia.org/wiki/Wind_rose).
This notebook is extracted from the python package of windrose with a little bit modification. Please refer to the original windrose’s documentation for more information.
In [2]:
%matplotlib inline
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
from math import pi
from windrose import WindroseAxes, WindAxes, plot_windrose
from pylab import rcParams
rcParams['figure.figsize'] = 6, 6
In [3]:
df = pd.read_csv("data/sample_wind_poitiers.csv", parse_dates=['Timestamp'])
df = df.set_index('Timestamp')
df.head()
Out[3]:
In [4]:
df.index[0:5]
Out[4]:
In [5]:
df['speed_x'] = df['speed'] * np.sin(df['direction'] * pi / 180.0)
df['speed_y'] = df['speed'] * np.cos(df['direction'] * pi / 180.0)
In [6]:
fig, ax = plt.subplots()
x0, x1 = ax.get_xlim()
y0, y1 = ax.get_ylim()
ax.set_aspect('equal')
_ = df.plot(kind='scatter', x='speed_x', y='speed_y', alpha=0.25, ax=ax)
Vw = 60
_ = ax.set_xlim([-Vw, Vw])
_ = ax.set_ylim([-Vw, Vw])
In [7]:
ax = WindroseAxes.from_ax()
ax.bar(df.direction.values, df.speed.values, normed=True, bins=np.arange(0.01,8,1), cmap=cm.RdYlBu_r, lw=3)
ax.set_legend()
Out[7]:
In [8]:
_ = plot_windrose(df, kind='contour', normed=True, bins=np.arange(0.01,8,1), cmap=cm.RdYlBu_r, lw=3)
In [9]:
bins = np.arange(0,30+1,1)
bins = bins[1:]
bins
Out[9]:
In [10]:
_ = plot_windrose(df, kind='pdf', bins=np.arange(0.01,30,1))
In [11]:
data = np.histogram(df['speed'], bins=bins)[0]
data
Out[11]:
In [12]:
def plot_month(df, t_year_month, *args, **kwargs):
by = 'year_month'
df[by] = df.index.map(lambda x: x.year*100+x.month)
df_month = df[df[by] == t_year_month[0]*100+t_year_month[1]]
ax = plot_windrose(df_month, *args, **kwargs)
return ax
Out[12]:
In [ ]:
plot_month(df, (2014, 7), kind='contour', normed=True,bins=np.arange(0, 10, 1), cmap=cm.RdYlBu_r)
In [13]:
plot_month(df, (2014, 8), kind='contour', normed=True,bins=np.arange(0, 10, 1), cmap=cm.RdYlBu_r)
Out[13]:
In [14]:
plot_month(df, (2014, 9), kind='contour', normed=True, bins=np.arange(0, 10, 1), cmap=cm.RdYlBu_r)
Out[14]:
Dan Reboussin (2005). Wind Rose. University of Florida. Retrieved on 2009-04-26.
John D. Hunter. Matplotlib: A 2D Graphics Environment, Computing in Science & Engineering, 9, 90-95 (2007), DOI:10.1109/MCSE.2007.55
Stéfan van der Walt, S. Chris Colbert and Gaël Varoquaux. The NumPy Array: A Structure for Efficient Numerical Computation, Computing in Science & Engineering, 13, 22-30 (2011), DOI:10.1109/MCSE.2011.37
In [ ]: