Skip to content

Commit 3167fa3

Browse files
committed
Bug fixes and test fixes
1 parent fb97168 commit 3167fa3

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

tests/test_modelchain.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ def test_run_model(self):
178178
test_turbine = {'hub_height': 100,
179179
'rotor_diameter': 80,
180180
'turbine_name': 'ENERCON E 126 7500',
181-
'fetch_curve': 'p'}
181+
'fetch_curve': 'power_curve'}
182182

183-
# Test with default parameters of modelchain (p curve)
183+
# Test with default parameters of modelchain (power curve)
184184
power_output_exp = pd.Series(data=[1731887.39768, 3820152.27489],
185185
name='feedin_wind_turbine')
186186
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine))
@@ -201,7 +201,7 @@ def test_run_model(self):
201201
# Test with power coefficient curve and hellman
202202
power_output_exp = pd.Series(data=[559060.36156, 1251143.98621],
203203
name='feedin_wind_turbine')
204-
test_turbine['fetch_curve'] = 'cp'
204+
test_turbine['fetch_curve'] = 'power_coefficient_curve'
205205
test_modelchain = {'wind_speed_model': 'hellman',
206206
'power_output_model': 'power_coefficient_curve',
207207
'density_correction': False}
@@ -229,17 +229,17 @@ def test_run_model(self):
229229
**test_modelchain)
230230
test_mc.run_model(weather_df)
231231
with pytest.raises(ValueError):
232-
test_modelchain['wind_speed_model'] = 'wrong_spelling'
232+
test_modelchain['density_model'] = 'wrong_spelling'
233233
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
234234
**test_modelchain)
235235
test_mc.run_model(weather_df)
236236
with pytest.raises(ValueError):
237-
test_modelchain['density_model'] = 'wrong_spelling'
237+
test_modelchain['temperature_model'] = 'wrong_spelling'
238238
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
239239
**test_modelchain)
240240
test_mc.run_model(weather_df)
241241
with pytest.raises(ValueError):
242-
test_modelchain['temperature_model'] = 'wrong_spelling'
242+
test_modelchain['wind_speed_model'] = 'wrong_spelling'
243243
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
244244
**test_modelchain)
245245
test_mc.run_model(weather_df)
@@ -263,7 +263,7 @@ def test_run_model(self):
263263
test_turbine = {'hub_height': 100,
264264
'rotor_diameter': 80,
265265
'turbine_name': 'ENERCON E 126 7500',
266-
'fetch_curve': 'p'}
266+
'fetch_curve': 'power_curve'}
267267
test_modelchain = {'power_output_model': 'power_coefficient_curve',
268268
'density_correction': True}
269269
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
@@ -273,7 +273,7 @@ def test_run_model(self):
273273
test_turbine = {'hub_height': 100,
274274
'rotor_diameter': 80,
275275
'turbine_name': 'ENERCON E 126 7500',
276-
'fetch_curve': 'cp'}
276+
'fetch_curve': 'power_coefficient_curve'}
277277
test_modelchain = {'power_output_model': 'power_curve',
278278
'density_corr': True}
279279
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),

tests/test_tools.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ def test_linear_interpolation_extrapolation(self):
3939
parameters['target_height'] = 5
4040
assert_series_equal(linear_interpolation_extrapolation(
4141
df, **parameters), exp_output)
42+

windpowerlib/modelchain.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def density_hub(self, weather_df):
236236
weather_df['density'], self.wind_turbine.hub_height)
237237
else:
238238
raise ValueError("'{0}' is an invalid value. ".format(
239-
self.density_model) + "`rho_model` " +
239+
self.density_model) + "`density_model` " +
240240
"must be 'barometric', 'ideal_gas' or " +
241241
"'interpolation_extrapolation'.")
242242
return density_hub
@@ -348,8 +348,8 @@ def turbine_power_output(self, wind_speed_hub, density_hub):
348348
'curve.')
349349
return (power_output.power_coefficient_curve(
350350
wind_speed_hub,
351-
self.wind_turbine.power_curve['wind_speed'],
352-
self.wind_turbine.power_curve['values'],
351+
self.wind_turbine.power_coefficient_curve['wind_speed'],
352+
self.wind_turbine.power_coefficient_curve['values'],
353353
self.wind_turbine.rotor_diameter, density_hub,
354354
self.density_correction))
355355
else:

windpowerlib/wind_turbine.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,19 @@ def restructure_data():
170170
data = np.vstack((data, np.array(
171171
[float(col), float(wpp_df[col])])))
172172
data = np.delete(data, 0, 0)
173-
df = pd.DataFrame(data, columns=['v_wind', self.fetch_curve])
174-
series = pd.Series(df[self.fetch_curve], index=df['v_wind'])
175-
nominal_power = wpp_df['p_nom'].iloc[0] * 1000.0 # kW to W
176-
return series, nominal_power
177-
if self.fetch_curve == 'p':
178-
filename = 'p_curves.csv'
179-
p_values, p_nom = restructure_data()
180-
self.p_values = p_values * 1000.0 # kW to W
173+
df = pd.DataFrame(data, columns=['wind_speed', 'values'])
174+
nominal_power = wpp_df['p_nom'].iloc[0]
175+
return df, nominal_power
176+
if self.fetch_curve == 'power_curve':
177+
filename = 'power_curves.csv'
178+
self.power_curve, p_nom = restructure_data()
179+
elif self.fetch_curve == 'power_coefficient_curve':
180+
filename = 'power_coefficient_curves.csv'
181+
self.power_coefficient_curve, p_nom = restructure_data()
181182
else:
182-
filename = 'cp_curves.csv'
183-
self.cp_values, p_nom = restructure_data()
183+
raise ValueError("'{0}' is an invalid value. ".format(
184+
self.fetch_curve) + "`fetch_curve` must be " +
185+
"'power_curve' or 'power_coefficient_curve'.")
184186
if self.nominal_power is None:
185187
self.nominal_power = p_nom
186188
return self
@@ -198,9 +200,8 @@ def read_turbine_data(**kwargs):
198200
datapath : string, optional
199201
Path where the data file is stored. Default: './data'
200202
filename : string, optional
201-
Name of data file. Provided data files are 'p_curves.csv' containing
202-
power curves and 'cp_curves.csv' containing power coefficient curves.
203-
Default: 'p_curves.csv'
203+
Name of data file. Provided data files are 'power_curves.csv' and
204+
'power_coefficient_curves.csv'. Default: 'power_curves.csv'.
204205
205206
Returns
206207
-------

0 commit comments

Comments
 (0)