|
36 | 36 | "id": "bba9a869-8fbe-450e-8a16-9cff24613e73",
|
37 | 37 | "metadata": {},
|
38 | 38 | "outputs": [],
|
39 |
| - "source": [ |
40 |
| - "# !pip install solcast plotly\n", |
41 |
| - "# !pip install -U kaleido" |
42 |
| - ] |
| 39 | + "source": "# !pip install solcast plotly kaleido" |
43 | 40 | },
|
44 | 41 | {
|
45 | 42 | "cell_type": "code",
|
|
151 | 148 | " api_key: str,\n",
|
152 | 149 | "):\n",
|
153 | 150 | " pre_tuned = get_rooftop_data(\n",
|
154 |
| - " latitude, longitude, site_parameter_estimates, months, period, api_key\n", |
| 151 | + " latitude, longitude, site_parameter_estimates, months, PERIOD, api_key\n", |
155 | 152 | " ).tz_convert(None)\n",
|
156 | 153 | " pre_tuned.columns = [\"solcast_pretuned_estimate\"]\n",
|
157 | 154 | " return pre_tuned\n",
|
|
202 | 199 | " site_parameter_estimates[\"capacity\"],\n",
|
203 | 200 | " args=(\n",
|
204 | 201 | " est[\"pv_power_rooftop\"].loc[meas.index].values,\n",
|
205 |
| - " meas[power_column_name].values,\n", |
| 202 | + " meas[PV_POWER_COLUMN].values,\n", |
206 | 203 | " ),\n",
|
207 | 204 | " )\n",
|
208 | 205 | " capacity_est = np.round(res.x[0] * site_parameter_estimates[\"capacity\"], 0)\n",
|
|
346 | 343 | "id": "b881add6-c456-4955-96ea-3104af0a22a0",
|
347 | 344 | "metadata": {},
|
348 | 345 | "source": [
|
349 |
| - "## 1a: Input user Data" |
| 346 | + "## 1a: Input user Data\n", |
| 347 | + "\n", |
| 348 | + "Replace the variables in the following cell with your own values" |
350 | 349 | ]
|
351 | 350 | },
|
352 | 351 | {
|
|
356 | 355 | "metadata": {},
|
357 | 356 | "outputs": [],
|
358 | 357 | "source": [
|
359 |
| - "api_key = os.environ[\"API_KEY\"]\n", |
| 358 | + "API_KEY = os.environ[\"API_KEY\"]\n", |
360 | 359 | "measurement_data = pd.read_csv(\n",
|
361 | 360 | " \"https://solcast.github.io/solcast-api-python-sdk/notebooks/data/3.4_sample_measurements.csv\",\n",
|
362 | 361 | " index_col=[0],\n",
|
363 | 362 | " parse_dates=True,\n",
|
364 | 363 | ") # Make sure this is in kW\n",
|
365 |
| - "power_column_name = (\n", |
| 364 | + "PV_POWER_COLUMN = (\n", |
366 | 365 | " \"pv_power_rooftop\" # Set this to the name of the power column in measurement_data\n",
|
367 | 366 | ")\n",
|
368 |
| - "longitude = 151.215297\n", |
369 |
| - "latitude = -33.856784\n", |
370 |
| - "period = \"PT60M\"\n", |
| 367 | + "LONGITUDE = 151.215297\n", |
| 368 | + "LATITUDE = -33.856784\n", |
| 369 | + "PERIOD = \"PT60M\"\n", |
371 | 370 | "\n",
|
372 | 371 | "# Set this to true if User data is in local timezone and not UTC\n",
|
373 |
| - "local_timezone = False\n", |
| 372 | + "LOCAL_TIMEZONE = False\n", |
374 | 373 | "\n",
|
375 | 374 | "# Optional inputs. Only supply these if you have a high level of confidence they are close to the true value.\n",
|
376 |
| - "user_input_azi = None\n", |
377 |
| - "user_input_tilt = None\n", |
| 375 | + "USER_INPUT_AZI = None\n", |
| 376 | + "USER_INPUT_TILT = None\n", |
378 | 377 | "\n",
|
379 | 378 | "# Save output to csv?\n",
|
380 |
| - "save_to_csv = False" |
| 379 | + "SAVE_TO_CSV = False" |
381 | 380 | ]
|
382 | 381 | },
|
383 | 382 | {
|
|
397 | 396 | "source": [
|
398 | 397 | "# setup estimates\n",
|
399 | 398 | "site_parameter_estimates = {}\n",
|
400 |
| - "if user_input_azi is not None:\n", |
401 |
| - " site_parameter_estimates[\"azimuth\"] = user_input_azi\n", |
402 |
| - "if user_input_tilt is not None:\n", |
403 |
| - " site_parameter_estimates[\"tilt\"] = user_input_tilt" |
| 399 | + "if USER_INPUT_AZI is not None:\n", |
| 400 | + " site_parameter_estimates[\"azimuth\"] = USER_INPUT_AZI\n", |
| 401 | + "if USER_INPUT_TILT is not None:\n", |
| 402 | + " site_parameter_estimates[\"tilt\"] = USER_INPUT_TILT" |
404 | 403 | ]
|
405 | 404 | },
|
406 | 405 | {
|
|
419 | 418 | ],
|
420 | 419 | "source": [
|
421 | 420 | "# align to UTC if required\n",
|
422 |
| - "utc_offset = longitude // 15\n", |
| 421 | + "utc_offset = LONGITUDE // 15\n", |
423 | 422 | "utc_offset = pd.Timedelta(f\"{utc_offset}h\")\n",
|
424 |
| - "if local_timezone:\n", |
| 423 | + "if LOCAL_TIMEZONE:\n", |
425 | 424 | " measurement_data.index = measurement_data.index - utc_offset\n",
|
426 | 425 | "print(\n",
|
427 | 426 | " \"We estimate your UTC offset is \", utc_offset, \". You can update this if incorrect.\"\n",
|
|
450 | 449 | "source": [
|
451 | 450 | "# required for all grid searches\n",
|
452 | 451 | "KWARGS = {\n",
|
453 |
| - " \"latitude\": latitude,\n", |
454 |
| - " \"longitude\": longitude,\n", |
| 452 | + " \"latitude\": LATITUDE,\n", |
| 453 | + " \"longitude\": LONGITUDE,\n", |
455 | 454 | " \"meas\": measurement_data,\n",
|
456 | 455 | " \"months\": months,\n",
|
457 | 456 | " \"site_parameter_estimates\": site_parameter_estimates,\n",
|
458 |
| - " \"period\": period,\n", |
459 |
| - " \"api_key\": api_key,\n", |
| 457 | + " \"period\": PERIOD,\n", |
| 458 | + " \"api_key\": API_KEY,\n", |
460 | 459 | "}"
|
461 | 460 | ]
|
462 | 461 | },
|
|
543 | 542 | ],
|
544 | 543 | "source": [
|
545 | 544 | "# take an initial capacity estimate and show an initial estimation with no tuning\n",
|
546 |
| - "capacity_initial_estimate = measurement_data[power_column_name].max()\n", |
| 545 | + "capacity_initial_estimate = measurement_data[PV_POWER_COLUMN].max()\n", |
547 | 546 | "site_parameter_estimates[\"capacity\"] = capacity_initial_estimate\n",
|
548 | 547 | "\n",
|
549 | 548 | "pre_tuned = get_solcast_untuned(\n",
|
550 |
| - " latitude, longitude, site_parameter_estimates, months, api_key\n", |
| 549 | + " LATITUDE, LONGITUDE, site_parameter_estimates, months, API_KEY\n", |
551 | 550 | ")\n",
|
552 | 551 | "display_evaluation_plots(measurement_data, pre_tuned)"
|
553 | 552 | ]
|
|
767 | 766 | }
|
768 | 767 | ],
|
769 | 768 | "source": [
|
770 |
| - "if user_input_azi is None:\n", |
| 769 | + "if USER_INPUT_AZI is None:\n", |
771 | 770 | " # Use these defaults or update the range if you prefer\n",
|
772 | 771 | " initial_azi_min = -180\n",
|
773 | 772 | " initial_azi_max = 180\n",
|
774 | 773 | " azi_delta = 45\n",
|
775 | 774 | "else:\n",
|
776 | 775 | " azi_delta = 45\n",
|
777 |
| - " initial_azi_min = user_input_azi - azi_delta\n", |
778 |
| - " initial_azi_max = user_input_azi + azi_delta\n", |
| 776 | + " initial_azi_min = USER_INPUT_AZI - azi_delta\n", |
| 777 | + " initial_azi_max = USER_INPUT_AZI + azi_delta\n", |
779 | 778 | "\n",
|
780 | 779 | "# Initial wide search\n",
|
781 | 780 | "initial_azimuth_search = np.arange(\n",
|
|
962 | 961 | }
|
963 | 962 | ],
|
964 | 963 | "source": [
|
965 |
| - "if user_input_tilt is None:\n", |
| 964 | + "if USER_INPUT_TILT is None:\n", |
966 | 965 | " # Use these defaults or update the range if you prefer\n",
|
967 | 966 | " initial_tilt_min = 0\n",
|
968 | 967 | " initial_tilt_max = 90\n",
|
969 | 968 | " tilt_delta = 10\n",
|
970 | 969 | "else:\n",
|
971 | 970 | " tilt_delta = 10\n",
|
972 |
| - " initial_tilt_min = user_input_tilt - tilt_delta\n", |
973 |
| - " initial_tilt_max = user_input_tilt + tilt_delta\n", |
| 971 | + " initial_tilt_min = USER_INPUT_TILT - tilt_delta\n", |
| 972 | + " initial_tilt_max = USER_INPUT_TILT + tilt_delta\n", |
974 | 973 | "\n",
|
975 | 974 | "\n",
|
976 | 975 | "# Initial wide search\n",
|
|
1189 | 1188 | ],
|
1190 | 1189 | "source": [
|
1191 | 1190 | "est_final = get_rooftop_data(\n",
|
1192 |
| - " latitude, longitude, site_parameter_estimates, months, period, api_key\n", |
| 1191 | + " LATITUDE, LONGITUDE, site_parameter_estimates, months, PERIOD, API_KEY\n", |
1193 | 1192 | ").tz_convert(None)[\"pv_power_rooftop\"]\n",
|
1194 | 1193 | "\n",
|
1195 | 1194 | "est_df = pd.DataFrame(\n",
|
1196 | 1195 | " data={\n",
|
1197 |
| - " \"meas\": measurement_data[power_column_name],\n", |
| 1196 | + " \"meas\": measurement_data[PV_POWER_COLUMN],\n", |
1198 | 1197 | " \"solcast_estimate\": est_final,\n",
|
1199 | 1198 | " \"solcast_pre_tuned\": pre_tuned[\"solcast_pretuned_estimate\"],\n",
|
1200 | 1199 | " },\n",
|
1201 | 1200 | " index=measurement_data.index,\n",
|
1202 | 1201 | ")\n",
|
1203 |
| - "if save_to_csv:\n", |
| 1202 | + "if SAVE_TO_CSV:\n", |
1204 | 1203 | " est_df.to_csv(\"Solcast_Tuned_Rooftop_PV.csv\")\n",
|
1205 | 1204 | "\n",
|
1206 | 1205 | "print(\"Tuned Parameter Estimates:\", site_parameter_estimates)\n",
|
1207 | 1206 | "\n",
|
1208 |
| - "results = calculate_stats(measurement_data[power_column_name], est_final, df=True)\n", |
| 1207 | + "results = calculate_stats(measurement_data[PV_POWER_COLUMN], est_final, df=True)\n", |
1209 | 1208 | "display_evaluation_plots(meas=measurement_data, est=est_final, untuned=pre_tuned)"
|
1210 | 1209 | ]
|
1211 | 1210 | }
|
|
0 commit comments