|
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": {}, |
6 | 6 | "source": [ |
7 | | - "This example shows you the basic usage of the windpowerlib. There are mainly three steps.\n", |
8 | | - "First you need to define your wind turbine, then get your weather data and in the last step call the windpowerlib ModelChain to generate your feedin timeseries.\n", |
9 | | - "Be careful with the units!" |
| 7 | + "This example shows you the basic usage of the windpowerlib. \n", |
| 8 | + "There are mainly three steps. First you have to import your weather data, then you need to specify your wind turbine, and in the last step call the windpowerlib functions to calculate the feedin timeseries." |
10 | 9 | ] |
11 | 10 | }, |
12 | 11 | { |
|
59 | 58 | "source": [ |
60 | 59 | "### Import weather data\n", |
61 | 60 | "\n", |
62 | | - "The function below imports the example weather data from the weather.csv file provided along with the windpowerlib. The data include wind speed at two different heights in m/s, air temperature in two different heights in K, surface roughness length in m and air pressure in Pa.\n", |
| 61 | + "In order to use the windpowerlib you need to at least provide wind speed data for the time frame you want to analyse.\n", |
| 62 | + "The function below imports example weather data from the weather.csv file provided along with the windpowerlib. The data include wind speed at two different heights in m/s, air temperature in two different heights in K, surface roughness length in m and air pressure in Pa.\n", |
63 | 63 | "\n", |
64 | 64 | "To find out which weather data in which units need to be provided in order to use the ModelChain or other functions of the windpowerlib see the individual function documentation." |
65 | 65 | ] |
|
72 | 72 | }, |
73 | 73 | "outputs": [], |
74 | 74 | "source": [ |
75 | | - "def read_weather_data(filename, datetime_column='Unnamed: 0',\n", |
| 75 | + "def read_weather_data(filename, datetime_column='time_index',\n", |
76 | 76 | " **kwargs):\n", |
77 | 77 | " r\"\"\"\n", |
78 | 78 | " Fetches weather data from a file.\n", |
|
109 | 109 | "\n", |
110 | 110 | "\n", |
111 | 111 | "# Read weather data from csv\n", |
112 | | - "weather = read_weather_data('weather.csv')" |
| 112 | + "weather = read_weather_data(filename='weather.csv', datapath='')" |
113 | 113 | ] |
114 | 114 | }, |
115 | 115 | { |
|
127 | 127 | }, |
128 | 128 | "outputs": [], |
129 | 129 | "source": [ |
| 130 | + "# height in meters\n", |
130 | 131 | "data_height = {\n", |
131 | 132 | " 'pressure': 0,\n", |
132 | 133 | " 'temp_air': 2,\n", |
|
146 | 147 | "cell_type": "markdown", |
147 | 148 | "metadata": {}, |
148 | 149 | "source": [ |
149 | | - "There are two ways to initialize a WindTurbine object. You can either specify your own turbine, as done below or use" |
| 150 | + "To initialise your specific turbine you need a dictionary that contains your basic parameters. A turbine is defined by its nominal power, hub height, rotor diameter, and power or power coefficient curve.\n", |
| 151 | + "\n", |
| 152 | + "There are two ways to initialise a WindTurbine object in the windpowerlib. You can either specify your own turbine, as done below for 'myTurbine' or fetch power and/or power coefficient curve data from data files provided by the windpowerlib, as done for the 'enerconE126'.\n", |
| 153 | + "\n", |
| 154 | + "You can execute the following to get a list of all wind turbines for which power or power coefficient curves are provided." |
150 | 155 | ] |
151 | 156 | }, |
152 | 157 | { |
153 | 158 | "cell_type": "code", |
154 | 159 | "execution_count": null, |
155 | | - "metadata": { |
156 | | - "collapsed": true |
157 | | - }, |
| 160 | + "metadata": {}, |
158 | 161 | "outputs": [], |
159 | 162 | "source": [ |
| 163 | + "# print names of wind turbines for which power curves are provided (default)\n", |
160 | 164 | "wt.get_turbine_types()\n", |
161 | | - "turbines[turbines[\"turbine_id\"].str.contains(\"VESTAS\")]" |
| 165 | + "\n", |
| 166 | + "# write names of wind turbines for which power coefficient curves are provided to 'turbines' DataFrame\n", |
| 167 | + "turbines = wt.get_turbine_types(filename='cp_curves.csv', print_out=False)\n", |
| 168 | + "# find all Vestas in 'turbines' DataFrame\n", |
| 169 | + "print(turbines[turbines[\"turbine_id\"].str.contains(\"ENERCON\")])" |
162 | 170 | ] |
163 | 171 | }, |
164 | 172 | { |
|
169 | 177 | }, |
170 | 178 | "outputs": [], |
171 | 179 | "source": [ |
172 | | - "# Specifications of the wind turbines\n", |
173 | | - "enerconE126 = {\n", |
174 | | - " 'hub_height': 135,\n", |
175 | | - " 'd_rotor': 127,\n", |
176 | | - " 'fetch_curve': 'P', # 'P' vor p-curve and 'cp' for cp-curve\n", |
177 | | - " 'turbine_name': 'ENERCON E 126 7500'} # Turbine name as in register. Use\n", |
178 | | - " # wind_turbine.get_turbine_types()\n", |
179 | | - "P_data = {0:\n", |
180 | | - " 3:\n", |
181 | | - " 5:\n", |
182 | | - " 10:\n", |
183 | | - " 15:\n", |
184 | | - " 20:\n", |
185 | | - " 25:}\n", |
186 | | - "# for a full list.\n", |
187 | | - "vestasV90 = {\n", |
188 | | - " 'hub_height': 105,\n", |
189 | | - " 'd_rotor': 90,\n", |
190 | | - " 'fetch_curve': 'P',\n", |
191 | | - " 'turbine_name': 'VESTAS V 90 3000'}\n", |
| 180 | + "# specification of own wind turbine (Note: power coefficient values and nominal power have to be in Watt)\n", |
| 181 | + "myTurbine = {\n", |
| 182 | + " 'turbine_name': 'myTurbine',\n", |
| 183 | + " 'nominal_power': 3e6, # in W\n", |
| 184 | + " 'hub_height': 105, # in m\n", |
| 185 | + " 'd_rotor': 90, # in m\n", |
| 186 | + " 'p_values': pd.DataFrame(\n", |
| 187 | + " data={'p': [p * 1000 for p in [0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]]}, # in W\n", |
| 188 | + " index=[0.0, 3.0, 5.0, 10.0, 15.0, 25.0])\n", |
| 189 | + " }\n", |
192 | 190 | "\n", |
193 | | - "# Initialize WindTurbine objects\n", |
| 191 | + "# specification of wind turbine where power curve is provided\n", |
| 192 | + "# if you want to use the power coefficient curve add {}'fetch_curve': 'cp'} to the dictionary\n", |
| 193 | + "enerconE126 = {\n", |
| 194 | + " 'turbine_name': 'ENERCON E 126 7500', # Turbine name as in register\n", |
| 195 | + " 'hub_height': 135, # in m\n", |
| 196 | + " 'd_rotor': 127 # in m\n", |
| 197 | + " }\n", |
| 198 | + " \n", |
| 199 | + "# initialise WindTurbine objects\n", |
194 | 200 | "e126 = wt.WindTurbine(**enerconE126)\n", |
195 | | - "v90 = wt.WindTurbine(**vestasV90)" |
| 201 | + "my_turbine = wt.WindTurbine(**myTurbine)" |
196 | 202 | ] |
197 | 203 | }, |
198 | 204 | { |
199 | 205 | "cell_type": "markdown", |
200 | 206 | "metadata": {}, |
201 | 207 | "source": [ |
202 | | - "### Use the ModelChain to generate feedin timeseries" |
| 208 | + "### Use the ModelChain to generate feedin timeseries\n", |
| 209 | + "\n", |
| 210 | + "The ModelChain is a class that provides all necessary steps to calculate the power output of a wind turbine. If you use the 'run_model' method first the wind speed and density (if necessary) at hub height are calculated and then used to calculate the power output. You can either use the default methods for the calculation steps, as done for 'my_turbine', or choose different methods, as done for the 'e126'." |
203 | 211 | ] |
204 | 212 | }, |
205 | 213 | { |
206 | 214 | "cell_type": "code", |
207 | 215 | "execution_count": null, |
208 | | - "metadata": { |
209 | | - "collapsed": true |
210 | | - }, |
| 216 | + "metadata": {}, |
211 | 217 | "outputs": [], |
212 | 218 | "source": [ |
213 | | - "# Specifications of the modelchain data\n", |
| 219 | + "# initialise ModelChain with default parameters and use run_model method to calculate power output\n", |
| 220 | + "mc_my_turbine = modelchain.ModelChain(my_turbine).run_model(\n", |
| 221 | + " weather, data_height)\n", |
| 222 | + "# write power output timeseries to WindTurbine object\n", |
| 223 | + "my_turbine.power_output = mc_my_turbine.power_output" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": null, |
| 229 | + "metadata": {}, |
| 230 | + "outputs": [], |
| 231 | + "source": [ |
| 232 | + "# own specifications for ModelChain setup\n", |
214 | 233 | "modelchain_data = {\n", |
215 | | - " 'obstacle_height': 0,\n", |
216 | | - " 'wind_model': 'logarithmic', # 'logarithmic' or 'hellman'\n", |
217 | | - " 'rho_model': 'ideal_gas', # 'barometric' or 'ideal_gas'\n", |
218 | | - " 'power_output_model': 'p_values', # 'p_values' or 'cp_values'\n", |
219 | | - " 'density_corr': False, # True or False\n", |
220 | | - " 'hellman_exp': None} # Float or None\n", |
221 | | - "\n", |
222 | | - "# Calculate turbine power output\n", |
| 234 | + " 'obstacle_height': 0, # default: 0\n", |
| 235 | + " 'wind_model': 'logarithmic', # 'logarithmic' (default) or 'hellman'\n", |
| 236 | + " 'rho_model': 'ideal_gas', # 'barometric' (default) or 'ideal_gas'\n", |
| 237 | + " 'power_output_model': 'p_values', # 'p_values' (default) or 'cp_values'\n", |
| 238 | + " 'density_corr': True, # False (default) or True\n", |
| 239 | + " 'hellman_exp': None} # None (default) or None\n", |
| 240 | + "# initialise ModelChain with own specifications and use run_model method to calculate power output\n", |
223 | 241 | "mc_e126 = modelchain.ModelChain(e126, **modelchain_data).run_model(\n", |
224 | | - " weather, coastDat2)\n", |
225 | | - "e126.power_output = mc_e126.power_output\n", |
226 | | - "mc_v90 = modelchain.ModelChain(v90, **modelchain_data).run_model(\n", |
227 | | - " weather, coastDat2)\n", |
228 | | - "v90.power_output = mc_v90.power_output\n", |
229 | | - "\n", |
230 | | - "\n" |
| 242 | + " weather, data_height)\n", |
| 243 | + "# write power output timeseries to WindTurbine object\n", |
| 244 | + "e126.power_output = mc_e126.power_output" |
231 | 245 | ] |
232 | 246 | }, |
233 | 247 | { |
234 | 248 | "cell_type": "markdown", |
235 | 249 | "metadata": {}, |
236 | 250 | "source": [ |
237 | | - "### Plot results" |
| 251 | + "### Plot results\n", |
| 252 | + "\n", |
| 253 | + "If you have matplotlib installed you can visualise the calculated power output and used power (coefficient) curves." |
238 | 254 | ] |
239 | 255 | }, |
240 | 256 | { |
|
245 | 261 | }, |
246 | 262 | "outputs": [], |
247 | 263 | "source": [ |
| 264 | + "# try to import matplotlib\n", |
248 | 265 | "try:\n", |
249 | 266 | " from matplotlib import pyplot as plt\n", |
| 267 | + " %matplotlib inline # needed in notebook to plot inline\n", |
250 | 268 | "except ImportError:\n", |
251 | | - " plt = None\n", |
252 | | - "# Plot turbine power output\n", |
| 269 | + " plt = None" |
| 270 | + ] |
| 271 | + }, |
| 272 | + { |
| 273 | + "cell_type": "code", |
| 274 | + "execution_count": null, |
| 275 | + "metadata": {}, |
| 276 | + "outputs": [], |
| 277 | + "source": [ |
| 278 | + "# plot turbine power output\n", |
253 | 279 | "if plt:\n", |
254 | 280 | " e126.power_output.plot(legend=True, label='Enercon E126')\n", |
255 | | - " v90.power_output.plot(legend=True, label='Vestas V90')\n", |
256 | | - " plt.show()\n", |
257 | | - "else:\n", |
258 | | - " print(e126.power_output)\n", |
259 | | - " print(v90.power_output)\n", |
260 | | - "\n", |
261 | | - "# Plot power (coefficient) curves\n", |
| 281 | + " my_turbine.power_output.plot(legend=True, label='myTurbine')\n", |
| 282 | + " plt.show()" |
| 283 | + ] |
| 284 | + }, |
| 285 | + { |
| 286 | + "cell_type": "code", |
| 287 | + "execution_count": null, |
| 288 | + "metadata": { |
| 289 | + "collapsed": true |
| 290 | + }, |
| 291 | + "outputs": [], |
| 292 | + "source": [ |
| 293 | + "# plot power (coefficient) curves\n", |
262 | 294 | "if plt:\n", |
263 | 295 | " if e126.cp_values is not None:\n", |
264 | 296 | " e126.cp_values.plot(style='*', title='Enercon E126')\n", |
265 | 297 | " plt.show()\n", |
266 | 298 | " if e126.p_values is not None:\n", |
267 | 299 | " e126.p_values.plot(style='*', title='Enercon E126')\n", |
268 | 300 | " plt.show()\n", |
269 | | - " if v90.cp_values is not None:\n", |
270 | | - " v90.cp_values.plot(style='*', title='Vestas V90')\n", |
| 301 | + " if my_turbine.cp_values is not None:\n", |
| 302 | + " my_turbine.cp_values.plot(style='*', title='myTurbine')\n", |
271 | 303 | " plt.show()\n", |
272 | | - " if v90.p_values is not None:\n", |
273 | | - " v90.p_values.plot(style='*', title='Vestas V90')\n", |
274 | | - " plt.show()\n", |
275 | | - "else:\n", |
276 | | - " if e126.cp_values is not None:\n", |
277 | | - " print(\"The cp value at a wind speed of 5 m/s: {0}\".format(\n", |
278 | | - " e126.cp_values.cp[5.0]))\n", |
279 | | - " if e126.p_values is not None:\n", |
280 | | - " print(\"The P value at a wind speed of 5 m/s: {0}\".format(\n", |
281 | | - " e126.p_values.P[5.0]))\n", |
282 | | - "logging.info('Done!')" |
| 304 | + " if my_turbine.p_values is not None:\n", |
| 305 | + " my_turbine.p_values.plot(style='*', title='myTurbine')\n", |
| 306 | + " plt.show()" |
283 | 307 | ] |
| 308 | + }, |
| 309 | + { |
| 310 | + "cell_type": "code", |
| 311 | + "execution_count": null, |
| 312 | + "metadata": { |
| 313 | + "collapsed": true |
| 314 | + }, |
| 315 | + "outputs": [], |
| 316 | + "source": [] |
284 | 317 | } |
285 | 318 | ], |
286 | 319 | "metadata": { |
|
0 commit comments