Skip to content

Commit 6b9983d

Browse files
committed
Merge branch 'release_preparation' into dev
2 parents 0b58c97 + be021d9 commit 6b9983d

15 files changed

+1314
-44
lines changed

README.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ Examples and basic usage
4747

4848
The basic usage of the windpowerlib is shown `here <http://windpowerlib.readthedocs.io/en/stable/basic_example_notebook.html>`_. The presented example is available as jupyter notebook and python script. You can download them along with example weather data:
4949

50-
* `Python script <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/basic_example.py>`_
51-
* `Jupyter notebook <https://raw.githubusercontent.com/wind-python/windpowerlib/features/revise_example/example/basic_example.ipynb>`_
50+
* `Basic example (Python script) <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/basic_example.py>`_
51+
* `Basic example (Jupyter notebook) <https://raw.githubusercontent.com/wind-python/windpowerlib/features/revise_example/example/basic_example.ipynb>`_
5252
* `Example data file <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/weather.csv>`_
5353

5454

5555
To run the examples you first have to install the windpowerlib. To run the notebook you also need to install notebook using pip3. To launch jupyter notebook type ``jupyter notebook`` in terminal.
5656
This will open a browser window. Navigate to the directory containing the notebook to open it. See the jupyter notebook quick start guide for more information on `how to install <http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/install.html>`_ and
5757
`how to run <http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html>`_ jupyter notebooks.
5858

59+
The usage of further functions are shown in a second example. As the basic usage example it is available as jupyter notebook and as python script. The weather data in this example is the same as in the example above.
60+
61+
* `Further example (Python script) <https://raw.githubusercontent.com/wind-python/windpowerlib/release_preparation/example/further_example.py>`_
62+
* `Further example (Jupyter notebook) <https://raw.githubusercontent.com/wind-python/windpowerlib/release_preparation/example/basic_example.ipynb>`_
63+
* `Example data file <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/weather.csv>`_
64+
5965

6066
Contributing
6167
==============

doc/examples_basic_and_further.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#############
2+
Examples
3+
#############
4+
5+
6+
.. toctree::
7+
8+
basic_example_notebook
9+
further_example_notebook

doc/further_example_notebook.ipynb

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.

doc/getting_started.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,19 @@ Examples and basic usage
4646

4747
The basic usage of the windpowerlib is shown :ref:`here <basic_example_notebook.ipynb>`. The presented example is available as jupyter notebook and python script. You can download them along with example weather data:
4848

49-
* :download:`Python script <../example/basic_example.py>`
50-
* :download:`Jupyter notebook <../example/basic_example.ipynb>`
49+
* :download:`Basic example (Python script) <../example/basic_example.py>`
50+
* :download:`Basic example (Jupyter notebook) <../example/basic_example.ipynb>`
5151
* :download:`Example data file <../example/weather.csv>`
5252

5353
To run the examples you first have to install the windpowerlib. To run the notebook you also need to install notebook using pip3. To launch jupyter notebook type ``jupyter notebook`` in terminal.
5454
This will open a browser window. Navigate to the directory containing the notebook to open it. See the jupyter notebook quick start guide for more information on `how to install <http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/install.html>`_ and
5555
`how to run <http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html>`_ jupyter notebooks.
5656

57+
Further functionalities are shown in a second example. As the basic usage example it is available as jupyter notebook and as python script. The weather data in this example is the same as in the example above.
58+
59+
* :download:`Further example (Python script) <../example/further_example.py>`
60+
* :download:`Further example (Jupyter notebook) <../example/further_example.ipynb>`
61+
* :download:`Example data file <../example/weather.csv>`
5762

5863
Contributing
5964
==============

doc/index.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ Contents:
88
:glob:
99

1010
getting_started
11-
basic_example_notebook
11+
12+
.. toctree::
13+
:maxdepth: 3
14+
:glob:
15+
16+
examples_basic_and_further
17+
18+
.. toctree::
19+
:maxdepth: 2
20+
:glob:
21+
1222
whats_new
1323
modules
1424

example/basic_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def calculate_power_output(weather, my_turbine, e126):
171171
# initialise ModelChain with own specifications and use run_model method
172172
# to calculate power output
173173
mc_e126 = ModelChain(e126, **modelchain_data).run_model(weather)
174-
# write power output timeseries to WindTurbine object
174+
# write power output time series to WindTurbine object
175175
e126.power_output = mc_e126.power_output
176176

177177
return

example/further_example.ipynb

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.

example/further_example.py

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
"""
2+
The ``further_example`` module shows a further usage of the windpowerlib.
3+
4+
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+
# set efficiency of example_farm to apply wake losses
138+
example_farm.efficiency = 0.9
139+
# power output calculation for example_farm
140+
# initialise TurbineClusterModelChain with default parameters and use
141+
# run_model method to calculate power output
142+
mc_example_farm = TurbineClusterModelChain(example_farm).run_model(weather)
143+
# write power output time series to WindFarm object
144+
example_farm.power_output = mc_example_farm.power_output
145+
146+
# power output calculation for turbine_cluster
147+
# own specifications for TurbineClusterModelChain setup
148+
modelchain_data = {
149+
'wake_losses_model': 'constant_efficiency', #
150+
# 'dena_mean' (default), None,
151+
# 'power_efficiency_curve',
152+
# 'constant_efficiency' or name of
153+
# a wind efficiency curve
154+
# see :py:func:`~.wake_losses.display_wind_efficiency_curves`
155+
'smoothing': True, # False (default) or True
156+
'block_width': 0.5, # default: 0.5
157+
'standard_deviation_method': 'Staffell_Pfenninger', #
158+
# 'turbulence_intensity' (default)
159+
# or 'Staffell_Pfenninger'
160+
'smoothing_order': 'wind_farm_power_curves', #
161+
# 'wind_farm_power_curves' (default) or
162+
# 'turbine_power_curves'
163+
'wind_speed_model': 'logarithmic', # 'logarithmic' (default),
164+
# 'hellman' or
165+
# 'interpolation_extrapolation'
166+
'density_model': 'ideal_gas', # 'barometric' (default), 'ideal_gas' or
167+
# 'interpolation_extrapolation'
168+
'temperature_model': 'linear_gradient', # 'linear_gradient' (def.) or
169+
# 'interpolation_extrapolation'
170+
'power_output_model': 'power_curve', # 'power_curve' (default) or
171+
# 'power_coefficient_curve'
172+
'density_correction': True, # False (default) or True
173+
'obstacle_height': 0, # default: 0
174+
'hellman_exp': None} # None (default) or None
175+
# initialise TurbineClusterModelChain with own specifications and use
176+
# run_model method to calculate power output
177+
mc_example_cluster = TurbineClusterModelChain(
178+
example_cluster, **modelchain_data).run_model(weather)
179+
# write power output time series to WindTurbineCluster object
180+
example_cluster.power_output = mc_example_cluster.power_output
181+
182+
return
183+
184+
185+
def plot_or_print(example_farm, example_cluster):
186+
r"""
187+
Plots or prints power output and power (coefficient) curves.
188+
189+
Parameters
190+
----------
191+
example_farm : WindFarm
192+
WindFarm object.
193+
example_farm_2 : WindFarm
194+
WindFarm object constant wind farm efficiency and coordinates.
195+
196+
"""
197+
198+
# plot or print power output
199+
if plt:
200+
example_cluster.power_output.plot(legend=True, label='example cluster')
201+
example_farm.power_output.plot(legend=True, label='example farm')
202+
plt.show()
203+
else:
204+
print(example_cluster.power_output)
205+
print(example_farm.power_output)
206+
207+
208+
def run_example():
209+
r"""
210+
Run the example.
211+
212+
"""
213+
weather = basic_example.get_weather_data('weather.csv')
214+
my_turbine, e126 = basic_example.initialise_wind_turbines()
215+
example_farm, example_farm_2 = initialise_wind_farm(my_turbine, e126)
216+
example_cluster = initialise_wind_turbine_cluster(example_farm,
217+
example_farm_2)
218+
calculate_power_output(weather, example_farm, example_cluster)
219+
plot_or_print(example_farm, example_cluster)
220+
221+
222+
if __name__ == "__main__":
223+
run_example()

0 commit comments

Comments
 (0)