Skip to content

Commit 92dc64a

Browse files
committed
Merge branch 'API_changes' into dev
2 parents c2f14f1 + 5f7167f commit 92dc64a

File tree

3 files changed

+50
-42
lines changed

3 files changed

+50
-42
lines changed

windpowerlib/modelchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def v_wind_hub(self, weather, data_height):
260260
v_wind = wind_speed.v_wind_hellman(
261261
weather['v_wind'], data_height['v_wind'],
262262
self.wind_turbine.hub_height,
263-
self.hellman_exp, weather['z0'])
263+
weather['z0'], self.hellman_exp)
264264
else:
265265
raise ValueError("'{0}' is an invalid value.".format(
266266
self.wind_model) + "`wind_model` " +
@@ -313,8 +313,8 @@ def turbine_power_output(self, v_wind, rho_hub):
313313
" are missing.")
314314
if self.density_corr is False:
315315
logging.debug('Calculating power output using power curve.')
316-
output = power_output.p_curve(self.wind_turbine.p_values,
317-
v_wind)
316+
output = power_output.p_curve(v_wind,
317+
self.wind_turbine.p_values)
318318
elif self.density_corr is True:
319319
logging.debug('Calculating power output using density ' +
320320
'corrected power curve.')

windpowerlib/power_output.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def cp_curve(v_wind, rho_hub, d_rotor, cp_values):
3434
3535
Returns
3636
-------
37-
pandas.Series
37+
pandas.Series or numpy.array
3838
Electrical power output of the wind turbine in W.
3939
4040
Notes
@@ -60,17 +60,18 @@ def cp_curve(v_wind, rho_hub, d_rotor, cp_values):
6060
6161
"""
6262
# cp time series
63-
cp_series = np.interp(v_wind, cp_values.index, cp_values.cp,
64-
left=0, right=0)
63+
cp_time_series = np.interp(v_wind, cp_values.index, cp_values.cp,
64+
left=0, right=0)
65+
# Convert rho_hub to np.array if v_wind is np.array
66+
if (isinstance(v_wind, np.ndarray) and isinstance(rho_hub, pd.Series)):
67+
rho_hub = np.array(rho_hub)
6568
power_output = (1 / 8 * rho_hub * d_rotor ** 2 * np.pi
66-
* np.power(v_wind, 3) * cp_series)
67-
# Set index for time series
68-
try:
69-
series_index = v_wind.index
70-
except AttributeError:
71-
series_index = range(1, len(power_output)+1)
72-
return pd.Series(data=power_output, index=series_index,
73-
name='feedin_wind_turbine')
69+
* np.power(v_wind, 3) * cp_time_series)
70+
# Power_output as pd.Series if v_wind is pd.Series
71+
if isinstance(v_wind, pd.Series):
72+
power_output = pd.Series(data=power_output, index=v_wind.index,
73+
name='feedin_wind_turbine')
74+
return power_output
7475

7576

7677
def cp_curve_density_corr(v_wind, rho_hub, d_rotor, cp_values):
@@ -87,16 +88,16 @@ def cp_curve_density_corr(v_wind, rho_hub, d_rotor, cp_values):
8788
Wind speed at hub height in m/s.
8889
rho_hub : pandas.Series or numpy.array
8990
Density of air at hub height in kg/m³.
91+
d_rotor : float
92+
Diameter of the rotor in m.
9093
cp_values : pandas.DataFrame
9194
Power coefficient curve of the wind turbine.
9295
Indices are the wind speeds of the power coefficient curve in m/s, the
9396
corresponding power coefficient values are in the column 'cp'.
94-
d_rotor : float
95-
Diameter of the rotor in m.
9697
9798
Returns
9899
-------
99-
pandas.Series
100+
pandas.Series or numpy.array
100101
Electrical power of the wind turbine in W.
101102
102103
Notes
@@ -116,7 +117,7 @@ def cp_curve_density_corr(v_wind, rho_hub, d_rotor, cp_values):
116117
return p_curve_density_corr(v_wind, rho_hub, p_values)
117118

118119

119-
def p_curve(p_values, v_wind):
120+
def p_curve(v_wind, p_values):
120121
r"""
121122
Calculates the turbine power output using a power curve.
122123
@@ -126,16 +127,16 @@ def p_curve(p_values, v_wind):
126127
127128
Parameters
128129
----------
130+
v_wind : pandas.Series or numpy.array
131+
Wind speed at hub height in m/s.
129132
p_values : pandas.DataFrame
130133
Power curve of the wind turbine.
131134
Indices are the wind speeds of the power curve in m/s, the
132135
corresponding power values in W are in the column 'p'.
133-
v_wind : pandas.Series or numpy.array
134-
Wind speed at hub height in m/s.
135136
136137
Returns
137138
-------
138-
pandas.Series
139+
pandas.Series or numpy.array
139140
Electrical power output of the wind turbine in W.
140141
141142
Notes
@@ -146,13 +147,11 @@ def p_curve(p_values, v_wind):
146147
"""
147148
power_output = np.interp(v_wind, p_values.index, p_values.p,
148149
left=0, right=0)
149-
# Set index for time series
150-
try:
151-
series_index = v_wind.index
152-
except AttributeError:
153-
series_index = range(1, len(power_output)+1)
154-
return pd.Series(data=power_output, index=series_index,
155-
name='feedin_wind_turbine')
150+
# Power_output as pd.Series if v_wind is pd.Series
151+
if isinstance(v_wind, pd.Series):
152+
power_output = pd.Series(data=power_output, index=v_wind.index,
153+
name='feedin_wind_turbine')
154+
return power_output
156155

157156

158157
def p_curve_density_corr(v_wind, rho_hub, p_values):
@@ -176,7 +175,7 @@ def p_curve_density_corr(v_wind, rho_hub, p_values):
176175
177176
Returns
178177
-------
179-
pandas.Series
178+
pandas.Series or numpy.array
180179
Electrical power output of the wind turbine in W.
181180
182181
Notes
@@ -219,17 +218,19 @@ def p_curve_density_corr(v_wind, rho_hub, p_values):
219218
at Reiner Lemoine Institute, 2014, p. 13
220219
221220
"""
221+
# Convert rho_hub to np.array if v_wind is np.array
222+
if (isinstance(v_wind, np.ndarray) and isinstance(rho_hub, pd.Series)):
223+
rho_hub = np.array(rho_hub)
222224
power_output = [(np.interp(v_wind[i],
223225
p_values.index * (1.225 / rho_hub[i])**(
224226
np.interp(p_values.index,
225227
[7.5, 12.5], [1/3, 2/3])),
226228
p_values.p, left=0, right=0))
227229
for i in range(len(v_wind))]
228-
229-
# Set index for time series
230-
try:
231-
series_index = v_wind.index
232-
except AttributeError:
233-
series_index = range(1, len(power_output)+1)
234-
return pd.Series(data=power_output, index=series_index,
235-
name='feedin_wind_turbine')
230+
# Power_output as pd.Series if v_wind is pd.Series
231+
if isinstance(v_wind, pd.Series):
232+
power_output = pd.Series(data=power_output, index=v_wind.index,
233+
name='feedin_wind_turbine')
234+
else:
235+
power_output = np.array(power_output)
236+
return power_output

windpowerlib/wind_speed.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
__license__ = "GPLv3"
99

1010
import numpy as np
11+
import pandas as pd
1112

1213

1314
def logarithmic_wind_profile(v_wind, v_wind_height, hub_height, z_0,
@@ -78,12 +79,15 @@ def logarithmic_wind_profile(v_wind, v_wind_height, hub_height, z_0,
7879
raise ValueError("To take an obstacle height of {0} m".format(
7980
obstacle_height) + " into consideration, wind" +
8081
" speed data of a greater height is needed.")
82+
# Return np.array if v_wind is np.array
83+
if (isinstance(v_wind, np.ndarray) and isinstance(z_0, pd.Series)):
84+
z_0 = np.array(z_0)
8185
return (v_wind * np.log((hub_height - 0.7 * obstacle_height) / z_0) /
8286
np.log((v_wind_height - 0.7 * obstacle_height) / z_0))
8387

8488

85-
def v_wind_hellman(v_wind, v_wind_height, hub_height, hellman_exp=None,
86-
z_0=None):
89+
def v_wind_hellman(v_wind, v_wind_height, hub_height, z_0=None,
90+
hellman_exp=None):
8791
r"""
8892
Calculates the wind speed at hub height using the hellman equation.
8993
@@ -99,14 +103,14 @@ def v_wind_hellman(v_wind, v_wind_height, hub_height, hellman_exp=None,
99103
Height for which the parameter `v_wind` applies.
100104
hub_height : float
101105
Hub height of wind turbine.
106+
z_0 : pandas.Series or numpy.array or float
107+
Roughness length. Default: None. If given and `hellman_exp` is None:
108+
`hellman_exp` = 1 / ln(h_hub/z_0), otherwise `hellman_exp` = 1/7.
102109
hellman_exp : float
103110
The Hellman exponent, which combines the increase in wind speed due to
104111
stability of atmospheric conditions and surface roughness into one
105112
constant. Default: None. If None and roughness length is given
106113
`hellman_exp` = 1 / ln(h_hub/z_0), otherwise `hellman_exp` = 1/7.
107-
z_0 : pandas.Series or numpy.array or float
108-
Roughness length. Default: None. If given
109-
`hellman_exp` = 1 / ln(h_hub/z_0), otherwise `hellman_exp` = 1/7.
110114
111115
Returns
112116
-------
@@ -149,6 +153,9 @@ def v_wind_hellman(v_wind, v_wind_height, hub_height, hellman_exp=None,
149153
"""
150154
if hellman_exp is None:
151155
if z_0 is not None:
156+
# Return np.array if v_wind is np.array
157+
if (isinstance(v_wind, np.ndarray) and isinstance(z_0, pd.Series)):
158+
z_0 = np.array(z_0)
152159
hellman_exp = 1 / np.log(hub_height / z_0)
153160
else:
154161
hellman_exp = 1/7

0 commit comments

Comments
 (0)