7171 {
7272 "cell_type" : " code" ,
7373 "execution_count" : null ,
74- "metadata" : {
75- "collapsed" : true
76- },
74+ "metadata" : {},
7775 "outputs" : [],
7876 "source" : [
79- " def read_weather_data(filename, datetime_column='time_index',\n " ,
80- " **kwargs):\n " ,
77+ " def get_weather_data(filename='weather.csv', **kwargs):\n " ,
8178 " r\"\"\"\n " ,
82- " Fetches weather data from a file.\n " ,
79+ " Imports weather data from a file.\n " ,
8380 " \n " ,
84- " The files are located in the example folder of the windpowerlib.\n " ,
81+ " The data include wind speed at two different heights in m/s, air\n " ,
82+ " temperature in two different heights in K, surface roughness length in m\n " ,
83+ " and air pressure in Pa. The file is located in the example folder of the\n " ,
84+ " windpowerlib. The height in m for which the data applies is specified in\n " ,
85+ " the second row.\n " ,
8586 " \n " ,
8687 " Parameters\n " ,
8788 " ----------\n " ,
8889 " filename : string\n " ,
89- " Filename of the weather data file.\n " ,
90- " datetime_column : string\n " ,
91- " Name of the datetime column of the weather DataFrame.\n " ,
90+ " Filename of the weather data file. Default: 'weather.csv'.\n " ,
9291 " \n " ,
9392 " Other Parameters\n " ,
9493 " ----------------\n " ,
9897 " \n " ,
9998 " Returns\n " ,
10099 " -------\n " ,
101- " pandas.DataFrame\n " ,
102- " Contains weather data time series.\n " ,
100+ " weather_df : pandas.DataFrame\n " ,
101+ " DataFrame with time series for wind speed `wind_speed` in m/s,\n " ,
102+ " temperature `temperature` in K, roughness length `roughness_length`\n " ,
103+ " in m, and pressure `pressure` in Pa.\n " ,
104+ " The columns of the DataFrame are a MultiIndex where the first level\n " ,
105+ " contains the variable name (e.g. wind_speed) and the second level\n " ,
106+ " contains the height at which it applies (e.g. 10, if it was\n " ,
107+ " measured at a height of 10 m).\n " ,
103108 " \n " ,
104109 " \"\"\"\n " ,
110+ " \n " ,
105111 " if 'datapath' not in kwargs:\n " ,
106112 " kwargs['datapath'] = os.path.join(os.path.split(\n " ,
107113 " os.path.dirname(__file__))[0], 'example')\n " ,
108- " \n " ,
109114 " file = os.path.join(kwargs['datapath'], filename)\n " ,
110- " df = pd.read_csv(file)\n " ,
111- " return df.set_index(pd.to_datetime(df[datetime_column])).tz_localize(\n " ,
112- " 'UTC').tz_convert('Europe/Berlin').drop(datetime_column, 1)\n " ,
115+ " # read csv file \n " ,
116+ " weather_df = pd.read_csv(file, index_col=0, header=[0, 1])\n " ,
117+ " # change type of index to datetime and set time zone\n " ,
118+ " weather_df.index = pd.to_datetime(weather_df.index).tz_localize(\n " ,
119+ " 'UTC').tz_convert('Europe/Berlin')\n " ,
120+ " # change type of height from str to int by resetting columns\n " ,
121+ " weather_df.columns = [weather_df.axes[1].levels[0][\n " ,
122+ " weather_df.axes[1].labels[0]],\n " ,
123+ " weather_df.axes[1].levels[1][\n " ,
124+ " weather_df.axes[1].labels[1]].astype(int)]\n " ,
125+ " return weather_df\n " ,
113126 " \n " ,
114127 " \n " ,
115128 " # Read weather data from csv\n " ,
116- " weather = read_weather_data(filename='weather.csv', datapath='')"
117- ]
118- },
119- {
120- "cell_type" : " markdown" ,
121- "metadata" : {},
122- "source" : [
123- " Along with the weather data you have to provide a dataframe or dictionary specifying the height for which the data applies."
124- ]
125- },
126- {
127- "cell_type" : " code" ,
128- "execution_count" : null ,
129- "metadata" : {
130- "collapsed" : true
131- },
132- "outputs" : [],
133- "source" : [
134- " # height in meters\n " ,
135- " data_height = {\n " ,
136- " 'pressure': 0,\n " ,
137- " 'temp_air': 2,\n " ,
138- " 'v_wind': 10,\n " ,
139- " 'temp_air_2': 10,\n " ,
140- " 'v_wind_2': 80}"
129+ " weather = get_weather_data(filename='weather.csv', datapath='')\n " ,
130+ " print(weather[['wind_speed', 'temperature', 'pressure']][0:3])"
141131 ]
142132 },
143133 {
180170 {
181171 "cell_type" : " code" ,
182172 "execution_count" : null ,
183- "metadata" : {
184- "collapsed" : true
185- },
173+ "metadata" : {},
186174 "outputs" : [],
187175 "source" : [
188176 " # specification of own wind turbine (Note: power coefficient values and\n " ,
192180 " 'nominal_power': 3e6, # in W\n " ,
193181 " 'hub_height': 105, # in m\n " ,
194182 " 'rotor_diameter': 90, # in m\n " ,
195- " 'p_values': pd.DataFrame (\n " ,
196- " data={'p': [p * 1000 for p in\n " ,
197- " [ 0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]]} , # in W\n " ,
183+ " 'p_values': pd.Series (\n " ,
184+ " data=[p * 1000 for p in [ \n " ,
185+ " 0.0, 26.0, 180.0, 1500.0, 3000.0, 3000.0]], # in W\n " ,
198186 " index=[0.0, 3.0, 5.0, 10.0, 15.0, 25.0]) # in m/s\n " ,
199187 " } \n " ,
200188 " # initialise WindTurbine object\n " ,
239227 " # power output calculation for my_turbine\n " ,
240228 " # initialise ModelChain with default parameters and use run_model\n " ,
241229 " # method to calculate power output\n " ,
242- " mc_my_turbine = modelchain.ModelChain(my_turbine).run_model(\n " ,
243- " weather, data_height)\n " ,
230+ " mc_my_turbine = modelchain.ModelChain(my_turbine).run_model(weather)\n " ,
244231 " # write power output timeseries to WindTurbine object\n " ,
245232 " my_turbine.power_output = mc_my_turbine.power_output"
246233 ]
254241 " # power output calculation for e126\n " ,
255242 " # own specifications for ModelChain setup\n " ,
256243 " modelchain_data = {\n " ,
257- " 'obstacle_height': 0, # default: 0\n " ,
258- " 'wind_model': 'logarithmic', # 'logarithmic' (default) or 'hellman'\n " ,
259- " 'rho_model': 'ideal_gas', # 'barometric' (default) or 'ideal_gas'\n " ,
260- " 'power_output_model': 'p_values', # 'p_values' (default) or 'cp_values'\n " ,
261- " 'density_corr': True, # False (default) or True\n " ,
262- " 'hellman_exp': None} # None (default) or None\n " ,
244+ " 'obstacle_height': 0, # default: 0\n " ,
245+ " 'wind_speed_model': 'logarithmic', # 'logarithmic' (default),\n " ,
246+ " # 'hellman' or\n " ,
247+ " # 'interpolation_extrapolation'\n " ,
248+ " 'density_model': 'ideal_gas', # 'barometric' (default) or 'ideal_gas'\n " ,
249+ " 'temperature_model': 'linear_gradient', # 'linear_gradient' (def.) or\n " ,
250+ " # 'interpolation_extrapolation'\n " ,
251+ " 'power_output_model': 'power_curve', # 'power_curve' (default) or\n " ,
252+ " # 'power_coefficient_curve'\n " ,
253+ " 'density_correction': True, # False (default) or True\n " ,
254+ " 'hellman_exp': None} # None (default) or None\n " ,
255+ " \n " ,
263256 " # initialise ModelChain with own specifications and use run_model method to\n " ,
264257 " # calculate power output\n " ,
265258 " mc_e126 = modelchain.ModelChain(e126, **modelchain_data).run_model(\n " ,
266- " weather, data_height )\n " ,
259+ " weather)\n " ,
267260 " # write power output timeseries to WindTurbine object\n " ,
268261 " e126.power_output = mc_e126.power_output"
269262 ]
328321 " my_turbine.p_values.plot(style='*', title='myTurbine')\n " ,
329322 " plt.show()"
330323 ]
324+ },
325+ {
326+ "cell_type" : " code" ,
327+ "execution_count" : null ,
328+ "metadata" : {
329+ "collapsed" : true
330+ },
331+ "outputs" : [],
332+ "source" : []
331333 }
332334 ],
333335 "metadata" : {
339341 "language_info" : {
340342 "codemirror_mode" : {
341343 "name" : " ipython" ,
342- "version" : 3.0
344+ "version" : 3
343345 },
344346 "file_extension" : " .py" ,
345347 "mimetype" : " text/x-python" ,
350352 }
351353 },
352354 "nbformat" : 4 ,
353- "nbformat_minor" : 0
354- }
355+ "nbformat_minor" : 1
356+ }
0 commit comments