You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This example use randoms values for wind speed and direction(ws and wd variables). In situation, these variables are loaded with reals values (1-D array), from a database or directly from a text file (see the "load" facility from the matplotlib.pylab interface for that).
67
-
68
-
```python
69
-
from windrose import WindroseAxes
70
-
from matplotlib import pyplot as plt
71
-
import matplotlib.cm as cm
72
-
import numpy as np
73
-
74
-
# Create wind speed and direction variables
75
-
76
-
ws = np.random.random(500) *6
77
-
wd = np.random.random(500) *360
78
-
```
79
-
80
-
### A stacked histogram with normed (displayed in percent) results :
After that, you can have a look at the computed values used to plot the windrose with the `ax._info` dictionnary :
132
-
-`ax._info['bins']` : list of bins (limits) used for wind speeds. If not set in the call, bins will be set to 6 parts between wind speed min and max.
133
-
-`ax._info['dir']` : list of directions "bundaries" used to compute the distribution by wind direction sector. This can be set by the nsector parameter (see below).
134
-
-`ax._info['table']` : the resulting table of the computation. It's a 2D histogram, where each line represents a wind speed class, and each column represents a wind direction class.
135
-
136
-
137
-
So, to know the frequency of each wind direction, for all wind speeds, do:
138
-
139
-
```python
140
-
ax.bar(wd, ws, normed=True, nsector=16)
141
-
table = ax._info['table']
142
-
wd_freq = np.sum(table, axis=0)
143
-
```
144
-
145
-
and to have a graphical representation of this result :
In addition of all the standard pyplot parameters, you can pass special parameters to control the windrose production. For the stacked histogram windrose, calling help(ax.bar) will give :
162
-
`bar(self, direction, var, **kwargs)` method of `windrose.WindroseAxes` instance Plot a windrose in bar mode. For each var bins and for each sector, a colored bar will be draw on the axes.
163
-
164
-
165
-
Mandatory:
166
-
-`direction` : 1D array - directions the wind blows from, North centred
167
-
-`var` : 1D array - values of the variable to compute. Typically the wind speeds
168
-
169
-
Optional:
170
-
-`nsector` : integer - number of sectors used to compute the windrose table. If not set, nsectors=16, then each sector will be 360/16=22.5°, and the resulting computed table will be aligned with the cardinals points.
171
-
-`bins` : 1D array or integer- number of bins, or a sequence of bins variable. If not set, bins=6 between min(var) and max(var).
172
-
-`blowto` : bool. If True, the windrose will be pi rotated, to show where the wind blow to (usefull for pollutant rose).
173
-
-`colors` : string or tuple - one string color (`'k'` or `'black'`), in this case all bins will be plotted in this color; a tuple of matplotlib color args (string, float, rgb, etc), different levels will be plotted in different colors in the order specified.
174
-
-`cmap` : a cm Colormap instance from `matplotlib.cm`.
175
-
- if `cmap == None` and `colors == None`, a default Colormap is used.
176
-
-`edgecolor` : string - The string color each edge bar will be plotted.
177
-
Default : no edgecolor
178
-
-`opening` : float - between 0.0 and 1.0, to control the space between each sector (1.0 for no space)
179
-
-`mean_values` : Bool - specify wind speed statistics with direction=specific mean wind speeds. If this flag is specified, var is expected to be an array of mean wind speeds corresponding to each entry in `direction`. These are used to generate a distribution of wind speeds assuming the distribution is Weibull with shape factor = 2.
180
-
-`weibull_factors` : Bool - specify wind speed statistics with direction=specific weibull scale and shape factors. If this flag is specified, var is expected to be of the form [[7,2], ...., [7.5,1.9]] where var[i][0] is the weibull scale factor and var[i][1] is the shape factor
181
-
182
-
### probability density function (pdf) and fitting Weibull distribution
183
-
184
-
A probability density function can be plot using:
185
-
186
-
```python
187
-
from windrose import WindAxes
188
-
ax = WindAxes.from_ax()
189
-
bins = np.arange(0, 6+1, 0.5)
190
-
bins = bins[1:]
191
-
ax, params = ax.pdf(ws, bins=bins)
192
-
```
193
-
194
-

195
-
196
-
Optimal parameters of Weibull distribution can be displayed using
197
-
198
-
```python
199
-
print(params)
200
-
(1, 1.7042156870194352, 0, 7.0907180300605459)
201
-
```
202
-
203
-
204
-
## Functional API
205
-
206
-
Instead of using object oriented approach like previously shown, some "shortcut" functions have been defined: `wrbox`, `wrbar`, `wrcontour`, `wrcontourf`, `wrpdf`.
207
-
See [unit tests](tests/test_windrose.py).
208
-
209
-
## Pandas support
210
-
211
-
windrose not only supports Numpy arrays. It also supports also Pandas DataFrame. `plot_windrose` function provides most of plotting features previously shown.
0 commit comments