1515"""
1616import os
1717import pandas as pd
18+ import logging
19+ import requests
20+ from windpowerlib import ModelChain
21+ from windpowerlib import WindTurbine
1822
1923try :
2024 from matplotlib import pyplot as plt
2125except ImportError :
2226 plt = None
2327
24- from windpowerlib import ModelChain
25- from windpowerlib import WindTurbine
26-
27- # You can use the logging package to get logging messages from the windpowerlib
28- # Change the logging level if you want more or less messages
29- import logging
30- logging .getLogger ().setLevel (logging .DEBUG )
31-
3228
3329def get_weather_data (filename = 'weather.csv' , ** kwargs ):
3430 r"""
@@ -65,11 +61,16 @@ def get_weather_data(filename='weather.csv', **kwargs):
6561 """
6662
6763 if "datapath" not in kwargs :
68- kwargs ["datapath" ] = os .path .join (
69- os .path .split (os .path .dirname (__file__ ))[0 ], "example"
70- )
64+ kwargs ["datapath" ] = os .path .dirname (__file__ )
65+
7166 file = os .path .join (kwargs ["datapath" ], filename )
7267
68+ if not os .path .isfile (file ):
69+ logging .debug ("Download weather data for example." )
70+ req = requests .get ("https://osf.io/59bqn/download" )
71+ with open (file , "wb" ) as fout :
72+ fout .write (req .content )
73+
7374 # read csv file
7475 weather_df = pd .read_csv (
7576 file ,
@@ -136,22 +137,10 @@ def initialize_wind_turbines():
136137 # initialize WindTurbine object
137138 my_turbine = WindTurbine (** my_turbine )
138139
139- # specification of wind turbine where power coefficient curve and nominal
140- # power is provided in an own csv file
141- csv_path = os .path .join (os .path .dirname (__file__ ), "data" )
142- dummy_turbine = {
143- "turbine_type" : "DUMMY 1" ,
144- "hub_height" : 100 , # in m
145- "rotor_diameter" : 70 , # in m
146- "path" : csv_path ,
147- }
148- # initialize WindTurbine object
149- dummy_turbine = WindTurbine (** dummy_turbine )
150-
151- return my_turbine , e126 , dummy_turbine
140+ return my_turbine , e126
152141
153142
154- def calculate_power_output (weather , my_turbine , e126 , dummy_turbine ):
143+ def calculate_power_output (weather , my_turbine , e126 ):
155144 r"""
156145 Calculates power output of wind turbines using the
157146 :class:`~.modelchain.ModelChain`.
@@ -172,8 +161,6 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
172161 e126 : :class:`~.wind_turbine.WindTurbine`
173162 WindTurbine object with power curve from the OpenEnergy Database
174163 turbine library.
175- dummy_turbine : :class:`~.wind_turbine.WindTurbine`
176- WindTurbine object with power coefficient curve from example file.
177164
178165 """
179166
@@ -209,14 +196,14 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
209196 # power output calculation for example_turbine
210197 # own specification for 'power_output_model'
211198 mc_example_turbine = ModelChain (
212- dummy_turbine , power_output_model = "power_coefficient_curve"
199+ my_turbine , power_output_model = "power_coefficient_curve"
213200 ).run_model (weather )
214- dummy_turbine .power_output = mc_example_turbine .power_output
201+ my_turbine .power_output = mc_example_turbine .power_output
215202
216203 return
217204
218205
219- def plot_or_print (my_turbine , e126 , dummy_turbine ):
206+ def plot_or_print (my_turbine , e126 ):
220207 r"""
221208 Plots or prints power output and power (coefficient) curves.
222209
@@ -227,23 +214,18 @@ def plot_or_print(my_turbine, e126, dummy_turbine):
227214 e126 : :class:`~.wind_turbine.WindTurbine`
228215 WindTurbine object with power curve from the OpenEnergy Database
229216 turbine library.
230- dummy_turbine : :class:`~.wind_turbine.WindTurbine`
231- WindTurbine object with power coefficient curve from example file.
232-
233217 """
234218
235219 # plot or print turbine power output
236220 if plt :
237221 e126 .power_output .plot (legend = True , label = 'Enercon E126' )
238222 my_turbine .power_output .plot (legend = True , label = 'myTurbine' )
239- dummy_turbine .power_output .plot (legend = True , label = 'dummyTurbine' )
240223 plt .xlabel ('Time' )
241224 plt .ylabel ('Power in W' )
242225 plt .show ()
243226 else :
244227 print (e126 .power_output )
245228 print (my_turbine .power_output )
246- print (dummy_turbine .power_output )
247229
248230 # plot or print power curve
249231 if plt :
@@ -259,13 +241,6 @@ def plot_or_print(my_turbine, e126, dummy_turbine):
259241 plt .xlabel ('Wind speed in m/s' )
260242 plt .ylabel ('Power in W' )
261243 plt .show ()
262- if dummy_turbine .power_coefficient_curve is not False :
263- dummy_turbine .power_coefficient_curve .plot (
264- x = 'wind_speed' , y = 'value' , style = '*' ,
265- title = 'dummyTurbine power coefficient curve' )
266- plt .xlabel ('Wind speed in m/s' )
267- plt .ylabel ('Power coefficient' )
268- plt .show ()
269244 else :
270245 if e126 .power_coefficient_curve is not False :
271246 print (e126 .power_coefficient_curve )
@@ -278,10 +253,16 @@ def run_example():
278253 Runs the basic example.
279254
280255 """
256+ # You can use the logging package to get logging messages from the
257+ # windpowerlib. Change the logging level if you want more or less messages:
258+ # logging.DEBUG -> many messages
259+ # logging.INFO -> few messages
260+ logging .getLogger ().setLevel (logging .DEBUG )
261+
281262 weather = get_weather_data ("weather.csv" )
282- my_turbine , e126 , dummy_turbine = initialize_wind_turbines ()
283- calculate_power_output (weather , my_turbine , e126 , dummy_turbine )
284- plot_or_print (my_turbine , e126 , dummy_turbine )
263+ my_turbine , e126 = initialize_wind_turbines ()
264+ calculate_power_output (weather , my_turbine , e126 )
265+ plot_or_print (my_turbine , e126 )
285266
286267
287268if __name__ == "__main__" :
0 commit comments