Skip to content

Commit 9176f9d

Browse files
birgitsstickler-ci
andauthored
Fixes/#73 revise notebooks (#103)
* Revise notebooks * Minor changes in example python files * Delete example files for turbine data * Adapt README * Fixing style errors. * Fix test due to changed modelchain input Co-authored-by: stickler-ci <[email protected]>
1 parent 3ef8b2b commit 9176f9d

9 files changed

+167
-187
lines changed

README.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,15 @@ The basic usage of the windpowerlib is shown in the `ModelChain example <http://
6464
* `ModelChain example (Python script) <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/modelchain_example.py>`_
6565
* `ModelChain example (Jupyter notebook) <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/modelchain_example.ipynb>`_
6666

67-
To run the example you need the example weather and turbine data used:
67+
To run the example you need example weather that is downloaded automatically and can also be downloaded here:
6868

6969
* `Example weather data file <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/weather.csv>`_
70-
* `Example power curve data file <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/data/example_power_curves.csv>`_
71-
* `Example power coefficient curve data file <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/data/example_power_coefficient_curves.csv>`_
72-
* `Example nominal power data file <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/data/example_turbine_data.csv>`_
7370

74-
To run the examples locally you have to install windpowerlib. To run the notebook you also need to install `notebook` using pip3. To launch jupyter notebook type ``jupyter notebook`` in the terminal.
71+
To run the examples locally you 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 the terminal.
7572
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
7673
`how to run <http://jupyter-notebook-beginner-guide.readthedocs.io/en/latest/execute.html>`_ jupyter notebooks. In order to reproduce the figures in a notebook you need to install `matplotlib`.
7774

78-
Further functionalities, like the modelling of wind farms and wind turbine clusters, are shown in the `TurbineClusterModelChain example <http://windpowerlib.readthedocs.io/en/stable/turbine_cluster_modelchain_example_notebook.html>`_. As the ModelChain example it is available as jupyter notebook and as python script. The weather and turbine datadata used in this example is the same as in the example above.
75+
Further functionalities, like the modelling of wind farms and wind turbine clusters, are shown in the `TurbineClusterModelChain example <http://windpowerlib.readthedocs.io/en/stable/turbine_cluster_modelchain_example_notebook.html>`_. As the ModelChain example it is available as jupyter notebook and as python script. The weather used in this example is the same as in the ModelChain example.
7976

8077
* `TurbineClusterModelChain example (Python script) <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/turbine_cluster_modelchain_example.py>`_
8178
* `TurbineClusterModelChain example (Jupyter notebook) <https://raw.githubusercontent.com/wind-python/windpowerlib/master/example/turbine_cluster_modelchain_example.ipynb>`_

example/modelchain_example.ipynb

Lines changed: 134 additions & 127 deletions
Large diffs are not rendered by default.

example/modelchain_example.py

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ def get_weather_data(filename="weather.csv", **kwargs):
3838
3939
The data include wind speed at two different heights in m/s, air
4040
temperature in two different heights in K, surface roughness length in m
41-
and air pressure in Pa. The file is located in the example folder of the
42-
windpowerlib. The height in m for which the data applies is specified in
43-
the second row.
41+
and air pressure in Pa. The height in m for which the data applies is
42+
specified in the second row.
43+
In case no weather data file exists, an example weather data file is
44+
automatically downloaded and stored in the same directory as this example.
4445
4546
Parameters
4647
----------
@@ -51,18 +52,19 @@ def get_weather_data(filename="weather.csv", **kwargs):
5152
----------------
5253
datapath : str, optional
5354
Path where the weather data file is stored.
54-
Default: 'windpowerlib/example'.
55+
Default is the same directory this example is stored in.
5556
5657
Returns
5758
-------
5859
:pandas:`pandas.DataFrame<frame>`
59-
DataFrame with time series for wind speed `wind_speed` in m/s,
60-
temperature `temperature` in K, roughness length `roughness_length`
61-
in m, and pressure `pressure` in Pa.
62-
The columns of the DataFrame are a MultiIndex where the first level
63-
contains the variable name as string (e.g. 'wind_speed') and the
64-
second level contains the height as integer at which it applies
65-
(e.g. 10, if it was measured at a height of 10 m).
60+
DataFrame with time series for wind speed `wind_speed` in m/s,
61+
temperature `temperature` in K, roughness length `roughness_length`
62+
in m, and pressure `pressure` in Pa.
63+
The columns of the DataFrame are a MultiIndex where the first level
64+
contains the variable name as string (e.g. 'wind_speed') and the
65+
second level contains the height as integer at which it applies
66+
(e.g. 10, if it was measured at a height of 10 m). The index is a
67+
DateTimeIndex.
6668
6769
"""
6870

@@ -71,6 +73,7 @@ def get_weather_data(filename="weather.csv", **kwargs):
7173

7274
file = os.path.join(kwargs["datapath"], filename)
7375

76+
# download example weather data file in case it does not yet exist
7477
if not os.path.isfile(file):
7578
logging.debug("Download weather data for example.")
7679
req = requests.get("https://osf.io/59bqn/download")
@@ -85,10 +88,8 @@ def get_weather_data(filename="weather.csv", **kwargs):
8588
date_parser=lambda idx: pd.to_datetime(idx, utc=True),
8689
)
8790

88-
# change type of index to datetime and set time zone
89-
weather_df.index = pd.to_datetime(weather_df.index).tz_convert(
90-
"Europe/Berlin"
91-
)
91+
# change time zone
92+
weather_df.index = weather_df.index.tz_convert("Europe/Berlin")
9293

9394
return weather_df
9495

@@ -197,8 +198,7 @@ def calculate_power_output(weather, my_turbine, e126, my_turbine2):
197198
"""
198199

199200
# ************************************************************************
200-
# **** Data is provided in the oedb turbine library **********************
201-
# **** ModelChain with non-default specifications
201+
# **** ModelChain with non-default specifications ************************
202202
modelchain_data = {
203203
"wind_speed_model": "logarithmic", # 'logarithmic' (default),
204204
# 'hellman' or
@@ -207,8 +207,8 @@ def calculate_power_output(weather, my_turbine, e126, my_turbine2):
207207
# 'interpolation_extrapolation'
208208
"temperature_model": "linear_gradient", # 'linear_gradient' (def.) or
209209
# 'interpolation_extrapolation'
210-
"power_output_model": "power_curve", # 'power_curve' (default) or
211-
# 'power_coefficient_curve'
210+
"power_output_model": "power_coefficient_curve", # 'power_curve'
211+
# (default) or 'power_coefficient_curve'
212212
"density_correction": True, # False (default) or True
213213
"obstacle_height": 0, # default: 0
214214
"hellman_exp": None,
@@ -220,17 +220,15 @@ def calculate_power_output(weather, my_turbine, e126, my_turbine2):
220220
e126.power_output = mc_e126.power_output
221221

222222
# ************************************************************************
223-
# **** Specification of wind turbine with your own data ******************
224-
# **** ModelChain with default parameter
223+
# **** ModelChain with default parameter *********************************
225224
mc_my_turbine = ModelChain(my_turbine).run_model(weather)
226225
# write power output time series to WindTurbine object
227226
my_turbine.power_output = mc_my_turbine.power_output
228227

229228
# ************************************************************************
230-
# **** Specification of wind turbine with data in own file ***************
231-
# **** Using "power_coefficient_curve" as "power_output_model".
229+
# **** ModelChain with non-default value for "wind_speed_model" **********
232230
mc_example_turbine = ModelChain(
233-
my_turbine2, power_output_model="power_curve"
231+
my_turbine2, wind_speed_model="hellman"
234232
).run_model(weather)
235233
my_turbine2.power_output = mc_example_turbine.power_output
236234

example/power_coefficient_curves.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/power_curves.csv

Lines changed: 0 additions & 3 deletions
This file was deleted.

example/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_modelchain_example_flh(self):
2222
mc_e.calculate_power_output(weather, my_turbine, e126, dummy_turbine)
2323

2424
assert_allclose(
25-
2764.194772, (e126.power_output.sum() / e126.nominal_power), 0.01
25+
2730.142, (e126.power_output.sum() / e126.nominal_power), 0.01
2626
)
2727
assert_allclose(
2828
1882.7567,

example/turbine_cluster_modelchain_example.ipynb

Lines changed: 6 additions & 17 deletions
Large diffs are not rendered by default.

example/turbine_cluster_modelchain_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def run_example():
219219
220220
"""
221221
weather = mc_e.get_weather_data("weather.csv")
222-
my_turbine, e126, dummy_turbine = mc_e.initialize_wind_turbines()
222+
my_turbine, e126, my_turbine2 = mc_e.initialize_wind_turbines()
223223
example_farm, example_farm_2 = initialize_wind_farms(my_turbine, e126)
224224
example_cluster = initialize_wind_turbine_cluster(
225225
example_farm, example_farm_2

example/turbine_data.csv

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)