2424import pandas as pd
2525import requests
2626import logging
27- from windpowerlib import ModelChain , WindTurbine
27+ from windpowerlib import ModelChain , WindTurbine , create_power_curve
2828
2929try :
3030 from matplotlib import pyplot as plt
3131except ImportError :
3232 plt = None
3333
3434
35- def get_weather_data (filename = ' weather.csv' , ** kwargs ):
35+ def get_weather_data (filename = " weather.csv" , ** kwargs ):
3636 r"""
3737 Imports weather data from a file.
3838
@@ -127,6 +127,7 @@ def initialize_wind_turbines():
127127 # ************************************************************************
128128 # **** Specification of wind turbine with your own data ******************
129129 # **** NOTE: power values and nominal power have to be in Watt
130+
130131 my_turbine = {
131132 "nominal_power" : 3e6 , # in W
132133 "hub_height" : 105 , # in m
@@ -144,18 +145,31 @@ def initialize_wind_turbines():
144145
145146 # ************************************************************************
146147 # **** Specification of wind turbine with data in own file ***************
147- dummy_turbine = {
148- "turbine_type" : "DUMMY 1" ,
149- "hub_height" : 100 , # in m
150- "rotor_diameter" : 70 , # in m
151- "path" : os .path .dirname (__file__ ),
148+
149+ # Read your turbine data from your data file using functions like
150+ # pandas.read_csv().
151+ # >>> import pandas as pd
152+ # >>> my_data = pd.read_csv("path/to/my/data/file")
153+ # >>> my_power = my_data["my_power"]
154+ # >>> my_wind_speed = my_data["my_wind_speed"]
155+
156+ my_power = pd .Series (
157+ [0.0 , 39000.0 , 270000.0 , 2250000.0 , 4500000.0 , 4500000.0 ])
158+ my_wind_speed = (0.0 , 3.0 , 5.0 , 10.0 , 15.0 , 25.0 )
159+
160+ my_turbine2 = {
161+ "nominal_power" : 6e6 , # in W
162+ "hub_height" : 115 , # in m
163+ "power_curve" : create_power_curve (
164+ wind_speed = my_wind_speed , power = my_power
165+ ),
152166 }
153- dummy_turbine = WindTurbine (** dummy_turbine )
167+ my_turbine2 = WindTurbine (** my_turbine2 )
154168
155- return my_turbine , e126 , dummy_turbine
169+ return my_turbine , e126 , my_turbine2
156170
157171
158- def calculate_power_output (weather , my_turbine , e126 , dummy_turbine ):
172+ def calculate_power_output (weather , my_turbine , e126 , my_turbine2 ):
159173 r"""
160174 Calculates power output of wind turbines using the
161175 :class:`~.modelchain.ModelChain`.
@@ -176,7 +190,7 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
176190 e126 : :class:`~.wind_turbine.WindTurbine`
177191 WindTurbine object with power curve from the OpenEnergy Database
178192 turbine library.
179- dummy_turbine : :class:`~.wind_turbine.WindTurbine`
193+ my_turbine2 : :class:`~.wind_turbine.WindTurbine`
180194 WindTurbine object with power coefficient curve from example file.
181195
182196 """
@@ -215,14 +229,14 @@ def calculate_power_output(weather, my_turbine, e126, dummy_turbine):
215229 # **** Specification of wind turbine with data in own file ***************
216230 # **** Using "power_coefficient_curve" as "power_output_model".
217231 mc_example_turbine = ModelChain (
218- dummy_turbine , power_output_model = "power_coefficient_curve "
232+ my_turbine2 , power_output_model = "power_curve "
219233 ).run_model (weather )
220- dummy_turbine .power_output = mc_example_turbine .power_output
234+ my_turbine2 .power_output = mc_example_turbine .power_output
221235
222236 return
223237
224238
225- def plot_or_print (my_turbine , e126 , dummy_turbine ):
239+ def plot_or_print (my_turbine , e126 , my_turbine2 ):
226240 r"""
227241 Plots or prints power output and power (coefficient) curves.
228242
@@ -233,44 +247,55 @@ def plot_or_print(my_turbine, e126, dummy_turbine):
233247 e126 : :class:`~.wind_turbine.WindTurbine`
234248 WindTurbine object with power curve from the OpenEnergy Database
235249 turbine library.
236- dummy_turbine : :class:`~.wind_turbine.WindTurbine`
250+ my_turbine2 : :class:`~.wind_turbine.WindTurbine`
237251 WindTurbine object with power coefficient curve from example file.
238252
239253 """
240254
241255 # plot or print turbine power output
242256 if plt :
243- e126 .power_output .plot (legend = True , label = ' Enercon E126' )
244- my_turbine .power_output .plot (legend = True , label = ' myTurbine' )
245- dummy_turbine .power_output .plot (legend = True , label = ' dummyTurbine' )
246- plt .xlabel (' Time' )
247- plt .ylabel (' Power in W' )
257+ e126 .power_output .plot (legend = True , label = " Enercon E126" )
258+ my_turbine .power_output .plot (legend = True , label = " myTurbine" )
259+ my_turbine2 .power_output .plot (legend = True , label = " dummyTurbine" )
260+ plt .xlabel (" Time" )
261+ plt .ylabel (" Power in W" )
248262 plt .show ()
249263 else :
250264 print (e126 .power_output )
251265 print (my_turbine .power_output )
252- print (dummy_turbine .power_output )
266+ print (my_turbine2 .power_output )
253267
254268 # plot or print power curve
255269 if plt :
256270 if e126 .power_curve is not False :
257- e126 .power_curve .plot (x = 'wind_speed' , y = 'value' , style = '*' ,
258- title = 'Enercon E126 power curve' )
259- plt .xlabel ('Wind speed in m/s' )
260- plt .ylabel ('Power in W' )
271+ e126 .power_curve .plot (
272+ x = "wind_speed" ,
273+ y = "value" ,
274+ style = "*" ,
275+ title = "Enercon E126 power curve" ,
276+ )
277+ plt .xlabel ("Wind speed in m/s" )
278+ plt .ylabel ("Power in W" )
261279 plt .show ()
262280 if my_turbine .power_curve is not False :
263- my_turbine .power_curve .plot (x = 'wind_speed' , y = 'value' , style = '*' ,
264- title = 'myTurbine power curve' )
265- plt .xlabel ('Wind speed in m/s' )
266- plt .ylabel ('Power in W' )
281+ my_turbine .power_curve .plot (
282+ x = "wind_speed" ,
283+ y = "value" ,
284+ style = "*" ,
285+ title = "myTurbine power curve" ,
286+ )
287+ plt .xlabel ("Wind speed in m/s" )
288+ plt .ylabel ("Power in W" )
267289 plt .show ()
268- if dummy_turbine .power_coefficient_curve is not False :
269- dummy_turbine .power_coefficient_curve .plot (
270- x = 'wind_speed' , y = 'value' , style = '*' ,
271- title = 'dummyTurbine power coefficient curve' )
272- plt .xlabel ('Wind speed in m/s' )
273- plt .ylabel ('Power coefficient' )
290+ if my_turbine2 .power_curve is not False :
291+ my_turbine2 .power_curve .plot (
292+ x = "wind_speed" ,
293+ y = "value" ,
294+ style = "*" ,
295+ title = "myTurbine2 power curve" ,
296+ )
297+ plt .xlabel ("Wind speed in m/s" )
298+ plt .ylabel ("Power in W" )
274299 plt .show ()
275300 else :
276301 if e126 .power_coefficient_curve is not False :
@@ -291,9 +316,9 @@ def run_example():
291316 logging .getLogger ().setLevel (logging .DEBUG )
292317
293318 weather = get_weather_data ("weather.csv" )
294- my_turbine , e126 , dummy_turbine = initialize_wind_turbines ()
295- calculate_power_output (weather , my_turbine , e126 , dummy_turbine )
296- plot_or_print (my_turbine , e126 , dummy_turbine )
319+ my_turbine , e126 , my_turbine2 = initialize_wind_turbines ()
320+ calculate_power_output (weather , my_turbine , e126 , my_turbine2 )
321+ plot_or_print (my_turbine , e126 , my_turbine2 )
297322
298323
299324if __name__ == "__main__" :
0 commit comments