Skip to content

Commit

Permalink
Merge pull request #114 from kyri-petrou/feature/vectorize-power-output
Browse files Browse the repository at this point in the history
Vectorize _get_power_output calculations
  • Loading branch information
uvchik committed Mar 9, 2021
2 parents ba0fb3d + 2653387 commit 2d1f437
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions windpowerlib/power_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,22 @@ def _get_power_output(
:numpy:`numpy.array`
Electrical power output of the wind turbine in W.
"""
power_output = np.empty(len(wind_speed), dtype=np.float)
# 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

for i in range(len(wind_speed)):
power_output[i] = np.interp(
wind_speed[i],
power_curve_wind_speeds
* (1.225 / density[i])
** (
np.interp(power_curve_wind_speeds, [7.5, 12.5], [1 / 3, 2 / 3])
),
power_curve_values,
left=0,
right=0,
# 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

0 comments on commit 2d1f437

Please sign in to comment.