Skip to content

Commit e20310b

Browse files
authored
Merge pull request #91 from wind-python/features/test-stickler-ci
Add stickler and black config files
2 parents c4a5dbd + fb4f10b commit e20310b

28 files changed

+2224
-1346
lines changed

.stickler.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
linters:
2+
flake8:
3+
python: 3
4+
max-line-length: 79
5+
select: C,E,F,W,B,B950
6+
ignore: E203, E501, W503
7+
black:
8+
config: ./pyproject.toml
9+
fixer: true
10+
11+
fixers:
12+
enable: true

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ matrix:
55
- python: 3.5
66
- python: 3.6
77
- python: 3.7
8-
dist: xenial
9-
sudo: true
8+
- python: 3.8
109

1110
# command to install dependencies
1211
#before_install:

example/modelchain_example.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,24 @@ def get_weather_data(filename='weather.csv', **kwargs):
6464
6565
"""
6666

67-
if 'datapath' not in kwargs:
68-
kwargs['datapath'] = os.path.join(os.path.split(
69-
os.path.dirname(__file__))[0], 'example')
70-
file = os.path.join(kwargs['datapath'], filename)
67+
if "datapath" not in kwargs:
68+
kwargs["datapath"] = os.path.join(
69+
os.path.split(os.path.dirname(__file__))[0], "example"
70+
)
71+
file = os.path.join(kwargs["datapath"], filename)
7172

7273
# read csv file
7374
weather_df = pd.read_csv(
74-
file, index_col=0, header=[0, 1],
75-
date_parser=lambda idx: pd.to_datetime(idx, utc=True))
75+
file,
76+
index_col=0,
77+
header=[0, 1],
78+
date_parser=lambda idx: pd.to_datetime(idx, utc=True),
79+
)
7680

7781
# change type of index to datetime and set time zone
7882
weather_df.index = pd.to_datetime(weather_df.index).tz_convert(
79-
'Europe/Berlin')
83+
"Europe/Berlin"
84+
)
8085

8186
# change type of height from str to int by resetting columns
8287
l0 = [_[0] for _ in weather_df.columns]
@@ -112,33 +117,38 @@ def initialize_wind_turbines():
112117
# specification of wind turbine where data is provided in the oedb
113118
# turbine library
114119
enercon_e126 = {
115-
'turbine_type': 'E-126/4200', # turbine type as in register
116-
'hub_height': 135 # in m
120+
"turbine_type": "E-126/4200", # turbine type as in register
121+
"hub_height": 135, # in m
117122
}
118123
# initialize WindTurbine object
119124
e126 = WindTurbine(**enercon_e126)
120125

121126
# specification of own wind turbine (Note: power values and nominal power
122127
# have to be in Watt)
123128
my_turbine = {
124-
'nominal_power': 3e6, # in W
125-
'hub_height': 105, # in m
126-
'power_curve': pd.DataFrame(
127-
data={'value': [p * 1000 for p in [
128-
0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]], # in W
129-
'wind_speed': [0.0, 3.0, 5.0, 10.0, 15.0, 25.0]}) # in m/s
129+
"nominal_power": 3e6, # in W
130+
"hub_height": 105, # in m
131+
"power_curve": pd.DataFrame(
132+
data={
133+
"value": [
134+
p * 1000
135+
for p in [0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]
136+
], # in W
137+
"wind_speed": [0.0, 3.0, 5.0, 10.0, 15.0, 25.0],
138+
}
139+
), # in m/s
130140
}
131141
# initialize WindTurbine object
132142
my_turbine = WindTurbine(**my_turbine)
133143

134144
# specification of wind turbine where power coefficient curve and nominal
135145
# power is provided in an own csv file
136-
csv_path = os.path.join(os.path.dirname(__file__), 'data')
146+
csv_path = os.path.join(os.path.dirname(__file__), "data")
137147
dummy_turbine = {
138-
'turbine_type': "DUMMY 1",
139-
'hub_height': 100, # in m
140-
'rotor_diameter': 70, # in m
141-
'path': csv_path
148+
"turbine_type": "DUMMY 1",
149+
"hub_height": 100, # in m
150+
"rotor_diameter": 70, # in m
151+
"path": csv_path,
142152
}
143153
# initialize WindTurbine object
144154
dummy_turbine = WindTurbine(**dummy_turbine)
@@ -182,18 +192,19 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
182192
# power output calculation for e126
183193
# own specifications for ModelChain setup
184194
modelchain_data = {
185-
'wind_speed_model': 'logarithmic', # 'logarithmic' (default),
186-
# 'hellman' or
187-
# 'interpolation_extrapolation'
188-
'density_model': 'ideal_gas', # 'barometric' (default), 'ideal_gas' or
189-
# 'interpolation_extrapolation'
190-
'temperature_model': 'linear_gradient', # 'linear_gradient' (def.) or
191-
# 'interpolation_extrapolation'
192-
'power_output_model': 'power_curve', # 'power_curve' (default) or
193-
# 'power_coefficient_curve'
194-
'density_correction': True, # False (default) or True
195-
'obstacle_height': 0, # default: 0
196-
'hellman_exp': None} # None (default) or None
195+
"wind_speed_model": "logarithmic", # 'logarithmic' (default),
196+
# 'hellman' or
197+
# 'interpolation_extrapolation'
198+
"density_model": "ideal_gas", # 'barometric' (default), 'ideal_gas' or
199+
# 'interpolation_extrapolation'
200+
"temperature_model": "linear_gradient", # 'linear_gradient' (def.) or
201+
# 'interpolation_extrapolation'
202+
"power_output_model": "power_curve", # 'power_curve' (default) or
203+
# 'power_coefficient_curve'
204+
"density_correction": True, # False (default) or True
205+
"obstacle_height": 0, # default: 0
206+
"hellman_exp": None,
207+
} # None (default) or None
197208
# initialize ModelChain with own specifications and use run_model method
198209
# to calculate power output
199210
mc_e126 = ModelChain(e126, **modelchain_data).run_model(weather)
@@ -203,8 +214,8 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
203214
# power output calculation for example_turbine
204215
# own specification for 'power_output_model'
205216
mc_example_turbine = ModelChain(
206-
dummy_turbine,
207-
power_output_model='power_coefficient_curve').run_model(weather)
217+
dummy_turbine, power_output_model="power_coefficient_curve"
218+
).run_model(weather)
208219
dummy_turbine.power_output = mc_example_turbine.power_output
209220

210221
return
@@ -272,7 +283,7 @@ def run_example():
272283
Runs the basic example.
273284
274285
"""
275-
weather = get_weather_data('weather.csv')
286+
weather = get_weather_data("weather.csv")
276287
my_turbine, e126, dummy_turbine = initialize_wind_turbines()
277288
calculate_power_output(weather, my_turbine, e126, dummy_turbine)
278289
plot_or_print(my_turbine, e126, dummy_turbine)

example/test_examples.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,45 @@
1515

1616

1717
class TestExamples:
18-
1918
def test_modelchain_example_flh(self):
2019
# tests full load hours
21-
weather = mc_e.get_weather_data('weather.csv')
20+
weather = mc_e.get_weather_data("weather.csv")
2221
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
2322
mc_e.calculate_power_output(weather, my_turbine, e126, dummy_turbine)
2423

25-
assert_allclose(2764.194772, (e126.power_output.sum() /
26-
e126.nominal_power), 0.01)
27-
assert_allclose(1882.7567, (my_turbine.power_output.sum() /
28-
my_turbine.nominal_power), 0.01)
24+
assert_allclose(
25+
2764.194772, (e126.power_output.sum() / e126.nominal_power), 0.01
26+
)
27+
assert_allclose(
28+
1882.7567,
29+
(my_turbine.power_output.sum() / my_turbine.nominal_power),
30+
0.01,
31+
)
2932

3033
def test_turbine_cluster_modelchain_example_flh(self):
3134
# tests full load hours
32-
weather = mc_e.get_weather_data('weather.csv')
35+
weather = mc_e.get_weather_data("weather.csv")
3336
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
3437
example_farm, example_farm_2 = tc_mc_e.initialize_wind_farms(
35-
my_turbine, e126)
38+
my_turbine, e126
39+
)
3640
example_cluster = tc_mc_e.initialize_wind_turbine_cluster(
37-
example_farm, example_farm_2)
41+
example_farm, example_farm_2
42+
)
3843
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
39-
assert_allclose(1956.164053, (example_farm.power_output.sum() /
40-
example_farm.nominal_power), 0.01)
41-
assert_allclose(2156.794154, (example_cluster.power_output.sum() /
42-
example_cluster.nominal_power), 0.01)
44+
assert_allclose(
45+
1956.164053,
46+
(example_farm.power_output.sum() / example_farm.nominal_power),
47+
0.01,
48+
)
49+
assert_allclose(
50+
2156.794154,
51+
(
52+
example_cluster.power_output.sum()
53+
/ example_cluster.nominal_power
54+
),
55+
0.01,
56+
)
4357

4458
def _notebook_run(self, path):
4559
"""
@@ -49,30 +63,44 @@ def _notebook_run(self, path):
4963
dirname, __ = os.path.split(path)
5064
os.chdir(dirname)
5165
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
52-
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
53-
"--ExecutePreprocessor.timeout=60",
54-
"--output", fout.name, path]
66+
args = [
67+
"jupyter",
68+
"nbconvert",
69+
"--to",
70+
"notebook",
71+
"--execute",
72+
"--ExecutePreprocessor.timeout=60",
73+
"--output",
74+
fout.name,
75+
path,
76+
]
5577
subprocess.check_call(args)
5678

5779
fout.seek(0)
5880
nb = nbformat.read(fout, nbformat.current_nbformat)
5981

60-
errors = [output for cell in nb.cells if "outputs" in cell
61-
for output in cell["outputs"]
62-
if output.output_type == "error"]
82+
errors = [
83+
output
84+
for cell in nb.cells
85+
if "outputs" in cell
86+
for output in cell["outputs"]
87+
if output.output_type == "error"
88+
]
6389

6490
return nb, errors
6591

6692
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
6793
def test_modelchain_example_ipynb(self):
6894
dir_path = os.path.dirname(os.path.realpath(__file__))
6995
nb, errors = self._notebook_run(
70-
os.path.join(dir_path, 'modelchain_example.ipynb'))
96+
os.path.join(dir_path, "modelchain_example.ipynb")
97+
)
7198
assert errors == []
7299

73100
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
74101
def test_turbine_cluster_modelchain_example_ipynb(self):
75102
dir_path = os.path.dirname(os.path.realpath(__file__))
76103
nb, errors = self._notebook_run(
77-
os.path.join(dir_path, 'turbine_cluster_modelchain_example.ipynb'))
104+
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
105+
)
78106
assert errors == []

example/turbine_cluster_modelchain_example.py

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,27 @@ def initialize_wind_farms(my_turbine, e126):
5959
# that type in the wind farm (float values are possible as well) or the
6060
# total installed capacity of that turbine type in W
6161
wind_turbine_fleet = pd.DataFrame(
62-
{'wind_turbine': [my_turbine, e126], # as windpowerlib.WindTurbine
63-
'number_of_turbines': [6, None],
64-
'total_capacity': [None, 12.6e6]}
62+
{
63+
"wind_turbine": [my_turbine, e126], # as windpowerlib.WindTurbine
64+
"number_of_turbines": [6, None],
65+
"total_capacity": [None, 12.6e6],
66+
}
6567
)
6668
# initialize WindFarm object
67-
example_farm = WindFarm(name='example_farm',
68-
wind_turbine_fleet=wind_turbine_fleet)
69+
example_farm = WindFarm(
70+
name="example_farm", wind_turbine_fleet=wind_turbine_fleet
71+
)
6972

7073
# specification of wind farm data (2) containing a wind farm efficiency
7174
# wind turbine fleet is provided using the to_group function
7275
example_farm_2_data = {
73-
'name': 'example_farm_2',
74-
'wind_turbine_fleet': [my_turbine.to_group(6),
75-
e126.to_group(total_capacity=12.6e6)],
76-
'efficiency': 0.9}
76+
"name": "example_farm_2",
77+
"wind_turbine_fleet": [
78+
my_turbine.to_group(6),
79+
e126.to_group(total_capacity=12.6e6),
80+
],
81+
"efficiency": 0.9,
82+
}
7783
# initialize WindFarm object
7884
example_farm_2 = WindFarm(**example_farm_2_data)
7985

@@ -104,8 +110,9 @@ def initialize_wind_turbine_cluster(example_farm, example_farm_2):
104110

105111
# specification of cluster data
106112
example_cluster_data = {
107-
'name': 'example_cluster',
108-
'wind_farms': [example_farm, example_farm_2]}
113+
"name": "example_cluster",
114+
"wind_farms": [example_farm, example_farm_2],
115+
}
109116
# initialize WindTurbineCluster object
110117
example_cluster = WindTurbineCluster(**example_cluster_data)
111118

@@ -144,35 +151,36 @@ class that provides all necessary steps to calculate the power output of a
144151
# power output calculation for turbine_cluster
145152
# own specifications for TurbineClusterModelChain setup
146153
modelchain_data = {
147-
'wake_losses_model':
148-
'wind_farm_efficiency', # 'dena_mean' (default), None,
149-
# 'wind_farm_efficiency' or name
150-
# of another wind efficiency curve
151-
# see :py:func:`~.wake_losses.get_wind_efficiency_curve`
152-
'smoothing': True, # False (default) or True
153-
'block_width': 0.5, # default: 0.5
154-
'standard_deviation_method': 'Staffell_Pfenninger', #
155-
# 'turbulence_intensity' (default)
156-
# or 'Staffell_Pfenninger'
157-
'smoothing_order': 'wind_farm_power_curves', #
158-
# 'wind_farm_power_curves' (default) or
159-
# 'turbine_power_curves'
160-
'wind_speed_model': 'logarithmic', # 'logarithmic' (default),
161-
# 'hellman' or
162-
# 'interpolation_extrapolation'
163-
'density_model': 'ideal_gas', # 'barometric' (default), 'ideal_gas' or
164-
# 'interpolation_extrapolation'
165-
'temperature_model': 'linear_gradient', # 'linear_gradient' (def.) or
166-
# 'interpolation_extrapolation'
167-
'power_output_model': 'power_curve', # 'power_curve' (default) or
168-
# 'power_coefficient_curve'
169-
'density_correction': True, # False (default) or True
170-
'obstacle_height': 0, # default: 0
171-
'hellman_exp': None} # None (default) or None
154+
"wake_losses_model": "wind_farm_efficiency", # 'dena_mean' (default), None,
155+
# 'wind_farm_efficiency' or name
156+
# of another wind efficiency curve
157+
# see :py:func:`~.wake_losses.get_wind_efficiency_curve`
158+
"smoothing": True, # False (default) or True
159+
"block_width": 0.5, # default: 0.5
160+
"standard_deviation_method": "Staffell_Pfenninger", #
161+
# 'turbulence_intensity' (default)
162+
# or 'Staffell_Pfenninger'
163+
"smoothing_order": "wind_farm_power_curves", #
164+
# 'wind_farm_power_curves' (default) or
165+
# 'turbine_power_curves'
166+
"wind_speed_model": "logarithmic", # 'logarithmic' (default),
167+
# 'hellman' or
168+
# 'interpolation_extrapolation'
169+
"density_model": "ideal_gas", # 'barometric' (default), 'ideal_gas' or
170+
# 'interpolation_extrapolation'
171+
"temperature_model": "linear_gradient", # 'linear_gradient' (def.) or
172+
# 'interpolation_extrapolation'
173+
"power_output_model": "power_curve", # 'power_curve' (default) or
174+
# 'power_coefficient_curve'
175+
"density_correction": True, # False (default) or True
176+
"obstacle_height": 0, # default: 0
177+
"hellman_exp": None,
178+
} # None (default) or None
172179
# initialize TurbineClusterModelChain with own specifications and use
173180
# run_model method to calculate power output
174181
mc_example_cluster = TurbineClusterModelChain(
175-
example_cluster, **modelchain_data).run_model(weather)
182+
example_cluster, **modelchain_data
183+
).run_model(weather)
176184
# write power output time series to WindTurbineCluster object
177185
example_cluster.power_output = mc_example_cluster.power_output
178186

@@ -209,11 +217,12 @@ def run_example():
209217
Runs the example.
210218
211219
"""
212-
weather = mc_e.get_weather_data('weather.csv')
220+
weather = mc_e.get_weather_data("weather.csv")
213221
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
214222
example_farm, example_farm_2 = initialize_wind_farms(my_turbine, e126)
215-
example_cluster = initialize_wind_turbine_cluster(example_farm,
216-
example_farm_2)
223+
example_cluster = initialize_wind_turbine_cluster(
224+
example_farm, example_farm_2
225+
)
217226
calculate_power_output(weather, example_farm, example_cluster)
218227
plot_or_print(example_farm, example_cluster)
219228

0 commit comments

Comments
 (0)