Skip to content

Commit 0458a5f

Browse files
committed
Correct and add docstrings, comments and headers
1 parent 349d69f commit 0458a5f

File tree

6 files changed

+217
-183
lines changed

6 files changed

+217
-183
lines changed

windpowerlib/power_curves.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
2-
The ``power_curves`` module contains functions for applying alterations to the
3-
power curve of a wind turbine, wind farm or wind turbine cluster.
2+
The ``power_curves`` module contains functions for applying alterations like
3+
power curve smoohting or reducing power values by an efficiency to the power
4+
curve of a wind turbine, wind farm or wind turbine cluster.
45
56
"""
67

@@ -21,22 +22,23 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values,
2122
2223
Parameters
2324
----------
24-
power_curve_wind_speeds : pandas.Series
25+
power_curve_wind_speeds : pandas.Series or numpy.array
2526
Wind speeds in m/s for which the power curve values are provided in
2627
`power_curve_values`.
2728
power_curve_values : pandas.Series or numpy.array
2829
Power curve values corresponding to wind speeds in
2930
`power_curve_wind_speeds`.
3031
block_width : float
31-
Width of the moving block. Default: 0.5.
32+
Width between the wind speeds in the sum of the equation shown below in
33+
Notes. Default: 0.5.
3234
wind_speed_range : float
3335
The sum in the equation below is taken for this wind speed range below
3436
and above the power curve wind speed. Default: 15.0.
3537
standard_deviation_method : string
3638
Method for calculating the standard deviation for the Gauss
3739
distribution. Options: 'turbulence_intensity', 'Staffell_Pfenninger'.
3840
Default: 'turbulence_intensity'.
39-
mean_gauss : float or integer
41+
mean_gauss : float
4042
Mean of the Gaus distribution in
4143
:py:func:`~.tools.gauss_distribution`:. Default: 0.
4244
@@ -49,9 +51,8 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values,
4951
Returns
5052
-------
5153
smoothed_power_curve_df : pd.DataFrame
52-
Smoothed power curve. DataFrame has 'wind_speed' and
53-
'power' columns with wind speeds in m/s and the corresponding power
54-
curve value in W.
54+
Smoothed power curve. DataFrame has 'wind_speed' and 'power' columns
55+
with wind speeds in m/s and the corresponding power curve value in W.
5556
5657
Notes
5758
-----
@@ -60,17 +61,19 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values,
6061
P_{smoothed}(v_{std}) = \sum\limits_{v_i}^{} \Delta v_i \cdot P(v_i)
6162
\cdot \frac{1}{\sigma \sqrt{2 \pi}}
6263
\exp \left[-\frac{(v_{std} - v_i -\mu)^2}{2 \sigma^2} \right]
63-
64+
6465
with:
6566
P: power [W], v: wind speed [m/s],
66-
:math:`\sigma`: standard deviation (Gauss), :math: `\mu`: mean (Gauss),
67-
67+
:math:`\sigma`: standard deviation (Gauss), :math: `\mu`: mean (Gauss)
68+
6869
:math:`P_{smoothed}` is the smoothed power curve value,
6970
:math:`v_{std}` is the standard wind speed in the power curve,
7071
:math: `\Delta v_i` is the interval length between
7172
:math: `$v_\text{i}$` and :math: `$v_\text{i+1}$`
72-
73-
This way of smoothing power curves is also used in [2]_ and [3]_.
73+
74+
Power curve smoothing is applied to take account for the spatial
75+
distribution of wind speed. This way of smoothing power curves is also used
76+
in [2]_ and [3]_.
7477
7578
References
7679
----------
@@ -99,7 +102,7 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values,
99102
normalized_standard_deviation = 0.2
100103
# Initialize list for power curve values
101104
smoothed_power_curve_values = []
102-
# Append wind speeds to `power_curve_wind_speeds` until last value + range
105+
# Append wind speeds to `power_curve_wind_speeds`
103106
maximum_value = power_curve_wind_speeds.values[-1] + wind_speed_range
104107
while (power_curve_wind_speeds.values[-1] < maximum_value):
105108
power_curve_wind_speeds = power_curve_wind_speeds.append(
@@ -108,11 +111,10 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values,
108111
power_curve_values = power_curve_values.append(
109112
pd.Series(0.0, index=[power_curve_values.index[-1] + 1]))
110113
for power_curve_wind_speed in power_curve_wind_speeds:
111-
# Create array of wind speeds for the moving block
112-
wind_speeds_block = (np.arange(-wind_speed_range,
113-
wind_speed_range + block_width,
114-
block_width) +
115-
power_curve_wind_speed)
114+
# Create array of wind speeds for the sum
115+
wind_speeds_block = (np.arange(
116+
-wind_speed_range, wind_speed_range + block_width, block_width) +
117+
power_curve_wind_speed)
116118
# Get standard deviation for Gauss function
117119
standard_deviation = (
118120
(power_curve_wind_speed * normalized_standard_deviation + 0.6)
@@ -126,15 +128,14 @@ def smooth_power_curve(power_curve_wind_speeds, power_curve_values,
126128
power_curve_wind_speed - wind_speed,
127129
standard_deviation, mean_gauss)
128130
for wind_speed in wind_speeds_block)
129-
# Add value to list - add 0 if `smoothed_value` is nan. This occurs
130-
# because the Gauss distribution is not defined for 0.
131+
# Add value to list - add 0 if `smoothed_value` is nan.
131132
smoothed_power_curve_values.append(0 if np.isnan(smoothed_value)
132133
else smoothed_value)
133-
# Create smoothed power curve DataFrame
134+
# Create smoothed power curve data frame
134135
smoothed_power_curve_df = pd.DataFrame(
135136
data=[list(power_curve_wind_speeds.values),
136137
smoothed_power_curve_values]).transpose()
137-
# Rename columns of DataFrame
138+
# Rename columns of the data frame
138139
smoothed_power_curve_df.columns = ['wind_speed', 'power']
139140
return smoothed_power_curve_df
140141

@@ -147,7 +148,7 @@ def wake_losses_to_power_curve(power_curve_wind_speeds, power_curve_values,
147148
148149
Parameters
149150
----------
150-
power_curve_wind_speeds : pandas.Series
151+
power_curve_wind_speeds : pandas.Series or numpy.array
151152
Wind speeds in m/s for which the power curve values are provided in
152153
`power_curve_values`.
153154
power_curve_values : pandas.Series or numpy.array
@@ -157,10 +158,9 @@ def wake_losses_to_power_curve(power_curve_wind_speeds, power_curve_values,
157158
Efficiency of the wind farm. Either constant (float) or efficiency
158159
curve (pd.DataFrame) containing 'wind_speed' and 'efficiency' columns
159160
with wind speeds in m/s and the corresponding dimensionless wind farm
160-
efficiency (reduction of power).
161-
Default: None.
161+
efficiency (reduction of power). Default: None.
162162
wake_losses_model : String
163-
Defines the method for talking wake losses within the farm into
163+
Defines the method for taking wake losses within the farm into
164164
consideration. Options: 'power_efficiency_curve',
165165
'constant_efficiency'. Default: 'power_efficiency_curve'.
166166
@@ -193,8 +193,8 @@ def wake_losses_to_power_curve(power_curve_wind_speeds, power_curve_values,
193193
wake_losses_model, wind_farm_efficiency))
194194
df = pd.concat([power_curve_df.set_index('wind_speed'),
195195
wind_farm_efficiency.set_index('wind_speed')], axis=1)
196-
# Add by efficiency reduced power column (nan values of efficiency
197-
# are interpolated)
196+
# Add column with reduced power (nan values of efficiency are
197+
# interpolated)
198198
df['reduced_power'] = df['power'] * df['efficiency'].interpolate(
199199
method='index')
200200
reduced_power = df['reduced_power'].dropna()

windpowerlib/tools.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def linear_interpolation_extrapolation(df, target_height):
4343
4444
For the inter- and extrapolation the following equation is used:
4545
46-
.. math:: f(x) = \frac{(f(x_2) - f(x_1))}{(x_2 - x_1)} \cdot (x - x_1) + f(x_1)
46+
.. math:: f(x) = \frac{(f(x_2) - f(x_1))}{(x_2 - x_1)} \cdot
47+
(x - x_1) + f(x_1)
4748
4849
Examples
4950
---------
@@ -106,7 +107,8 @@ def logarithmic_interpolation_extrapolation(df, target_height):
106107
For the logarithmic inter- and extrapolation the following equation is
107108
used [1]_:
108109
109-
.. math:: f(x) = \frac{\ln(x) \cdot (f(x_2) - f(x_1)) - f(x_2) \cdot \ln(x_1) + f(x_1) \cdot \ln(x_2)}{\ln(x_2) - \ln(x_1)}
110+
.. math:: f(x) = \frac{\ln(x) \cdot (f(x_2) - f(x_1)) - f(x_2) \cdot
111+
\ln(x_1) + f(x_1) \cdot \ln(x_2)}{\ln(x_2) - \ln(x_1)}
110112
111113
References
112114
----------
@@ -131,6 +133,9 @@ def gauss_distribution(function_variable, standard_deviation, mean=0):
131133
r"""
132134
Gauss distribution.
133135
136+
The Gauss distribution is used in the function
137+
:py:func:`~.power_curves.smooth_power_curve`: for power curve smoothing.
138+
134139
Parameters
135140
----------
136141
function_variable : float
@@ -143,7 +148,8 @@ def gauss_distribution(function_variable, standard_deviation, mean=0):
143148
Returns
144149
-------
145150
pandas.Series or numpy.array
146-
Wind speed at hub height. Data type depends on type of `wind_speed`.
151+
Wind speed at hub height. Data type depends on the type of
152+
`wind_speed`.
147153
148154
Notes
149155
-----
@@ -160,8 +166,6 @@ def gauss_distribution(function_variable, standard_deviation, mean=0):
160166
.. [1] Berendsen, H.: "A Student's Guide to Data and Error Analysis".
161167
New York, Cambridge University Press, 2011, p. 37
162168
163-
# TODO: add references
164-
165169
"""
166170
return (1 / (standard_deviation * np.sqrt(2 * np.pi)) *
167171
np.exp(-(function_variable - mean)**2 /
@@ -170,11 +174,11 @@ def gauss_distribution(function_variable, standard_deviation, mean=0):
170174

171175
def estimate_turbulence_intensity(height, roughness_length):
172176
"""
173-
Calculate turbulence intensity.
177+
Estimate turbulence intensity by the roughness length.
174178
175179
Parameters
176180
----------
177-
height : Float
181+
height : float
178182
Height above ground in m at which the turbulence intensity is
179183
calculated.
180184
roughness_length : pandas.Series or numpy.array or float
@@ -184,7 +188,7 @@ def estimate_turbulence_intensity(height, roughness_length):
184188
-----
185189
The following equation is used [1]_:
186190
187-
.. math:: TI = \frac{1}{ln \left(\frac{h}{z_\text{0}} \right)}
191+
.. math:: TI \approx \frac{1}{ln \left(\frac{h}{z_\text{0}} \right)}
188192
189193
with:
190194
TI: turbulence intensity, h: height, :math:`z_{0}`: roughness length

windpowerlib/turbine_cluster_modelchain.py

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ class TurbineClusterModelChain(ModelChain):
1717
1818
Parameters
1919
----------
20-
wind_object : WindFarm or WindTurbineCluster
20+
power_plant : WindFarm or WindTurbineCluster
2121
A :class:`~.wind_farm.WindFarm` object representing the wind farm or
2222
a :class:`~.wind_turbine_cluster.WindTurbineCluster` object
2323
representing the wind turbine cluster.
24-
wake_losses_model : String
24+
wake_losses_model : string
2525
Defines the method for talking wake losses within the farm into
26-
consideration. Options: 'power_efficiency_curve',
27-
'constant_efficiency', 'dena_mean', 'knorr_mean', 'dena_extreme1',
28-
'dena_extreme2', 'knorr_extreme1', 'knorr_extreme2', 'knorr_extreme3'
29-
or None. Default: 'dena_mean'.
30-
smoothing : Boolean
31-
If True the power curves will be smoothed before the summation.
26+
consideration. Options: None, 'power_efficiency_curve' or
27+
'constant_efficiency' or the name of a wind efficiency curve like
28+
'dena_mean'. Default: 'dena_mean'.
29+
Use :py:func:`~.wake_losses.display_wind_efficiency_curves`: to see a
30+
list of all provided wind efficiency curves.
31+
smoothing : boolean
32+
If True the power curves will be smoothed before or after the
33+
aggregation of power curves depending on `smoothing_order`.
3234
Default: False.
33-
block_width : Float, optional
34-
Width of the moving block.
35-
Default in :py:func:`~.power_curves.smooth_power_curve`: 0.5.
36-
standard_deviation_method : String, optional
37-
Method for calculating the standard deviation for the gaussian
38-
distribution. Options: 'turbulence_intensity', 'Norgaard',
39-
'Staffell_Pfenninger'.
40-
Default in :py:func:`~.power_curves.smooth_power_curve`:
41-
'turbulence_intensity'.
42-
smoothing_order : String
35+
block_width : float
36+
Width between the wind speeds in the sum of the equation in
37+
:py:func:`~.power_curves.smooth_power_curve`:. Default: 0.5.
38+
standard_deviation_method : string
39+
Method for calculating the standard deviation for the Gauss
40+
distribution. Options: 'turbulence_intensity', 'Staffell_Pfenninger'.
41+
Default: 'turbulence_intensity'.
42+
smoothing_order : string
4343
Defines when the smoothing takes place if `smoothing` is True. Options:
4444
'turbine_power_curves' (to the single turbine power curves),
4545
'wind_farm_power_curves'. Default: 'wind_farm_power_curves'.
@@ -79,30 +79,32 @@ class TurbineClusterModelChain(ModelChain):
7979
A :class:`~.wind_farm.WindFarm` object representing the wind farm or
8080
a :class:`~.wind_turbine_cluster.WindTurbineCluster` object
8181
representing the wind turbine cluster.
82-
wake_losses_model : String
82+
wake_losses_model : string
8383
Defines the method for talking wake losses within the farm into
84-
consideration. Options: 'power_efficiency_curve',
85-
'constant_efficiency', 'dena_mean', 'knorr_mean', 'dena_extreme1',
86-
'dena_extreme2', 'knorr_extreme1', 'knorr_extreme2', 'knorr_extreme3'
87-
or None. Default: 'dena_mean'.
88-
smoothing : Boolean
89-
If True the power curves will be smoothed before the summation.
84+
consideration. Options: None, 'power_efficiency_curve' or
85+
'constant_efficiency' or the name of a wind efficiency curve like
86+
'dena_mean'. Default: 'dena_mean'.
87+
Use :py:func:`~.wake_losses.display_wind_efficiency_curves`: to see a
88+
list of all provided wind efficiency curves.
89+
smoothing : boolean
90+
If True the power curves will be smoothed before or after the
91+
aggregation of power curves depending on `smoothing_order`.
9092
Default: False.
91-
block_width : Float, optional
92-
Width of the moving block.
93-
Default in :py:func:`~.power_curves.smooth_power_curve`: 0.5.
94-
standard_deviation_method : String, optional
95-
Method for calculating the standard deviation for the gaussian
96-
distribution. Options: 'turbulence_intensity', 'Norgaard',
97-
'Staffell_Pfenninger'.
98-
Default in :py:func:`~.power_curves.smooth_power_curve`:
99-
'turbulence_intensity'.
100-
power_output : pandas.Series
101-
Electrical power output of the wind turbine in W.
102-
smoothing_order : String
93+
block_width : float
94+
Width between the wind speeds in the sum of the equation in
95+
:py:func:`~.power_curves.smooth_power_curve`:. Default: 0.5.
96+
standard_deviation_method : string
97+
Method for calculating the standard deviation for the Gauss
98+
distribution. Options: 'turbulence_intensity', 'Staffell_Pfenninger'.
99+
Default: 'turbulence_intensity'.
100+
smoothing_order : string
103101
Defines when the smoothing takes place if `smoothing` is True. Options:
104102
'turbine_power_curves' (to the single turbine power curves),
105103
'wind_farm_power_curves'. Default: 'wind_farm_power_curves'.
104+
power_output : pandas.Series
105+
Electrical power output of the wind turbine in W.
106+
pandas.DataFrame or None
107+
The calculated power curve of the wind farm.
106108
wind_speed_model : string
107109
Parameter to define which model to use to calculate the wind speed
108110
at hub height. Valid options are 'logarithmic', 'hellman' and

0 commit comments

Comments
 (0)