Skip to content

Commit 5614282

Browse files
committed
Remove Dummy turbine and download weather
1 parent 4b7a082 commit 5614282

3 files changed

Lines changed: 42 additions & 60 deletions

File tree

example/modelchain_example.py

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@
1515
"""
1616
import os
1717
import pandas as pd
18+
import logging
19+
import requests
20+
from windpowerlib import ModelChain
21+
from windpowerlib import WindTurbine
1822

1923
try:
2024
from matplotlib import pyplot as plt
2125
except ImportError:
2226
plt = None
2327

24-
from windpowerlib import ModelChain
25-
from windpowerlib import WindTurbine
26-
27-
# You can use the logging package to get logging messages from the windpowerlib
28-
# Change the logging level if you want more or less messages
29-
import logging
30-
logging.getLogger().setLevel(logging.DEBUG)
31-
3228

3329
def get_weather_data(filename='weather.csv', **kwargs):
3430
r"""
@@ -65,11 +61,16 @@ def get_weather_data(filename='weather.csv', **kwargs):
6561
"""
6662

6763
if "datapath" not in kwargs:
68-
kwargs["datapath"] = os.path.join(
69-
os.path.split(os.path.dirname(__file__))[0], "example"
70-
)
64+
kwargs["datapath"] = os.path.dirname(__file__)
65+
7166
file = os.path.join(kwargs["datapath"], filename)
7267

68+
if not os.path.isfile(file):
69+
logging.debug("Download weather data for example.")
70+
req = requests.get("https://osf.io/59bqn/download")
71+
with open(file, "wb") as fout:
72+
fout.write(req.content)
73+
7374
# read csv file
7475
weather_df = pd.read_csv(
7576
file,
@@ -136,22 +137,10 @@ def initialize_wind_turbines():
136137
# initialize WindTurbine object
137138
my_turbine = WindTurbine(**my_turbine)
138139

139-
# specification of wind turbine where power coefficient curve and nominal
140-
# power is provided in an own csv file
141-
csv_path = os.path.join(os.path.dirname(__file__), "data")
142-
dummy_turbine = {
143-
"turbine_type": "DUMMY 1",
144-
"hub_height": 100, # in m
145-
"rotor_diameter": 70, # in m
146-
"path": csv_path,
147-
}
148-
# initialize WindTurbine object
149-
dummy_turbine = WindTurbine(**dummy_turbine)
150-
151-
return my_turbine, e126, dummy_turbine
140+
return my_turbine, e126
152141

153142

154-
def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
143+
def calculate_power_output(weather, my_turbine, e126):
155144
r"""
156145
Calculates power output of wind turbines using the
157146
:class:`~.modelchain.ModelChain`.
@@ -172,8 +161,6 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
172161
e126 : :class:`~.wind_turbine.WindTurbine`
173162
WindTurbine object with power curve from the OpenEnergy Database
174163
turbine library.
175-
dummy_turbine : :class:`~.wind_turbine.WindTurbine`
176-
WindTurbine object with power coefficient curve from example file.
177164
178165
"""
179166

@@ -209,14 +196,14 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
209196
# power output calculation for example_turbine
210197
# own specification for 'power_output_model'
211198
mc_example_turbine = ModelChain(
212-
dummy_turbine, power_output_model="power_coefficient_curve"
199+
my_turbine, power_output_model="power_coefficient_curve"
213200
).run_model(weather)
214-
dummy_turbine.power_output = mc_example_turbine.power_output
201+
my_turbine.power_output = mc_example_turbine.power_output
215202

216203
return
217204

218205

219-
def plot_or_print(my_turbine, e126, dummy_turbine):
206+
def plot_or_print(my_turbine, e126):
220207
r"""
221208
Plots or prints power output and power (coefficient) curves.
222209
@@ -227,23 +214,18 @@ def plot_or_print(my_turbine, e126, dummy_turbine):
227214
e126 : :class:`~.wind_turbine.WindTurbine`
228215
WindTurbine object with power curve from the OpenEnergy Database
229216
turbine library.
230-
dummy_turbine : :class:`~.wind_turbine.WindTurbine`
231-
WindTurbine object with power coefficient curve from example file.
232-
233217
"""
234218

235219
# plot or print turbine power output
236220
if plt:
237221
e126.power_output.plot(legend=True, label='Enercon E126')
238222
my_turbine.power_output.plot(legend=True, label='myTurbine')
239-
dummy_turbine.power_output.plot(legend=True, label='dummyTurbine')
240223
plt.xlabel('Time')
241224
plt.ylabel('Power in W')
242225
plt.show()
243226
else:
244227
print(e126.power_output)
245228
print(my_turbine.power_output)
246-
print(dummy_turbine.power_output)
247229

248230
# plot or print power curve
249231
if plt:
@@ -259,13 +241,6 @@ def plot_or_print(my_turbine, e126, dummy_turbine):
259241
plt.xlabel('Wind speed in m/s')
260242
plt.ylabel('Power in W')
261243
plt.show()
262-
if dummy_turbine.power_coefficient_curve is not False:
263-
dummy_turbine.power_coefficient_curve.plot(
264-
x='wind_speed', y='value', style='*',
265-
title='dummyTurbine power coefficient curve')
266-
plt.xlabel('Wind speed in m/s')
267-
plt.ylabel('Power coefficient')
268-
plt.show()
269244
else:
270245
if e126.power_coefficient_curve is not False:
271246
print(e126.power_coefficient_curve)
@@ -278,10 +253,16 @@ def run_example():
278253
Runs the basic example.
279254
280255
"""
256+
# You can use the logging package to get logging messages from the
257+
# windpowerlib. Change the logging level if you want more or less messages:
258+
# logging.DEBUG -> many messages
259+
# logging.INFO -> few messages
260+
logging.getLogger().setLevel(logging.DEBUG)
261+
281262
weather = get_weather_data("weather.csv")
282-
my_turbine, e126, dummy_turbine = initialize_wind_turbines()
283-
calculate_power_output(weather, my_turbine, e126, dummy_turbine)
284-
plot_or_print(my_turbine, e126, dummy_turbine)
263+
my_turbine, e126 = initialize_wind_turbines()
264+
calculate_power_output(weather, my_turbine, e126)
265+
plot_or_print(my_turbine, e126)
285266

286267

287268
if __name__ == "__main__":

example/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class TestExamples:
1818
def test_modelchain_example_flh(self):
1919
# tests full load hours
2020
weather = mc_e.get_weather_data("weather.csv")
21-
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
22-
mc_e.calculate_power_output(weather, my_turbine, e126, dummy_turbine)
21+
my_turbine, e126 = mc_e.initialize_wind_turbines()
22+
mc_e.calculate_power_output(weather, my_turbine, e126)
2323

2424
assert_allclose(
2525
2764.194772, (e126.power_output.sum() / e126.nominal_power), 0.01

example/turbine_cluster_modelchain_example.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@
1111
SPDX-License-Identifier: MIT
1212
"""
1313
import pandas as pd
14-
15-
try:
16-
from matplotlib import pyplot as plt
17-
except ImportError:
18-
plt = None
19-
14+
import logging
2015
from example import modelchain_example as mc_e
2116
from windpowerlib import WindFarm
2217
from windpowerlib import WindTurbineCluster
2318
from windpowerlib import TurbineClusterModelChain
24-
25-
# You can use the logging package to get logging messages from the windpowerlib
26-
# Change the logging level if you want more or less messages
27-
import logging
28-
logging.getLogger().setLevel(logging.DEBUG)
19+
try:
20+
from matplotlib import pyplot as plt
21+
except ImportError:
22+
plt = None
2923

3024

3125
def initialize_wind_farms(my_turbine, e126):
@@ -151,7 +145,8 @@ class that provides all necessary steps to calculate the power output of a
151145
# power output calculation for turbine_cluster
152146
# own specifications for TurbineClusterModelChain setup
153147
modelchain_data = {
154-
"wake_losses_model": "wind_farm_efficiency", # 'dena_mean' (default), None,
148+
"wake_losses_model": "wind_farm_efficiency",
149+
# 'dena_mean' (default), None,
155150
# 'wind_farm_efficiency' or name
156151
# of another wind efficiency curve
157152
# see :py:func:`~.wake_losses.get_wind_efficiency_curve`
@@ -217,8 +212,14 @@ def run_example():
217212
Runs the example.
218213
219214
"""
215+
# You can use the logging package to get logging messages from the
216+
# windpowerlib. Change the logging level if you want more or less messages:
217+
# logging.DEBUG -> many messages
218+
# logging.INFO -> few messages
219+
logging.getLogger().setLevel(logging.DEBUG)
220+
220221
weather = mc_e.get_weather_data("weather.csv")
221-
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
222+
my_turbine, e126 = mc_e.initialize_wind_turbines()
222223
example_farm, example_farm_2 = initialize_wind_farms(my_turbine, e126)
223224
example_cluster = initialize_wind_turbine_cluster(
224225
example_farm, example_farm_2

0 commit comments

Comments
 (0)