Skip to content

Commit 3b8deae

Browse files
authored
Merge pull request #107 from kumar10725/kumar10725-patch-1
Speed Improvement in "power_curve_density_correction"
2 parents 1273dea + 7c49763 commit 3b8deae

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

windpowerlib/power_output.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,8 @@ def power_curve_density_correction(
176176
):
177177
r"""
178178
Calculates the turbine power output using a density corrected power curve.
179-
180179
This function is carried out when the parameter `density_correction` of an
181180
instance of the :class:`~.modelchain.ModelChain` class is True.
182-
183181
Parameters
184182
----------
185183
wind_speed : :pandas:`pandas.Series<series>` or numpy.array
@@ -192,41 +190,33 @@ def power_curve_density_correction(
192190
`power_curve_wind_speeds`.
193191
density : :pandas:`pandas.Series<series>` or numpy.array
194192
Density of air at hub height in kg/m³.
195-
196193
Returns
197194
-------
198195
:pandas:`pandas.Series<series>` or numpy.array
199196
Electrical power output of the wind turbine in W.
200197
Data type depends on type of `wind_speed`.
201-
202198
Notes
203199
-----
204200
The following equation is used for the site specific power curve wind
205201
speeds [1]_ [2]_ [3]_:
206-
207202
.. math:: v_{site}=v_{std}\cdot\left(\frac{\rho_0}
208203
{\rho_{site}}\right)^{p(v)}
209-
210204
with:
211205
.. math:: p=\begin{cases}
212206
\frac{1}{3} & v_{std} \leq 7.5\text{ m/s}\\
213207
\frac{1}{15}\cdot v_{std}-\frac{1}{6} & 7.5
214208
\text{ m/s}<v_{std}<12.5\text{ m/s}\\
215209
\frac{2}{3} & \geq 12.5 \text{ m/s}
216210
\end{cases},
217-
218211
v: wind speed [m/s], :math:`\rho`: density [kg/m³]
219-
220212
:math:`v_{std}` is the standard wind speed in the power curve
221213
(:math:`v_{std}`, :math:`P_{std}`),
222214
:math:`v_{site}` is the density corrected wind speed for the power curve
223215
(:math:`v_{site}`, :math:`P_{std}`),
224216
:math:`\rho_0` is the ambient density (1.225 kg/m³)
225217
and :math:`\rho_{site}` the density at site conditions (and hub height).
226-
227218
It is assumed that the power output for wind speeds above the maximum
228219
and below the minimum wind speed given in the power curve is zero.
229-
230220
References
231221
----------
232222
.. [1] Svenningsen, L.: "Power Curve Air Density Correction And Other
@@ -238,14 +228,25 @@ def power_curve_density_correction(
238228
Variable Scale Simulation Model for Windpower based on the
239229
Georeferenced Installation Register of Germany". Master's Thesis
240230
at Reiner Lemoine Institute, 2014, p. 13
241-
242231
"""
243232
if density is None:
244233
raise TypeError(
245234
"`density` is None. For the calculation with a "
246235
+ "density corrected power curve density at hub "
247236
+ "height is needed."
248237
)
238+
239+
# Convert pandas.Series to a numpy array to speed up the interpolation below.
240+
if isinstance(wind_speed, pd.Series):
241+
# save the indexes for later conversion to pd.Series
242+
wind_speed_indexes = wind_speed.index
243+
# change the wind speed Series to numpy array
244+
wind_speed = wind_speed.values
245+
# Set the panda series flag True
246+
panda_series = True
247+
else:
248+
panda_series = False
249+
249250
power_output = [
250251
(
251252
np.interp(
@@ -266,10 +267,12 @@ def power_curve_density_correction(
266267
]
267268

268269
# Power_output as pd.Series if wind_speed is pd.Series (else: np.array)
269-
if isinstance(wind_speed, pd.Series):
270+
if (
271+
panda_series
272+
): # use the flag to check if the data should be converted back to pandas.Series
270273
power_output = pd.Series(
271274
data=power_output,
272-
index=wind_speed.index,
275+
index=wind_speed_indexes, # Use previously saved wind speed indexes
273276
name="feedin_power_plant",
274277
)
275278
else:

0 commit comments

Comments
 (0)