-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathturbine_cluster_modelchain_example.py
More file actions
232 lines (192 loc) · 8.29 KB
/
turbine_cluster_modelchain_example.py
File metadata and controls
232 lines (192 loc) · 8.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
"""
The ``turbine_cluster_modelchain_example`` module shows how to calculate the
power output of wind farms and wind turbine clusters with the windpowerlib.
A cluster can be useful if you want to calculate the feed-in of a region for
which you want to use one single weather data point.
Functions that are used in the ``modelchain_example``, like the initialization
of wind turbines, are imported and used without further explanations.
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""
import pandas as pd
try:
from matplotlib import pyplot as plt
except ImportError:
plt = None
from example import modelchain_example as mc_e
from windpowerlib import WindFarm
from windpowerlib import WindTurbineCluster
from windpowerlib import TurbineClusterModelChain
# You can use the logging package to get logging messages from the windpowerlib
# Change the logging level if you want more or less messages
import logging
logging.getLogger().setLevel(logging.DEBUG)
def initialize_wind_farms(my_turbine, e126):
r"""
Initializes two :class:`~.wind_farm.WindFarm` objects.
This function shows how to initialize a WindFarm object. A WindFarm needs
a wind turbine fleet specifying the wind turbines and their number or
total installed capacity (in Watt) in the farm. Optionally, you can provide
a wind farm efficiency (which can be constant or dependent on the wind
speed) and a name as an identifier. See :class:`~.wind_farm.WindFarm` for
more information.
Parameters
----------
my_turbine : :class:`~.wind_turbine.WindTurbine`
WindTurbine object with self provided power curve.
e126 : :class:`~.wind_turbine.WindTurbine`
WindTurbine object with power curve from the OpenEnergy Database
turbine library.
Returns
-------
tuple(:class:`~.wind_farm.WindFarm`, :class:`~.wind_farm.WindFarm`)
"""
# specification of wind farm data where turbine fleet is provided in a
# pandas.DataFrame
# for each turbine type you can either specify the number of turbines of
# that type in the wind farm (float values are possible as well) or the
# total installed capacity of that turbine type in W
wind_turbine_fleet = pd.DataFrame(
{
"wind_turbine": [my_turbine, e126], # as windpowerlib.WindTurbine
"number_of_turbines": [6, None],
"total_capacity": [None, 12.6e6],
}
)
# initialize WindFarm object
example_farm = WindFarm(
name="example_farm", wind_turbine_fleet=wind_turbine_fleet
)
# specification of wind farm data (2) containing a wind farm efficiency
# wind turbine fleet is provided using the to_group function
example_farm_2_data = {
"name": "example_farm_2",
"wind_turbine_fleet": [
my_turbine.to_group(6),
e126.to_group(total_capacity=12.6e6),
],
"efficiency": 0.9,
}
# initialize WindFarm object
example_farm_2 = WindFarm(**example_farm_2_data)
return example_farm, example_farm_2
def initialize_wind_turbine_cluster(example_farm, example_farm_2):
r"""
Initializes a :class:`~.wind_turbine_cluster.WindTurbineCluster` object.
Function shows how to initialize a WindTurbineCluster object. A
WindTurbineCluster consists of wind farms that are specified through the
`wind_farms` parameter. Optionally, you can provide a name as an
identifier.
Parameters
----------
example_farm : :class:`~.wind_farm.WindFarm`
WindFarm object without provided efficiency.
example_farm_2 : :class:`~.wind_farm.WindFarm`
WindFarm object with constant wind farm efficiency.
Returns
-------
:class:`~.wind_turbine_cluster.WindTurbineCluster`
"""
# specification of cluster data
example_cluster_data = {
"name": "example_cluster",
"wind_farms": [example_farm, example_farm_2],
}
# initialize WindTurbineCluster object
example_cluster = WindTurbineCluster(**example_cluster_data)
return example_cluster
def calculate_power_output(weather, example_farm, example_cluster):
r"""
Calculates power output of wind farms and clusters using the
:class:`~.turbine_cluster_modelchain.TurbineClusterModelChain`.
The :class:`~.turbine_cluster_modelchain.TurbineClusterModelChain` is a
class that provides all necessary steps to calculate the power output of a
wind farm or cluster. You can either use the default methods for the
calculation steps, as done for 'example_farm', or choose different methods,
as done for 'example_cluster'.
Parameters
----------
weather : :pandas:`pandas.DataFrame<frame>`
Contains weather data time series.
example_farm : :class:`~.wind_farm.WindFarm`
WindFarm object without provided efficiency.
example_cluster : :class:`~.wind_turbine_cluster.WindTurbineCluster`
WindTurbineCluster object.
"""
example_farm.efficiency = 0.9
# power output calculation for example_farm
# initialize TurbineClusterModelChain with default parameters and use
# run_model method to calculate power output
mc_example_farm = TurbineClusterModelChain(example_farm).run_model(weather)
# write power output time series to WindFarm object
example_farm.power_output = mc_example_farm.power_output
# power output calculation for turbine_cluster
# own specifications for TurbineClusterModelChain setup
modelchain_data = {
"wake_losses_model": "wind_farm_efficiency", # 'dena_mean' (default), None,
# 'wind_farm_efficiency' or name
# of another wind efficiency curve
# see :py:func:`~.wake_losses.get_wind_efficiency_curve`
"smoothing": True, # False (default) or True
"block_width": 0.5, # default: 0.5
"standard_deviation_method": "Staffell_Pfenninger", #
# 'turbulence_intensity' (default)
# or 'Staffell_Pfenninger'
"smoothing_order": "wind_farm_power_curves", #
# 'wind_farm_power_curves' (default) or
# 'turbine_power_curves'
"wind_speed_model": "logarithmic", # 'logarithmic' (default),
# 'hellman' or
# 'interpolation_extrapolation'
"density_model": "ideal_gas", # 'barometric' (default), 'ideal_gas' or
# 'interpolation_extrapolation'
"temperature_model": "linear_gradient", # 'linear_gradient' (def.) or
# 'interpolation_extrapolation'
"power_output_model": "power_curve", # 'power_curve' (default) or
# 'power_coefficient_curve'
"density_correction": True, # False (default) or True
"obstacle_height": 0, # default: 0
"hellman_exp": None,
} # None (default) or None
# initialize TurbineClusterModelChain with own specifications and use
# run_model method to calculate power output
mc_example_cluster = TurbineClusterModelChain(
example_cluster, **modelchain_data
).run_model(weather)
# write power output time series to WindTurbineCluster object
example_cluster.power_output = mc_example_cluster.power_output
return
def plot_or_print(example_farm, example_cluster):
r"""
Plots or prints power output and power (coefficient) curves.
Parameters
----------
example_farm : :class:`~.wind_farm.WindFarm`
WindFarm object without provided efficiency.
example_cluster : :class:`~.wind_turbine_cluster.WindTurbineCluster`
WindTurbineCluster object.
"""
# plot or print power output
if plt:
example_cluster.power_output.plot(legend=True, label="example cluster")
example_farm.power_output.plot(legend=True, label="example farm")
plt.xlabel("Wind speed in m/s")
plt.ylabel("Power in W")
plt.show()
else:
print(example_cluster.power_output)
print(example_farm.power_output)
def run_example():
r"""
Runs the example.
"""
weather = mc_e.get_weather_data("weather.csv")
my_turbine, e126, my_turbine2 = mc_e.initialize_wind_turbines()
example_farm, example_farm_2 = initialize_wind_farms(my_turbine, e126)
example_cluster = initialize_wind_turbine_cluster(
example_farm, example_farm_2
)
calculate_power_output(weather, example_farm, example_cluster)
plot_or_print(example_farm, example_cluster)
if __name__ == "__main__":
run_example()