1111import pandas as pd
1212import os
1313
14- try :
15- from matplotlib import pyplot as plt
16- except ImportError :
17- plt = None
18-
1914
2015def reduce_wind_speed (wind_speed , wind_efficiency_curve_name = 'dena_mean' ):
2116 r"""
@@ -66,9 +61,10 @@ def get_wind_efficiency_curve(curve_name='dena_mean'):
6661
6762 Parameters
6863 ----------
69- curve_name : String
64+ curve_name : str or list
7065 Specifies the curve. Use display_wind_efficiency_curves() to see all
71- provided wind efficiency curves. Default: 'dena_mean'.
66+ provided wind efficiency curves. Default: 'dena_mean'. Use 'all' to
67+ get all curves in a MultiIndex DataFrame.
7268
7369 Returns
7470 -------
@@ -92,79 +88,54 @@ def get_wind_efficiency_curve(curve_name='dena_mean'):
9288 Windleistungssimulationen". Universität Kassel, Diss., 2016,
9389 p. 124
9490
91+ Examples
92+ --------
93+ # Example to plot all curves
94+ fig, ax = plt.subplots()
95+ df = get_wind_efficiency_curve(curve_name='all')
96+ for t in df.columns.get_level_values(0).unique():
97+ p = df[t].set_index('wind_speed')['efficiency']
98+ p.name = t
99+ ax = p.plot(ax=ax, legend=True)
100+ plt.show()
101+
95102 """
96103 possible_curve_names = ['dena_mean' , 'knorr_mean' , 'dena_extreme1' ,
97104 'dena_extreme2' , 'knorr_extreme1' ,
98105 'knorr_extreme2' , 'knorr_extreme3' ]
99- if curve_name .split ('_' )[0 ] not in ['dena' , 'knorr' ]:
100- raise ValueError ("`curve_name` must be one of the following: " +
101- "{} but is {}" .format (possible_curve_names ,
102- curve_name ))
103- path = os .path .join (os .path .dirname (__file__ ), 'data' ,
104- 'wind_efficiency_curves_{}.csv' .format (
105- curve_name .split ('_' )[0 ]))
106- # Read wind efficiency curves from file
107- wind_efficiency_curves = pd .read_csv (path )
108- # Raise error if wind efficiency curve specified in 'curve_name' does not
109- # exist
110- if curve_name not in list (wind_efficiency_curves ):
111- raise ValueError ("Efficiency curve name does not exist. Must be one" +
112- "of the following: {}" .format (possible_curve_names ) +
113- "but is {}" .format (curve_name ))
114- # Get wind efficiency curve and rename column containing efficiency
115- efficiency_curve = wind_efficiency_curves [['wind_speed' , curve_name ]]
116- efficiency_curve .columns = ['wind_speed' , 'efficiency' ]
117- return efficiency_curve
118-
119-
120- def display_wind_efficiency_curves ():
121- r"""
122- Displays all wind efficiency curves available in the windpowerlib.
123-
124- Notes
125- -----
126- The wind efficiency curves were generated in the "Dena Netzstudie" and in
127- the dissertation of Kaspar Knorr. For more information see [1]_ and [2]_.
128106
129- References
130- ----------
131- .. [1] Kohler et.al.: "dena-Netzstudie II. Integration erneuerbarer
132- Energien in die deutsche Stromversorgung im Zeitraum 2015 – 2020
133- mit Ausblick 2025.", Deutsche Energie-Agentur GmbH (dena),
134- Tech. rept., 2010, p. 101
135- .. [2] Knorr, K.: "Modellierung von raum-zeitlichen Eigenschaften der
136- Windenergieeinspeisung für wetterdatenbasierte
137- Windleistungssimulationen". Universität Kassel, Diss., 2016,
138- p. 124
139-
140- """
141- origins = ['dena' , 'knorr' ]
142- paths = [os .path .join (os .path .dirname (__file__ ), 'data' ,
143- 'wind_efficiency_curves_{}.csv' .format (origin )) for
144- origin in origins ]
145- # Read wind efficiency curves from files
146- # Create separate data frames for origin of curve
147- dena_df = pd .read_csv (paths [0 ])
148- knorr_df = pd .read_csv (paths [1 ])
149- # Print names of all available curves
150- curves_list = [col for col in dena_df if 'wind_speed' not in col ]
151- curves_list .extend ([col for col in knorr_df if 'wind_speed' not in col ])
152- print ("Names of the provided wind efficiency curves are the " +
153- "following: {}" .format (curves_list ))
154- if plt :
155- # Create data frames for plot
156- dena_df .set_index ('wind_speed' , inplace = True )
157- knorr_df .set_index ('wind_speed' , inplace = True )
158- fig , ax = plt .subplots ()
159- dena_df .plot (ax = ax , legend = True , linestyle = '--' )
160- knorr_df .plot (ax = ax , legend = True )
161- plt .ylabel ('Wind efficiency' )
162- plt .xlabel ('Wind speed m/s' )
163- plt .show ()
107+ if curve_name == 'all' :
108+ curve_names = possible_curve_names
109+ elif isinstance (curve_name , str ):
110+ curve_names = [curve_name ]
164111 else :
165- print (dena_df )
166- print (knorr_df )
167-
168-
169- if __name__ == "__main__" :
170- display_wind_efficiency_curves ()
112+ curve_names = curve_name
113+
114+ efficiency_curve = pd .DataFrame (columns = pd .MultiIndex (levels = [[], []],
115+ labels = [[], []]))
116+
117+ for curve_name in curve_names :
118+ if curve_name .split ('_' )[0 ] not in ['dena' , 'knorr' ]:
119+ raise ValueError ("`curve_name` must be one of the following: " +
120+ "{} but is {}" .format (possible_curve_names ,
121+ curve_name ))
122+ path = os .path .join (os .path .dirname (__file__ ), 'data' ,
123+ 'wind_efficiency_curves_{}.csv' .format (
124+ curve_name .split ('_' )[0 ]))
125+ # Read wind efficiency curves from file
126+ wind_efficiency_curves = pd .read_csv (path )
127+ # Raise error if wind efficiency curve specified in 'curve_name' does
128+ # not exist
129+ if curve_name not in list (wind_efficiency_curves ):
130+ msg = ("Efficiency curve <{0}> does not exist. Must be one of the"
131+ "following: {1}." )
132+ raise ValueError (msg .format (curve_name , * possible_curve_names ))
133+
134+ # Get wind efficiency curve and rename column containing efficiency
135+ wec = wind_efficiency_curves [['wind_speed' , curve_name ]]
136+ efficiency_curve [curve_name , 'wind_speed' ] = wec ['wind_speed' ]
137+ efficiency_curve [curve_name , 'efficiency' ] = wec [curve_name ]
138+ if len (curve_names ) == 1 :
139+ return efficiency_curve [curve_names [0 ]]
140+ else :
141+ return efficiency_curve
0 commit comments