Skip to content

Commit f791288

Browse files
committed
Add example showing the usage of WindFarms and WindTurbineClusters
1 parent eaa1731 commit f791288

File tree

1 file changed

+220
-0
lines changed

1 file changed

+220
-0
lines changed

example/further_example.py

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
"""
2+
The ``further_example`` module shows a further usage of the windpowerlib.
3+
4+
In this example uses functions from the ``basic_example`` module where the
5+
basic usage of the windpowerlib is shown.
6+
7+
8+
"""
9+
10+
__copyright__ = "Copyright oemof developer group"
11+
__license__ = "GPLv3"
12+
13+
try:
14+
from matplotlib import pyplot as plt
15+
except ImportError:
16+
plt = None
17+
18+
import basic_example
19+
from windpowerlib.turbine_cluster_modelchain import TurbineClusterModelChain
20+
from windpowerlib.wind_turbine_cluster import WindTurbineCluster
21+
from windpowerlib.wind_farm import WindFarm
22+
# TODO: change imports
23+
24+
# You can use the logging package to get logging messages from the windpowerlib
25+
# Change the logging level if you want more or less messages
26+
import logging
27+
logging.getLogger().setLevel(logging.DEBUG)
28+
29+
30+
def initialise_wind_farm(my_turbine, e126):
31+
r"""
32+
Initialises a :class:`~.wind_farm.WindFarm` object.
33+
34+
This function shows how to initialise a WindFarm object. You need to
35+
provide at least a name and a the wind farm's wind turbine fleet as done
36+
below for 'example_farm'. Optionally you can provide a wind farm efficiency
37+
(which can be constant or dependent on the wind speed) and coordinates as
38+
done for 'example_farm_2'. In this example the coordinates are not being
39+
used as just a single weather data set is provided as example data.
40+
41+
Parameters
42+
----------
43+
my_turbine : WindTurbine
44+
WindTurbine object with self provided power curve.
45+
e126 : WindTurbine
46+
WindTurbine object with power curve from data file provided by the
47+
windpowerlib.
48+
49+
Returns
50+
-------
51+
Tuple (WindFarm, WindFarm)
52+
53+
"""
54+
55+
# specification of wind farm data
56+
example_farm_data = {
57+
'name': 'example_farm',
58+
'wind_turbine_fleet': [{'wind_turbine': my_turbine,
59+
'number_of_turbines': 6},
60+
{'wind_turbine': e126,
61+
'number_of_turbines': 3}
62+
]}
63+
64+
# initialise WindFarm object
65+
example_farm = WindFarm(**example_farm_data)
66+
67+
# specification of wind farm data (2) containing a wind farm efficiency
68+
# and coordinates
69+
example_farm_2_data = {
70+
'name': 'example_farm_2',
71+
'wind_turbine_fleet': [{'wind_turbine': my_turbine,
72+
'number_of_turbines': 6},
73+
{'wind_turbine': e126,
74+
'number_of_turbines': 3}],
75+
'efficiency': 0.9,
76+
'coordinates': [52.2, 13.1]}
77+
78+
# initialise WindFarm object
79+
example_farm_2 = WindFarm(**example_farm_2_data)
80+
81+
return example_farm, example_farm_2
82+
83+
84+
def initialise_wind_turbine_cluster(example_farm, example_farm_2):
85+
r"""
86+
Initialises a :class:`~.wind_turbine_cluster.WindTurbineCluster` object.
87+
88+
Function shows how to initialise a WindTurbineCluster object. In this case
89+
the cluster only contains two wind farms.
90+
91+
Parameters
92+
----------
93+
example_farm : WindFarm
94+
WindFarm object.
95+
example_farm_2 : WindFarm
96+
WindFarm object constant wind farm efficiency and coordinates.
97+
98+
Returns
99+
-------
100+
WindTurbineCluster
101+
102+
"""
103+
104+
# specification of cluster data
105+
example_cluster_data = {
106+
'name': 'example_cluster',
107+
'wind_farms': [example_farm, example_farm_2]}
108+
109+
# initialise WindTurbineCluster object
110+
example_cluster = WindTurbineCluster(**example_cluster_data)
111+
112+
return example_cluster
113+
114+
115+
def calculate_power_output(weather, example_farm, example_cluster):
116+
r"""
117+
Calculates power output of wind farms and clusters using the
118+
:class:`~.turbine_cluster_modelchain.TurbineClusterModelChain`.
119+
120+
The :class:`~.turbine_cluster_modelchain.TurbineClusterModelChain` is a
121+
class that provides all necessary steps to calculate the power output of a
122+
wind farm or cluster. You can either use the default methods for the
123+
calculation steps, as done for 'example_farm', or choose different methods,
124+
as done for 'example_cluster'.
125+
126+
Parameters
127+
----------
128+
weather : pd.DataFrame
129+
Contains weather data time series.
130+
example_farm : WindFarm
131+
WindFarm object.
132+
example_farm_2 : WindFarm
133+
WindFarm object constant wind farm efficiency and coordinates.
134+
135+
"""
136+
137+
# power output calculation for example_farm
138+
# initialise TurbineClusterModelChain with default parameters and use
139+
# run_model method to calculate power output
140+
mc_example_farm = TurbineClusterModelChain(example_farm).run_model(weather)
141+
# write power output time series to WindFarm object
142+
example_farm.power_output = mc_example_farm.power_output
143+
144+
# power output calculation for turbine_cluster
145+
# own specifications for TurbineClusterModelChain setup
146+
modelchain_data = {
147+
'wake_losses_model': 'dena_mean', # 'dena_mean' (default), None,
148+
# 'power_efficiency_curve',
149+
# 'constant_efficiency' or name of
150+
# a wind efficiency curve
151+
# see :py:func:`~.wake_losses.display_wind_efficiency_curves`
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
172+
# initialise TurbineClusterModelChain with own specifications and use
173+
# run_model method to calculate power output
174+
mc_example_cluster = TurbineClusterModelChain(
175+
example_cluster, **modelchain_data).run_model(weather)
176+
# write power output time series to WindTurbineCluster object
177+
example_cluster.power_output = mc_example_cluster.power_output
178+
179+
return
180+
181+
182+
def plot_or_print(example_farm, example_cluster):
183+
r"""
184+
Plots or prints power output and power (coefficient) curves.
185+
186+
Parameters
187+
----------
188+
example_farm : WindFarm
189+
WindFarm object.
190+
example_farm_2 : WindFarm
191+
WindFarm object constant wind farm efficiency and coordinates.
192+
193+
"""
194+
195+
# plot or print power output
196+
if plt:
197+
example_cluster.power_output.plot(legend=True, label='example cluster')
198+
example_farm.power_output.plot(legend=True, label='example farm')
199+
plt.show()
200+
else:
201+
print(example_cluster.power_output)
202+
print(example_farm.power_output)
203+
204+
205+
def run_example():
206+
r"""
207+
Run the example.
208+
209+
"""
210+
weather = basic_example.get_weather_data('weather.csv')
211+
my_turbine, e126 = basic_example.initialise_wind_turbines()
212+
example_farm, example_farm_2 = initialise_wind_farm(my_turbine, e126)
213+
example_cluster = initialise_wind_turbine_cluster(example_farm,
214+
example_farm_2)
215+
calculate_power_output(weather, example_farm, example_cluster)
216+
plot_or_print(example_farm, example_cluster)
217+
218+
219+
if __name__ == "__main__":
220+
run_example()

0 commit comments

Comments
 (0)