Skip to content

Commit dda3b45

Browse files
committed
Fixing style errors.
1 parent a4a4eb8 commit dda3b45

25 files changed

+2425
-1595
lines changed

example/modelchain_example.py

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
try:
2020
from matplotlib import pyplot as plt
2121
except ImportError:
22-
plt=None
22+
plt = None
2323

2424
from windpowerlib import ModelChain
2525
from windpowerlib import WindTurbine
@@ -64,24 +64,29 @@ 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
73-
weather_df=pd.read_csv(
74-
file, index_col=0, header=[0, 1],
75-
date_parser=lambda idx: pd.to_datetime(idx, utc=True))
74+
weather_df = pd.read_csv(
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
78-
weather_df.index=pd.to_datetime(weather_df.index).tz_convert(
79-
'Europe/Berlin')
82+
weather_df.index = pd.to_datetime(weather_df.index).tz_convert(
83+
"Europe/Berlin"
84+
)
8085

8186
# change type of height from str to int by resetting columns
82-
l0=[_[0] for _ in weather_df.columns]
83-
l1=[int(_[1]) for _ in weather_df.columns]
84-
weather_df.columns=[l0, l1]
87+
l0 = [_[0] for _ in weather_df.columns]
88+
l1 = [int(_[1]) for _ in weather_df.columns]
89+
weather_df.columns = [l0, l1]
8590

8691
return weather_df
8792

@@ -111,37 +116,42 @@ def initialize_wind_turbines():
111116

112117
# specification of wind turbine where data is provided in the oedb
113118
# turbine library
114-
enercon_e126={
115-
'turbine_type': 'E-126/4200', # turbine type as in register
116-
'hub_height': 135 # in m
119+
enercon_e126 = {
120+
"turbine_type": "E-126/4200", # turbine type as in register
121+
"hub_height": 135, # in m
117122
}
118123
# initialize WindTurbine object
119-
e126=WindTurbine(**enercon_e126)
124+
e126 = WindTurbine(**enercon_e126)
120125

121126
# specification of own wind turbine (Note: power values and nominal power
122127
# have to be in Watt)
123-
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
128+
my_turbine = {
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
132-
my_turbine=WindTurbine(**my_turbine)
142+
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')
137-
dummy_turbine={
138-
'turbine_type': "DUMMY 1",
139-
'hub_height': 100, # in m
140-
'rotor_diameter': 70, # in m
141-
'path': csv_path
146+
csv_path = os.path.join(os.path.dirname(__file__), "data")
147+
dummy_turbine = {
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
144-
dummy_turbine=WindTurbine(**dummy_turbine)
154+
dummy_turbine = WindTurbine(**dummy_turbine)
145155

146156
return my_turbine, e126, dummy_turbine
147157

@@ -175,37 +185,38 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
175185
# power output calculation for my_turbine
176186
# initialize ModelChain with default parameters and use run_model method
177187
# to calculate power output
178-
mc_my_turbine=ModelChain(my_turbine).run_model(weather)
188+
mc_my_turbine = ModelChain(my_turbine).run_model(weather)
179189
# write power output time series to WindTurbine object
180-
my_turbine.power_output=mc_my_turbine.power_output
190+
my_turbine.power_output = mc_my_turbine.power_output
181191

182192
# power output calculation for e126
183193
# own specifications for ModelChain setup
184-
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
194+
modelchain_data = {
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
199-
mc_e126=ModelChain(e126, **modelchain_data).run_model(weather)
210+
mc_e126 = ModelChain(e126, **modelchain_data).run_model(weather)
200211
# write power output time series to WindTurbine object
201-
e126.power_output=mc_e126.power_output
212+
e126.power_output = mc_e126.power_output
202213

203214
# power output calculation for example_turbine
204215
# own specification for 'power_output_model'
205-
mc_example_turbine=ModelChain(
206-
dummy_turbine,
207-
power_output_model='power_coefficient_curve').run_model(weather)
208-
dummy_turbine.power_output=mc_example_turbine.power_output
216+
mc_example_turbine = ModelChain(
217+
dummy_turbine, power_output_model="power_coefficient_curve"
218+
).run_model(weather)
219+
dummy_turbine.power_output = mc_example_turbine.power_output
209220

210221
return
211222

@@ -272,8 +283,8 @@ def run_example():
272283
Runs the basic example.
273284
274285
"""
275-
weather=get_weather_data('weather.csv')
276-
my_turbine, e126, dummy_turbine=initialize_wind_turbines()
286+
weather = get_weather_data("weather.csv")
287+
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)
279290

example/test_examples.py

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,92 @@
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')
22-
my_turbine, e126, dummy_turbine=mc_e.initialize_wind_turbines()
20+
weather = mc_e.get_weather_data("weather.csv")
21+
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')
33-
my_turbine, e126, dummy_turbine=mc_e.initialize_wind_turbines()
34-
example_farm, example_farm_2=tc_mc_e.initialize_wind_farms(
35-
my_turbine, e126)
36-
example_cluster=tc_mc_e.initialize_wind_turbine_cluster(
37-
example_farm, example_farm_2)
35+
weather = mc_e.get_weather_data("weather.csv")
36+
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
37+
example_farm, example_farm_2 = tc_mc_e.initialize_wind_farms(
38+
my_turbine, e126
39+
)
40+
example_cluster = tc_mc_e.initialize_wind_turbine_cluster(
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
"""
4660
Execute a notebook via nbconvert and collect output.
4761
Returns (parsed nb object, execution errors)
4862
"""
49-
dirname, __=os.path.split(path)
63+
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)
58-
nb=nbformat.read(fout, nbformat.current_nbformat)
80+
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):
68-
dir_path=os.path.dirname(os.path.realpath(__file__))
69-
nb, errors=self._notebook_run(
70-
os.path.join(dir_path, 'modelchain_example.ipynb'))
94+
dir_path = os.path.dirname(os.path.realpath(__file__))
95+
nb, errors = self._notebook_run(
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):
75-
dir_path=os.path.dirname(os.path.realpath(__file__))
76-
nb, errors=self._notebook_run(
77-
os.path.join(dir_path, 'turbine_cluster_modelchain_example.ipynb'))
102+
dir_path = os.path.dirname(os.path.realpath(__file__))
103+
nb, errors = self._notebook_run(
104+
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
105+
)
78106
assert errors == []

0 commit comments

Comments
 (0)