Skip to content

Commit 721f141

Browse files
author
kyri-petrou
committed
Vectorize power_output calculation
1 parent 96de09f commit 721f141

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

windpowerlib/power_output.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,24 @@ def _get_power_output(
286286
:numpy:`numpy.array`
287287
Electrical power output of the wind turbine in W.
288288
"""
289-
power_output = np.empty(len(wind_speed), dtype=np.float)
289+
# Create a new empty power curves array which which can be used t
290+
power_curve_exponent = np.interp(
291+
power_curve_wind_speeds, [7.5, 12.5], [1 / 3, 2 / 3]
292+
)
293+
294+
# Calculate the power curves for each timestep using vectors
295+
# NOTE: power_curves_per_ts.shape = [len(wind_speed), len(density)]
296+
power_curves_per_ts = (
297+
(1.225 / density).reshape(-1, 1) ** power_curve_exponent
298+
) * power_curve_wind_speeds
299+
300+
# Create the interpolation function
301+
interp_func = lambda w_speed, p_curves: np.interp(
302+
w_speed, p_curves, power_curve_values, left=0, right=0
303+
)
304+
# Calculate the power output by mapping the arrays to the interp function
305+
power_output = np.array(
306+
list(map(interp_func, wind_speed, power_curves_per_ts))
307+
)
290308

291-
for i in range(len(wind_speed)):
292-
power_output[i] = np.interp(
293-
wind_speed[i],
294-
power_curve_wind_speeds
295-
* (1.225 / density[i])
296-
** (
297-
np.interp(power_curve_wind_speeds, [7.5, 12.5], [1 / 3, 2 / 3])
298-
),
299-
power_curve_values,
300-
left=0,
301-
right=0,
302-
)
303309
return power_output

0 commit comments

Comments
 (0)