Skip to content

Commit 37e68df

Browse files
committed
Revert "Fixing style errors."
This reverts commit b5c3a1e.
1 parent 5d33233 commit 37e68df

25 files changed

+1595
-2425
lines changed

example/modelchain_example.py

Lines changed: 55 additions & 66 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,29 +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(
69-
os.path.split(os.path.dirname(__file__))[0], "example"
70-
)
71-
file = os.path.join(kwargs["datapath"], filename)
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)
7271

7372
# read csv file
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-
)
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))
8076

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

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

9186
return weather_df
9287

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

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

126121
# specification of own wind turbine (Note: power values and nominal power
127122
# have to be in Watt)
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
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
140130
}
141131
# initialize WindTurbine object
142-
my_turbine = WindTurbine(**my_turbine)
132+
my_turbine=WindTurbine(**my_turbine)
143133

144134
# specification of wind turbine where power coefficient curve and nominal
145135
# power is provided in an own csv file
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,
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
152142
}
153143
# initialize WindTurbine object
154-
dummy_turbine = WindTurbine(**dummy_turbine)
144+
dummy_turbine=WindTurbine(**dummy_turbine)
155145

156146
return my_turbine, e126, dummy_turbine
157147

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

192182
# power output calculation for e126
193183
# own specifications for ModelChain setup
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
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
208197
# initialize ModelChain with own specifications and use run_model method
209198
# to calculate power output
210-
mc_e126 = ModelChain(e126, **modelchain_data).run_model(weather)
199+
mc_e126=ModelChain(e126, **modelchain_data).run_model(weather)
211200
# write power output time series to WindTurbine object
212-
e126.power_output = mc_e126.power_output
201+
e126.power_output=mc_e126.power_output
213202

214203
# power output calculation for example_turbine
215204
# own specification for 'power_output_model'
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
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
220209

221210
return
222211

@@ -283,8 +272,8 @@ def run_example():
283272
Runs the basic example.
284273
285274
"""
286-
weather = get_weather_data("weather.csv")
287-
my_turbine, e126, dummy_turbine = initialize_wind_turbines()
275+
weather=get_weather_data('weather.csv')
276+
my_turbine, e126, dummy_turbine=initialize_wind_turbines()
288277
calculate_power_output(weather, my_turbine, e126, dummy_turbine)
289278
plot_or_print(my_turbine, e126, dummy_turbine)
290279

example/test_examples.py

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,92 +15,64 @@
1515

1616

1717
class TestExamples:
18+
1819
def test_modelchain_example_flh(self):
1920
# tests full load hours
20-
weather = mc_e.get_weather_data("weather.csv")
21-
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
21+
weather=mc_e.get_weather_data('weather.csv')
22+
my_turbine, e126, dummy_turbine=mc_e.initialize_wind_turbines()
2223
mc_e.calculate_power_output(weather, my_turbine, e126, dummy_turbine)
2324

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-
)
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)
3229

3330
def test_turbine_cluster_modelchain_example_flh(self):
3431
# tests full load hours
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-
)
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)
4338
tc_mc_e.calculate_power_output(weather, example_farm, example_cluster)
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-
)
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)
5743

5844
def _notebook_run(self, path):
5945
"""
6046
Execute a notebook via nbconvert and collect output.
6147
Returns (parsed nb object, execution errors)
6248
"""
63-
dirname, __ = os.path.split(path)
49+
dirname, __=os.path.split(path)
6450
os.chdir(dirname)
6551
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
66-
args = [
67-
"jupyter",
68-
"nbconvert",
69-
"--to",
70-
"notebook",
71-
"--execute",
72-
"--ExecutePreprocessor.timeout=60",
73-
"--output",
74-
fout.name,
75-
path,
76-
]
52+
args=["jupyter", "nbconvert", "--to", "notebook", "--execute",
53+
"--ExecutePreprocessor.timeout=60",
54+
"--output", fout.name, path]
7755
subprocess.check_call(args)
7856

7957
fout.seek(0)
80-
nb = nbformat.read(fout, nbformat.current_nbformat)
58+
nb=nbformat.read(fout, nbformat.current_nbformat)
8159

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-
]
60+
errors=[output for cell in nb.cells if "outputs" in cell
61+
for output in cell["outputs"]
62+
if output.output_type == "error"]
8963

9064
return nb, errors
9165

9266
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
9367
def test_modelchain_example_ipynb(self):
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-
)
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'))
9871
assert errors == []
9972

10073
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
10174
def test_turbine_cluster_modelchain_example_ipynb(self):
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-
)
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'))
10678
assert errors == []

0 commit comments

Comments
 (0)