|
10 | 10 | import numpy as np |
11 | 11 | import pandas as pd |
12 | 12 | import os |
13 | | -import logging |
14 | | - |
15 | | -try: |
16 | | - from matplotlib import pyplot as plt |
17 | | -except ImportError: |
18 | | - plt = None |
19 | 13 |
|
20 | 14 |
|
21 | 15 | def reduce_wind_speed(wind_speed, wind_efficiency_curve_name='dena_mean'): |
@@ -67,9 +61,10 @@ def get_wind_efficiency_curve(curve_name='dena_mean'): |
67 | 61 |
|
68 | 62 | Parameters |
69 | 63 | ---------- |
70 | | - curve_name : String |
| 64 | + curve_name : str or list |
71 | 65 | Specifies the curve. Use display_wind_efficiency_curves() to see all |
72 | | - 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. |
73 | 68 |
|
74 | 69 | Returns |
75 | 70 | ------- |
@@ -98,91 +93,54 @@ def get_wind_efficiency_curve(curve_name='dena_mean'): |
98 | 93 | Windleistungssimulationen". Universität Kassel, Diss., 2016, |
99 | 94 | p. 124 |
100 | 95 |
|
| 96 | + Examples |
| 97 | + -------- |
| 98 | + # Example to plot all curves |
| 99 | + fig, ax = plt.subplots() |
| 100 | + df = get_wind_efficiency_curve(curve_name='all') |
| 101 | + for t in df.columns.get_level_values(0).unique(): |
| 102 | + p = df[t].set_index('wind_speed')['efficiency'] |
| 103 | + p.name = t |
| 104 | + ax = p.plot(ax=ax, legend=True) |
| 105 | + plt.show() |
| 106 | +
|
101 | 107 | """ |
102 | 108 | possible_curve_names = ['dena_mean', 'knorr_mean', 'dena_extreme1', |
103 | 109 | 'dena_extreme2', 'knorr_extreme1', |
104 | 110 | 'knorr_extreme2', 'knorr_extreme3'] |
105 | | - if curve_name.split('_')[0] not in ['dena', 'knorr']: |
106 | | - raise ValueError("`curve_name` must be one of the following: " + |
107 | | - "{} but is {}".format(possible_curve_names, |
108 | | - curve_name)) |
109 | | - path = os.path.join(os.path.dirname(__file__), 'data', |
110 | | - 'wind_efficiency_curves_{}.csv'.format( |
111 | | - curve_name.split('_')[0])) |
112 | | - # Read wind efficiency curves from file |
113 | | - wind_efficiency_curves = pd.read_csv(path) |
114 | | - # Raise error if wind efficiency curve specified in 'curve_name' does not |
115 | | - # exist |
116 | | - if curve_name not in list(wind_efficiency_curves): |
117 | | - raise ValueError("Efficiency curve name does not exist. Must be one" + |
118 | | - "of the following: {}".format(possible_curve_names) + |
119 | | - "but is {}".format(curve_name)) |
120 | | - # Get wind efficiency curve and rename column containing efficiency |
121 | | - efficiency_curve = wind_efficiency_curves[['wind_speed', curve_name]] |
122 | | - efficiency_curve.columns = ['wind_speed', 'efficiency'] |
123 | | - return efficiency_curve |
124 | | - |
125 | | - |
126 | | -def display_wind_efficiency_curves(print_out=False, plot=False): |
127 | | - r""" |
128 | | - Displays all names of wind efficiency curves available in the windpowerlib. |
129 | | -
|
130 | | - Parameters |
131 | | - ---------- |
132 | | - print_out : Boolean |
133 | | - If True the values of the wind efficiency curves are printed. Default: |
134 | | - False. |
135 | | - plot : Boolean |
136 | | - If True all available wind efficiency curves are plotted - if |
137 | | - matplotlib is installed. Default: False. |
138 | 111 |
|
139 | | - Notes |
140 | | - ----- |
141 | | - The wind efficiency curves were generated in the "Dena Netzstudie" and in |
142 | | - the dissertation of Kaspar Knorr. For more information see [1]_ and [2]_. |
143 | | -
|
144 | | - References |
145 | | - ---------- |
146 | | - .. [1] Kohler et.al.: "dena-Netzstudie II. Integration erneuerbarer |
147 | | - Energien in die deutsche Stromversorgung im Zeitraum 2015 – 2020 |
148 | | - mit Ausblick 2025.", Deutsche Energie-Agentur GmbH (dena), |
149 | | - Tech. rept., 2010, p. 101 |
150 | | - .. [2] Knorr, K.: "Modellierung von raum-zeitlichen Eigenschaften der |
151 | | - Windenergieeinspeisung für wetterdatenbasierte |
152 | | - Windleistungssimulationen". Universität Kassel, Diss., 2016, |
153 | | - p. 124 |
154 | | -
|
155 | | - """ |
156 | | - origins = ['dena', 'knorr'] |
157 | | - paths = [os.path.join(os.path.dirname(__file__), 'data', |
158 | | - 'wind_efficiency_curves_{}.csv'.format(origin)) for |
159 | | - origin in origins] |
160 | | - # Read wind efficiency curves from files |
161 | | - # Create separate data frames for origin of curve |
162 | | - dena_df = pd.read_csv(paths[0]) |
163 | | - knorr_df = pd.read_csv(paths[1]) |
164 | | - # Print names of all available curves |
165 | | - curves_list = [col for col in dena_df if 'wind_speed' not in col] |
166 | | - curves_list.extend([col for col in knorr_df if 'wind_speed' not in col]) |
167 | | - print("Names of the provided wind efficiency curves are the " + |
168 | | - "following: {}".format(curves_list)) |
169 | | - print("To plot the different wind efficiency curves use this function " + |
170 | | - "with the parameter plot=True.") |
171 | | - if plt and plot is True: |
172 | | - # Create data frames for plot |
173 | | - dena_df.set_index('wind_speed', inplace=True) |
174 | | - knorr_df.set_index('wind_speed', inplace=True) |
175 | | - fig, ax = plt.subplots() |
176 | | - dena_df.plot(ax=ax, legend=True, linestyle='--') |
177 | | - knorr_df.plot(ax=ax, legend=True) |
178 | | - plt.ylabel('Wind efficiency') |
179 | | - plt.xlabel('Wind speed m/s') |
180 | | - plt.show() |
| 112 | + if curve_name == 'all': |
| 113 | + curve_names = possible_curve_names |
| 114 | + elif isinstance(curve_name, str): |
| 115 | + curve_names = [curve_name] |
181 | 116 | else: |
182 | | - logging.debug("Matplotlib is not installed.") |
183 | | - if print_out is True: |
184 | | - print(dena_df) |
185 | | - print(knorr_df) |
186 | | - |
187 | | -if __name__ == "__main__": |
188 | | - display_wind_efficiency_curves() |
| 117 | + curve_names = curve_name |
| 118 | + |
| 119 | + efficiency_curve = pd.DataFrame(columns=pd.MultiIndex(levels=[[], []], |
| 120 | + labels=[[], []])) |
| 121 | + |
| 122 | + for curve_name in curve_names: |
| 123 | + if curve_name.split('_')[0] not in ['dena', 'knorr']: |
| 124 | + raise ValueError("`curve_name` must be one of the following: " + |
| 125 | + "{} but is {}".format(possible_curve_names, |
| 126 | + curve_name)) |
| 127 | + path = os.path.join(os.path.dirname(__file__), 'data', |
| 128 | + 'wind_efficiency_curves_{}.csv'.format( |
| 129 | + curve_name.split('_')[0])) |
| 130 | + # Read wind efficiency curves from file |
| 131 | + wind_efficiency_curves = pd.read_csv(path) |
| 132 | + # Raise error if wind efficiency curve specified in 'curve_name' does |
| 133 | + # not exist |
| 134 | + if curve_name not in list(wind_efficiency_curves): |
| 135 | + msg = ("Efficiency curve <{0}> does not exist. Must be one of the" |
| 136 | + "following: {1}.") |
| 137 | + raise ValueError(msg.format(curve_name, *possible_curve_names)) |
| 138 | + |
| 139 | + # Get wind efficiency curve and rename column containing efficiency |
| 140 | + wec = wind_efficiency_curves[['wind_speed', curve_name]] |
| 141 | + efficiency_curve[curve_name, 'wind_speed'] = wec['wind_speed'] |
| 142 | + efficiency_curve[curve_name, 'efficiency'] = wec[curve_name] |
| 143 | + if len(curve_names) == 1: |
| 144 | + return efficiency_curve[curve_names[0]] |
| 145 | + else: |
| 146 | + return efficiency_curve |
0 commit comments