-
Notifications
You must be signed in to change notification settings - Fork 100
/
power_output.py
315 lines (276 loc) · 11 KB
/
power_output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
"""
The ``power_output`` module contains functions to calculate the power output
of a wind turbine.
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""
import numpy as np
import pandas as pd
def power_coefficient_curve(
wind_speed,
power_coefficient_curve_wind_speeds,
power_coefficient_curve_values,
rotor_diameter,
density,
):
r"""
Calculates the turbine power output using a power coefficient curve.
This function is carried out when the parameter `power_output_model` of an
instance of the :class:`~.modelchain.ModelChain` class is
'power_coefficient_curve'.
Parameters
----------
wind_speed : :pandas:`pandas.Series<series>` or numpy.array
Wind speed at hub height in m/s.
power_coefficient_curve_wind_speeds : :pandas:`pandas.Series<series>` or numpy.array
Wind speeds in m/s for which the power coefficients are provided in
`power_coefficient_curve_values`.
power_coefficient_curve_values : :pandas:`pandas.Series<series>` or numpy.array
Power coefficients corresponding to wind speeds in
`power_coefficient_curve_wind_speeds`.
rotor_diameter : float
Rotor diameter in m.
density : :pandas:`pandas.Series<series>` or numpy.array
Density of air at hub height in kg/m³.
Returns
-------
:pandas:`pandas.Series<series>` or numpy.array
Electrical power output of the wind turbine in W.
Data type depends on type of `wind_speed`.
Notes
-----
The following equation is used [1]_ [2]_:
.. math:: P=\frac{1}{8}\cdot\rho_{hub}\cdot d_{rotor}^{2}
\cdot\pi\cdot v_{wind}^{3}\cdot cp\left(v_{wind}\right)
with:
P: power [W], :math:`\rho`: density [kg/m³], d: diameter [m],
v: wind speed [m/s], cp: power coefficient
It is assumed that the power output for wind speeds above the maximum
and below the minimum wind speed given in the power coefficient curve is
zero.
References
----------
.. [1] Gasch, R., Twele, J.: "Windkraftanlagen". 6. Auflage, Wiesbaden,
Vieweg + Teubner, 2010, pages 35ff, 208
.. [2] Hau, E.: "Windkraftanlagen - Grundlagen, Technik, Einsatz,
Wirtschaftlichkeit". 4. Auflage, Springer-Verlag, 2008, p. 542
"""
power_coefficient_time_series = np.interp(
wind_speed,
power_coefficient_curve_wind_speeds,
power_coefficient_curve_values,
left=0,
right=0,
)
power_output = (
1
/ 8
* density
* rotor_diameter ** 2
* np.pi
* np.power(wind_speed, 3)
* power_coefficient_time_series
)
# Power_output as pd.Series if wind_speed is pd.Series (else: np.array)
if isinstance(wind_speed, pd.Series):
power_output = pd.Series(
data=power_output,
index=wind_speed.index,
name="feedin_power_plant",
)
else:
power_output = np.array(power_output)
return power_output
def power_curve(
wind_speed,
power_curve_wind_speeds,
power_curve_values,
density=None,
density_correction=False,
):
r"""
Calculates the turbine power output using a power curve.
This function is carried out when the parameter `power_output_model` of an
instance of the :class:`~.modelchain.ModelChain` class is 'power_curve'. If
the parameter `density_correction` is True the density corrected power
curve (see :py:func:`~.power_curve_density_correction`) is used.
Parameters
----------
wind_speed : :pandas:`pandas.Series<series>` or numpy.array
Wind speed at hub height in m/s.
power_curve_wind_speeds : :pandas:`pandas.Series<series>` or numpy.array
Wind speeds in m/s for which the power curve values are provided in
`power_curve_values`.
power_curve_values : pandas.Series or numpy.array
Power curve values corresponding to wind speeds in
`power_curve_wind_speeds`.
density : :pandas:`pandas.Series<series>` or numpy.array
Density of air at hub height in kg/m³. This parameter is needed
if `density_correction` is True. Default: None.
density_correction : bool
If the parameter is True the density corrected power curve (see
:py:func:`~.power_curve_density_correction`) is used for the
calculation of the turbine power output. In this case `density`
cannot be None. Default: False.
Returns
-------
:pandas:`pandas.Series<series>` or numpy.array
Electrical power output of the wind turbine in W.
Data type depends on type of `wind_speed`.
Notes
-------
It is assumed that the power output for wind speeds above the maximum
and below the minimum wind speed given in the power curve is zero.
"""
if density_correction is False:
power_output = np.interp(
wind_speed,
power_curve_wind_speeds,
power_curve_values,
left=0,
right=0,
)
# Power_output as pd.Series if wind_speed is pd.Series (else: np.array)
if isinstance(wind_speed, pd.Series):
power_output = pd.Series(
data=power_output,
index=wind_speed.index,
name="feedin_power_plant",
)
else:
power_output = np.array(power_output)
elif density_correction is True:
power_output = power_curve_density_correction(
wind_speed, power_curve_wind_speeds, power_curve_values, density
)
else:
raise TypeError(
"'{0}' is an invalid type. ".format(type(density_correction))
+ "`density_correction` must "
+ "be Boolean (True or False)."
)
return power_output
def power_curve_density_correction(
wind_speed, power_curve_wind_speeds, power_curve_values, density
):
r"""
Calculates the turbine power output using a density corrected power curve.
This function is carried out when the parameter `density_correction` of an
instance of the :class:`~.modelchain.ModelChain` class is True.
Parameters
----------
wind_speed : :pandas:`pandas.Series<series>` or numpy.array
Wind speed at hub height in m/s.
power_curve_wind_speeds : :pandas:`pandas.Series<series>` or numpy.array
Wind speeds in m/s for which the power curve values are provided in
`power_curve_values`.
power_curve_values : :pandas:`pandas.Series<series>` or numpy.array
Power curve values corresponding to wind speeds in
`power_curve_wind_speeds`.
density : :pandas:`pandas.Series<series>` or numpy.array
Density of air at hub height in kg/m³.
Returns
-------
:pandas:`pandas.Series<series>` or numpy.array
Electrical power output of the wind turbine in W.
Data type depends on type of `wind_speed`.
Notes
-----
The following equation is used for the site specific power curve wind
speeds [1]_ [2]_ [3]_:
.. math:: v_{site}=v_{std}\cdot\left(\frac{\rho_0}{\rho_{site}}\right)^{p(v)}
with:
.. math:: p=\begin{cases}
\frac{1}{3} & v_{std} \leq 7.5\text{ m/s}\\
\frac{1}{15}\cdot v_{std}-\frac{1}{6} & 7.5
\text{ m/s}<v_{std}<12.5\text{ m/s}\\
\frac{2}{3} & \geq 12.5 \text{ m/s}
\end{cases},
v: wind speed [m/s], :math:`\rho`: density [kg/m³]
:math:`v_{std}` is the standard wind speed in the power curve
(:math:`v_{std}`, :math:`P_{std}`),
:math:`v_{site}` is the density corrected wind speed for the power curve
(:math:`v_{site}`, :math:`P_{std}`),
:math:`\rho_0` is the ambient density (1.225 kg/m³)
and :math:`\rho_{site}` the density at site conditions (and hub height).
It is assumed that the power output for wind speeds above the maximum
and below the minimum wind speed given in the power curve is zero.
References
----------
.. [1] Svenningsen, L.: "Power Curve Air Density Correction And Other
Power Curve Options in WindPRO". 1st edition, Aalborg,
EMD International A/S , 2010, p. 4
.. [2] Svenningsen, L.: "Proposal of an Improved Power Curve Correction".
EMD International A/S , 2010
.. [3] Biank, M.: "Methodology, Implementation and Validation of a
Variable Scale Simulation Model for Windpower based on the
Georeferenced Installation Register of Germany". Master's Thesis
at Reiner Lemoine Institute, 2014, p. 13
"""
if density is None:
raise TypeError(
"`density` is None. For the calculation with a "
+ "density corrected power curve density at hub "
+ "height is needed."
)
# Convert pd.Series to a numpy array to speed up the interpolation below.
if isinstance(wind_speed, pd.Series):
# save the indexes for later conversion to pd.Series
wind_speed_indexes = wind_speed.index
# change the wind speed Series to numpy array
wind_speed = wind_speed.values
# Set the panda series flag True
panda_series = True
else:
panda_series = False
power_output = _get_power_output(
wind_speed,
np.array(power_curve_wind_speeds),
np.array(density),
np.array(power_curve_values),
)
# Convert results to the data type of the input data
if panda_series:
power_output = pd.Series(
data=power_output,
index=wind_speed_indexes, # Use previously saved wind speed index
name="feedin_power_plant",
)
return power_output
def _get_power_output(
wind_speed, power_curve_wind_speeds, density, power_curve_values
):
"""Get the power output at each timestep using only numpy to speed up performance
Parameters
----------
wind_speed : :numpy:`numpy.ndarray`
Wind speed at hub height in m/s.
power_curve_wind_speeds : :numpy:`numpy.ndarray`
Wind speeds in m/s for which the power curve values are provided in
`power_curve_values`.
density : :numpy:`numpy.ndarray`
Density of air at hub height in kg/m³.
power_curve_values : :numpy:`numpy.ndarray`
Power curve values corresponding to wind speeds in
`power_curve_wind_speeds`.
Returns
-------
:numpy:`numpy.array`
Electrical power output of the wind turbine in W.
"""
# Calculate the power curves for each timestep using vectors
# NOTE: power_curves_per_ts.shape = [len(wind_speed), len(density)]
power_curves_per_ts = (
(1.225 / density).reshape(-1, 1)
** np.interp(power_curve_wind_speeds, [7.5, 12.5], [1 / 3, 2 / 3])
) * power_curve_wind_speeds
# Create the interpolation function
def interp_func(w_speed, p_curves):
return np.interp(
w_speed, p_curves, power_curve_values, left=0, right=0
)
# Calculate the power output by mapping the arrays to the interp function
power_output = np.array(
list(map(interp_func, wind_speed, power_curves_per_ts))
)
return power_output