Skip to content

Commit 6b06924

Browse files
committed
Adapt tests to new WindTurbine class
1 parent f43ec28 commit 6b06924

File tree

7 files changed

+18
-184
lines changed

7 files changed

+18
-184
lines changed

example/modelchain_example.ipynb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@
277277
" 'hub_height': 135, # in m\n",
278278
" 'rotor_diameter': 127, # in m (only needs to be provided when calculating the power \n",
279279
" # output using the power coefficient curve)\n",
280-
" 'power_curve': True, # data is fetched from oedb, is default value\n",
281-
" 'nominal_power': True, # data is fetched from oedb, is default value\n",
282280
" }\n",
283281
"# initialize WindTurbine object\n",
284282
"e126 = WindTurbine(**enercon_e126)"
@@ -317,8 +315,6 @@
317315
" 'turbine_type': 'DUMMY 1', # turbine type as in file\n",
318316
" 'hub_height': 100, # in m\n",
319317
" 'rotor_diameter': 70, # in m\n",
320-
" 'power_coefficient_curve': 'example_power_coefficient_curves.csv', # data is fetched from file\n",
321-
" 'nominal_power': 'example_turbine_data.csv', # data is fetched from file\n",
322318
" 'path': csv_path\n",
323319
"}\n",
324320
"# initialize WindTurbine object\n",

example/modelchain_example.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ def initialize_wind_turbines():
132132
'turbine_type': "DUMMY 1",
133133
'hub_height': 100, # in m
134134
'rotor_diameter': 70, # in m
135-
'power_coefficient_curve':
136-
'example_power_coefficient_curves.csv', # data is fetched from
137-
# file
138-
'nominal_power': 'example_turbine_data.csv', # data is fetched from
139-
# file
140135
'path': csv_path
141136
}
142137
# initialize WindTurbine object
@@ -150,10 +145,6 @@ def initialize_wind_turbines():
150145
'turbine_type': 'E-126/4200', # turbine type as in register
151146
'hub_height': 135, # in m
152147
'rotor_diameter': 127, # in m
153-
'power_coefficient_curve':
154-
False, # curve data is not fetched (default)
155-
'power_curve': True, # data is fetched from oedb turbine library
156-
'nominal_power': True, # data is fetched from oedb turbine library
157148
}
158149
# initialize WindTurbine object
159150
e126 = WindTurbine(**enercon_e126)

tests/test_modelchain.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ def test_run_model(self):
184184

185185
test_turbine = {'hub_height': 100,
186186
'rotor_diameter': 80,
187-
'turbine_type': 'E-126/4200',
188-
'power_curve': True,
189-
'power_coefficient_curve': True}
187+
'turbine_type': 'E-126/4200'}
190188

191189
# Test with default parameters of modelchain (power curve)
192190
power_output_exp = pd.Series(data=[1637405.4840444783,
@@ -251,11 +249,12 @@ def test_run_model(self):
251249
test_mc.run_model(weather_df)
252250

253251
# Raise TypeErrors due to missing cp- or p-values
252+
# with pytest.raises(TypeError):
254253
with pytest.raises(TypeError):
255254
test_turbine = {'hub_height': 100,
256255
'rotor_diameter': 80,
257256
'turbine_type': 'E-126/4200',
258-
'power_curve': True}
257+
'power_coefficient_curve': 'True'}
259258
test_modelchain = {'power_output_model': 'power_coefficient_curve',
260259
'density_correction': True}
261260
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),
@@ -265,7 +264,7 @@ def test_run_model(self):
265264
test_turbine = {'hub_height': 100,
266265
'rotor_diameter': 80,
267266
'turbine_type': 'E-126/4200',
268-
'power_coefficient_curve': True}
267+
'power_curve': 'True'}
269268
test_modelchain = {'power_output_model': 'power_curve',
270269
'density_corr': True}
271270
test_mc = mc.ModelChain(wt.WindTurbine(**test_turbine),

tests/test_power_curves.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class TestPowerCurves:
1313
@classmethod
1414
def setup_class(self):
1515
self.test_turbine = {'hub_height': 100,
16-
'turbine_type': 'E-126/4200',
17-
'power_curve': True}
16+
'turbine_type': 'E-126/4200'}
1817

1918
def test_smooth_power_curve(self):
2019
test_curve = wt.WindTurbine(**self.test_turbine).power_curve

tests/test_turbine_cluster_modelchain.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ def setup_class(self):
3636
np.array([2, 10, 0, 8, 10, 0])])
3737
self.test_turbine = {'hub_height': 100,
3838
'rotor_diameter': 80,
39-
'turbine_type': 'E-126/4200',
40-
'power_curve': True}
39+
'turbine_type': 'E-126/4200'}
4140
self.test_turbine_2 = {'hub_height': 90,
4241
'rotor_diameter': 60,
4342
'turbine_type': 'V90/2000',
44-
'power_curve': True,
4543
'nominal_power': 2000000.0
4644
}
4745
self.test_farm = {'wind_turbine_fleet': [
@@ -197,7 +195,7 @@ def test_error_raising(self):
197195
'hub_height': 100,
198196
'rotor_diameter': 98,
199197
'turbine_type': 'V90/2000',
200-
'power_coefficient_curve': True}
198+
'power_curve': True}
201199
test_farm = {'wind_turbine_fleet':
202200
[{'wind_turbine':
203201
wt.WindTurbine(**self.test_turbine),

tests/test_wind_turbine.py

Lines changed: 10 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pytest
2-
import pandas as pd
32
import os
43

54
from windpowerlib.wind_turbine import (get_turbine_data_from_file, WindTurbine,
@@ -8,169 +7,22 @@
87

98
class TestWindTurbine:
109

11-
def test_initialization_power_curve(self):
12-
13-
# power curve from oedb turbine data
14-
self.test_turbine_data = {'hub_height': 100,
15-
'power_curve': True,
16-
'turbine_type': 'E-126/4200'}
17-
try:
18-
WindTurbine(**self.test_turbine_data)
19-
assert True
20-
except:
21-
assert False
22-
# power curve from self provided csv file
23-
self.test_turbine_data = {
24-
'hub_height': 100,
25-
'power_curve': 'example_power_curves.csv',
26-
'turbine_type': 'DUMMY 3',
27-
'path': os.path.join(os.path.dirname(__file__), '../example/data')}
28-
try:
29-
WindTurbine(**self.test_turbine_data)
30-
assert True
31-
except:
32-
assert False
33-
34-
# directly provided power curve (dictionary)
35-
self.test_turbine_data = {'hub_height': 100,
36-
'power_curve': {'wind_speed': [0, 10],
37-
'value': [0, 3]}}
38-
try:
39-
WindTurbine(**self.test_turbine_data)
40-
assert True
41-
except:
42-
assert False
43-
44-
# directly provided power curve (dataframe)
45-
self.test_turbine_data = {
46-
'hub_height': 100,
47-
'power_curve': pd.DataFrame({'wind_speed': [0, 10],
48-
'value': [0, 3]})}
49-
try:
50-
WindTurbine(**self.test_turbine_data)
51-
assert True
52-
except:
53-
assert False
54-
55-
def test_initialization_power_coefficient_curve(self):
56-
57-
# power coefficient curve from oedb turbine data
58-
self.test_turbine_data = {'hub_height': 100,
59-
'power_coefficient_curve': True,
60-
'turbine_type': 'E-126/4200'}
61-
try:
62-
WindTurbine(**self.test_turbine_data)
63-
assert True
64-
except:
65-
assert False
66-
67-
# power coefficient curve from self provided csv file
68-
self.test_turbine_data = {
69-
'hub_height': 100,
70-
'power_coefficient_curve': 'example_power_curves.csv',
71-
'nominal_power': 'example_turbine_data.csv',
72-
'turbine_type': 'DUMMY 3',
73-
'path': os.path.join(os.path.dirname(__file__), '../example/data')}
74-
try:
75-
WindTurbine(**self.test_turbine_data)
76-
assert True
77-
except:
78-
assert False
79-
80-
# directly provided power coefficient curve (dictionary)
81-
self.test_turbine_data = {'hub_height': 100,
82-
'power_coefficient_curve':
83-
{'wind_speed': [0, 10],
84-
'value': [0, 0.3]},
85-
'nominal_power': 3e6}
86-
try:
87-
WindTurbine(**self.test_turbine_data)
88-
assert True
89-
except:
90-
assert False
91-
92-
# directly provided power coefficient curve (dataframe)
93-
self.test_turbine_data = {'hub_height': 100,
94-
'power_coefficient_curve':
95-
pd.DataFrame({
96-
'wind_speed': [0, 10],
97-
'value': [0, 3]}),
98-
'nominal_power': 3e6}
99-
try:
100-
WindTurbine(**self.test_turbine_data)
101-
assert True
102-
except:
103-
assert False
104-
10510
def test_error_raising(self):
106-
107-
# Raise KeyError due to turbine type not in oedb turbine data
108-
self.test_turbine_data = {'hub_height': 100,
109-
'power_curve': True,
110-
'turbine_type': 'E-turbine_not_in_file/4200'}
111-
with pytest.raises(KeyError):
112-
WindTurbine(**self.test_turbine_data)
113-
114-
# Raise KeyError due to turbine type not in file
115-
self.test_turbine_data = {
116-
'hub_height': 100,
117-
'power_curve': True,
118-
'turbine_type': 'turbine_not_in_file',
119-
'power_coefficient_curve': 'example_power_curves.csv',
120-
'path': os.path.join(os.path.dirname(__file__), '../example/data')}
121-
with pytest.raises(KeyError):
122-
WindTurbine(**self.test_turbine_data)
123-
124-
# Raise TypeError due to invalid type for power curve and power
125-
# coefficient curve
126-
self.test_turbine_data = {'hub_height': 100,
127-
'power_curve': 3.0}
128-
with pytest.raises(TypeError):
129-
WindTurbine(**self.test_turbine_data)
130-
131-
self.test_turbine_data = {'hub_height': 100,
132-
'power_coefficient_curve': 3.0}
133-
with pytest.raises(TypeError):
134-
WindTurbine(**self.test_turbine_data)
135-
136-
# Raise TypeError due to invalid type for nominal power
137-
self.test_turbine_data = {'hub_height': 100,
138-
'power_curve': True,
139-
'turbine_type': 'E-126/4200',
140-
'nominal_power': [3]}
141-
with pytest.raises(TypeError):
142-
WindTurbine(**self.test_turbine_data)
143-
144-
# Raise AttributeError in case no power or power coefficient curve
145-
# is set
146-
self.test_turbine_data = {'hub_height': 100}
147-
with pytest.raises(AttributeError):
148-
WindTurbine(**self.test_turbine_data)
149-
150-
# Raise ValueError due to missing nominal power when using power
151-
# coefficient curve
11+
source = os.path.join(os.path.dirname(__file__), '../example/data')
15212
self.test_turbine_data = {'hub_height': 100,
153-
'power_coefficient_curve':
154-
pd.DataFrame({
155-
'wind_speed': [0, 10],
156-
'value': [0, 3]})}
157-
with pytest.raises(ValueError):
158-
WindTurbine(**self.test_turbine_data)
13+
'rotor_diameter': 80,
14+
'turbine_type': 'turbine_not_in_file',
15+
'path': source}
16+
# Raise system exit due to turbine type not in file
17+
# with pytest.raises(SystemExit):
18+
assert(WindTurbine(**self.test_turbine_data).power_curve is None)
15919

16020
def test_get_turbine_data_from_file(self):
16121
# Raise FileNotFoundError due to missing
16222
with pytest.raises(FileNotFoundError):
16323
get_turbine_data_from_file(turbine_type='...',
164-
file_='not_existent')
24+
path='not_existent')
16525

16626
def test_get_turbine_types(self):
167-
# local with and without filter
168-
get_turbine_types(turbine_library='local', print_out=True,
169-
filter_=True)
170-
get_turbine_types(turbine_library='local', print_out=False,
171-
filter_=False)
172-
# oedb with and without filter
173-
get_turbine_types(turbine_library='oedb', print_out=False,
174-
filter_=True)
175-
get_turbine_types(turbine_library='oedb', print_out=False,
176-
filter_=False)
27+
get_turbine_types(print_out=True, filter_=True)
28+
get_turbine_types(print_out=False, filter_=False)

windpowerlib/wind_farm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class WindFarm(object):
6464
>>> enerconE126 = {
6565
... 'hub_height': 135,
6666
... 'rotor_diameter': 127,
67-
... 'turbine_type': 'E-126/4200',
68-
... 'power_curve': True}
67+
... 'turbine_type': 'E-126/4200'}
6968
>>> e126 = wind_turbine.WindTurbine(**enerconE126)
7069
>>> example_farm_data = {
7170
... 'name': 'example_farm',

0 commit comments

Comments
 (0)