Skip to content

Commit 38bdfd2

Browse files
author
kyri-petrou
committed
Use pure numpy in power output calculation
1 parent 1190788 commit 38bdfd2

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

windpowerlib/power_output.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,42 @@ def power_curve_density_correction(
247247
else:
248248
panda_series = False
249249

250-
power_output = [
251-
(
250+
power_output = _get_power_output(wind_speed, power_curve_wind_speeds.to_numpy(), density.to_numpy(), power_curve_values.to_numpy())
251+
252+
# Convert results to the data type of the input data
253+
if panda_series:
254+
power_output = pd.Series(
255+
data=power_output,
256+
index=wind_speed_indexes, # Use previously saved wind speed index
257+
name="feedin_power_plant",
258+
)
259+
260+
return power_output
261+
262+
263+
def _get_power_output(wind_speed, power_curve_wind_speeds, density, power_curve_values):
264+
""" Get the power output at each timestep using only numpy to speed up performance
265+
Parameters
266+
----------
267+
wind_speed : :pandas:`pandas.Series<series>` or numpy.array
268+
Wind speed at hub height in m/s.
269+
power_curve_wind_speeds : :pandas:`pandas.Series<series>` or numpy.array
270+
Wind speeds in m/s for which the power curve values are provided in
271+
`power_curve_values`.
272+
power_curve_values : :pandas:`pandas.Series<series>` or numpy.array
273+
Power curve values corresponding to wind speeds in
274+
`power_curve_wind_speeds`.
275+
density : :pandas:`pandas.Series<series>` or numpy.array
276+
Density of air at hub height in kg/m³.
277+
Returns
278+
-------
279+
:numpy: `numpy.array`
280+
Electrical power output of the wind turbine in W.
281+
"""
282+
283+
power_output = np.empty(len(wind_speed), dtype=np.float)
284+
for i in range(len(wind_speed)):
285+
power_output[i] = (
252286
np.interp(
253287
wind_speed[i],
254288
power_curve_wind_speeds
@@ -263,16 +297,4 @@ def power_curve_density_correction(
263297
right=0,
264298
)
265299
)
266-
for i in range(len(wind_speed))
267-
]
268-
269-
# Convert results to the data type of the input data
270-
if panda_series:
271-
power_output = pd.Series(
272-
data=power_output,
273-
index=wind_speed_indexes, # Use previously saved wind speed index
274-
name="feedin_power_plant",
275-
)
276-
else:
277-
power_output = np.array(power_output)
278300
return power_output

0 commit comments

Comments
 (0)