Skip to content

Commit ca2f427

Browse files
committed
Add comments to make example cleaner
1 parent 33a1730 commit ca2f427

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

example/modelchain_example.py

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
you need to specify your wind turbine, and in the last step call the
1111
windpowerlib functions to calculate the feed-in time series.
1212
13+
Install the windpowerlib and optionally matplotlib to see the plots:
14+
15+
pip install windpowerlib
16+
pip install matplotlib
17+
18+
Go down to the "run_example()" function to start the example.
19+
1320
SPDX-FileCopyrightText: 2019 oemof developer group <[email protected]>
1421
SPDX-License-Identifier: MIT
1522
"""
1623
import os
1724
import pandas as pd
1825
import requests
26+
import logging
27+
from windpowerlib import ModelChain, WindTurbine
1928

2029
try:
2130
from matplotlib import pyplot as plt
2231
except ImportError:
2332
plt = None
2433

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

3435
def get_weather_data(filename='weather.csv', **kwargs):
3536
r"""
@@ -114,18 +115,18 @@ def initialize_wind_turbines():
114115
:class:`~.wind_turbine.WindTurbine`)
115116
116117
"""
118+
# ************************************************************************
119+
# **** Data is provided in the oedb turbine library **********************
117120

118-
# specification of wind turbine where data is provided in the oedb
119-
# turbine library
120121
enercon_e126 = {
121122
"turbine_type": "E-126/4200", # turbine type as in register
122123
"hub_height": 135, # in m
123124
}
124-
# initialize WindTurbine object
125125
e126 = WindTurbine(**enercon_e126)
126126

127-
# specification of own wind turbine (Note: power values and nominal power
128-
# have to be in Watt)
127+
# ************************************************************************
128+
# **** Specification of wind turbine with your own data ******************
129+
# **** NOTE: power values and nominal power have to be in Watt
129130
my_turbine = {
130131
"nominal_power": 3e6, # in W
131132
"hub_height": 105, # in m
@@ -139,19 +140,17 @@ def initialize_wind_turbines():
139140
}
140141
), # in m/s
141142
}
142-
# initialize WindTurbine object
143143
my_turbine = WindTurbine(**my_turbine)
144144

145-
# specification of wind turbine where power coefficient curve and nominal
146-
# power is provided in an own csv file
145+
# ************************************************************************
146+
# **** Specification of wind turbine with data in own file ***************
147147
csv_path = os.path.join(os.path.dirname(__file__), "data")
148148
dummy_turbine = {
149149
"turbine_type": "DUMMY 1",
150150
"hub_height": 100, # in m
151151
"rotor_diameter": 70, # in m
152152
"path": csv_path,
153153
}
154-
# initialize WindTurbine object
155154
dummy_turbine = WindTurbine(**dummy_turbine)
156155

157156
return my_turbine, e126, dummy_turbine
@@ -183,15 +182,9 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
183182
184183
"""
185184

186-
# power output calculation for my_turbine
187-
# initialize ModelChain with default parameters and use run_model method
188-
# to calculate power output
189-
mc_my_turbine = ModelChain(my_turbine).run_model(weather)
190-
# write power output time series to WindTurbine object
191-
my_turbine.power_output = mc_my_turbine.power_output
192-
193-
# power output calculation for e126
194-
# own specifications for ModelChain setup
185+
# ************************************************************************
186+
# **** Data is provided in the oedb turbine library **********************
187+
# **** ModelChain with non-default specifications
195188
modelchain_data = {
196189
"wind_speed_model": "logarithmic", # 'logarithmic' (default),
197190
# 'hellman' or
@@ -212,8 +205,16 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
212205
# write power output time series to WindTurbine object
213206
e126.power_output = mc_e126.power_output
214207

215-
# power output calculation for example_turbine
216-
# own specification for 'power_output_model'
208+
# ************************************************************************
209+
# **** Specification of wind turbine with your own data ******************
210+
# **** ModelChain with default parameter
211+
mc_my_turbine = ModelChain(my_turbine).run_model(weather)
212+
# write power output time series to WindTurbine object
213+
my_turbine.power_output = mc_my_turbine.power_output
214+
215+
# ************************************************************************
216+
# **** Specification of wind turbine with data in own file ***************
217+
# **** Using "power_coefficient_curve" as "power_output_model".
217218
mc_example_turbine = ModelChain(
218219
dummy_turbine, power_output_model="power_coefficient_curve"
219220
).run_model(weather)
@@ -284,10 +285,16 @@ def run_example():
284285
Runs the basic example.
285286
286287
"""
288+
# You can use the logging package to get logging messages from the
289+
# windpowerlib. Change the logging level if you want more or less messages:
290+
# logging.DEBUG -> many messages
291+
# logging.INFO -> few messages
292+
logging.getLogger().setLevel(logging.DEBUG)
293+
287294
weather = get_weather_data("weather.csv")
288-
my_turbine, e126, dummy_turbine = initialize_wind_turbines()
289-
calculate_power_output(weather, my_turbine, e126, dummy_turbine)
290-
plot_or_print(my_turbine, e126, dummy_turbine)
295+
my_turbine, e126 = initialize_wind_turbines()
296+
calculate_power_output(weather, my_turbine, e126)
297+
plot_or_print(my_turbine, e126)
291298

292299

293300
if __name__ == "__main__":

0 commit comments

Comments
 (0)