Skip to content

Commit

Permalink
feat: add more noise to rooftop example
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugh Cutcher committed Sep 20, 2024
1 parent 6b3af85 commit 2c4a407
Show file tree
Hide file tree
Showing 2 changed files with 1,466 additions and 1,467 deletions.
75 changes: 37 additions & 38 deletions docs/notebooks/3.4 Rooftop PV Tuning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
"id": "bba9a869-8fbe-450e-8a16-9cff24613e73",
"metadata": {},
"outputs": [],
"source": [
"# !pip install solcast plotly\n",
"# !pip install -U kaleido"
]
"source": "# !pip install solcast plotly kaleido"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -151,7 +148,7 @@
" api_key: str,\n",
"):\n",
" pre_tuned = get_rooftop_data(\n",
" latitude, longitude, site_parameter_estimates, months, period, api_key\n",
" latitude, longitude, site_parameter_estimates, months, PERIOD, api_key\n",
" ).tz_convert(None)\n",
" pre_tuned.columns = [\"solcast_pretuned_estimate\"]\n",
" return pre_tuned\n",
Expand Down Expand Up @@ -202,7 +199,7 @@
" site_parameter_estimates[\"capacity\"],\n",
" args=(\n",
" est[\"pv_power_rooftop\"].loc[meas.index].values,\n",
" meas[power_column_name].values,\n",
" meas[PV_POWER_COLUMN].values,\n",
" ),\n",
" )\n",
" capacity_est = np.round(res.x[0] * site_parameter_estimates[\"capacity\"], 0)\n",
Expand Down Expand Up @@ -346,7 +343,9 @@
"id": "b881add6-c456-4955-96ea-3104af0a22a0",
"metadata": {},
"source": [
"## 1a: Input user Data"
"## 1a: Input user Data\n",
"\n",
"Replace the variables in the following cell with your own values"
]
},
{
Expand All @@ -356,28 +355,28 @@
"metadata": {},
"outputs": [],
"source": [
"api_key = os.environ[\"API_KEY\"]\n",
"API_KEY = os.environ[\"API_KEY\"]\n",
"measurement_data = pd.read_csv(\n",
" \"https://solcast.github.io/solcast-api-python-sdk/notebooks/data/3.4_sample_measurements.csv\",\n",
" index_col=[0],\n",
" parse_dates=True,\n",
") # Make sure this is in kW\n",
"power_column_name = (\n",
"PV_POWER_COLUMN = (\n",
" \"pv_power_rooftop\" # Set this to the name of the power column in measurement_data\n",
")\n",
"longitude = 151.215297\n",
"latitude = -33.856784\n",
"period = \"PT60M\"\n",
"LONGITUDE = 151.215297\n",
"LATITUDE = -33.856784\n",
"PERIOD = \"PT60M\"\n",
"\n",
"# Set this to true if User data is in local timezone and not UTC\n",
"local_timezone = False\n",
"LOCAL_TIMEZONE = False\n",
"\n",
"# Optional inputs. Only supply these if you have a high level of confidence they are close to the true value.\n",
"user_input_azi = None\n",
"user_input_tilt = None\n",
"USER_INPUT_AZI = None\n",
"USER_INPUT_TILT = None\n",
"\n",
"# Save output to csv?\n",
"save_to_csv = False"
"SAVE_TO_CSV = False"
]
},
{
Expand All @@ -397,10 +396,10 @@
"source": [
"# setup estimates\n",
"site_parameter_estimates = {}\n",
"if user_input_azi is not None:\n",
" site_parameter_estimates[\"azimuth\"] = user_input_azi\n",
"if user_input_tilt is not None:\n",
" site_parameter_estimates[\"tilt\"] = user_input_tilt"
"if USER_INPUT_AZI is not None:\n",
" site_parameter_estimates[\"azimuth\"] = USER_INPUT_AZI\n",
"if USER_INPUT_TILT is not None:\n",
" site_parameter_estimates[\"tilt\"] = USER_INPUT_TILT"
]
},
{
Expand All @@ -419,9 +418,9 @@
],
"source": [
"# align to UTC if required\n",
"utc_offset = longitude // 15\n",
"utc_offset = LONGITUDE // 15\n",
"utc_offset = pd.Timedelta(f\"{utc_offset}h\")\n",
"if local_timezone:\n",
"if LOCAL_TIMEZONE:\n",
" measurement_data.index = measurement_data.index - utc_offset\n",
"print(\n",
" \"We estimate your UTC offset is \", utc_offset, \". You can update this if incorrect.\"\n",
Expand Down Expand Up @@ -450,13 +449,13 @@
"source": [
"# required for all grid searches\n",
"KWARGS = {\n",
" \"latitude\": latitude,\n",
" \"longitude\": longitude,\n",
" \"latitude\": LATITUDE,\n",
" \"longitude\": LONGITUDE,\n",
" \"meas\": measurement_data,\n",
" \"months\": months,\n",
" \"site_parameter_estimates\": site_parameter_estimates,\n",
" \"period\": period,\n",
" \"api_key\": api_key,\n",
" \"period\": PERIOD,\n",
" \"api_key\": API_KEY,\n",
"}"
]
},
Expand Down Expand Up @@ -543,11 +542,11 @@
],
"source": [
"# take an initial capacity estimate and show an initial estimation with no tuning\n",
"capacity_initial_estimate = measurement_data[power_column_name].max()\n",
"capacity_initial_estimate = measurement_data[PV_POWER_COLUMN].max()\n",
"site_parameter_estimates[\"capacity\"] = capacity_initial_estimate\n",
"\n",
"pre_tuned = get_solcast_untuned(\n",
" latitude, longitude, site_parameter_estimates, months, api_key\n",
" LATITUDE, LONGITUDE, site_parameter_estimates, months, API_KEY\n",
")\n",
"display_evaluation_plots(measurement_data, pre_tuned)"
]
Expand Down Expand Up @@ -767,15 +766,15 @@
}
],
"source": [
"if user_input_azi is None:\n",
"if USER_INPUT_AZI is None:\n",
" # Use these defaults or update the range if you prefer\n",
" initial_azi_min = -180\n",
" initial_azi_max = 180\n",
" azi_delta = 45\n",
"else:\n",
" azi_delta = 45\n",
" initial_azi_min = user_input_azi - azi_delta\n",
" initial_azi_max = user_input_azi + azi_delta\n",
" initial_azi_min = USER_INPUT_AZI - azi_delta\n",
" initial_azi_max = USER_INPUT_AZI + azi_delta\n",
"\n",
"# Initial wide search\n",
"initial_azimuth_search = np.arange(\n",
Expand Down Expand Up @@ -962,15 +961,15 @@
}
],
"source": [
"if user_input_tilt is None:\n",
"if USER_INPUT_TILT is None:\n",
" # Use these defaults or update the range if you prefer\n",
" initial_tilt_min = 0\n",
" initial_tilt_max = 90\n",
" tilt_delta = 10\n",
"else:\n",
" tilt_delta = 10\n",
" initial_tilt_min = user_input_tilt - tilt_delta\n",
" initial_tilt_max = user_input_tilt + tilt_delta\n",
" initial_tilt_min = USER_INPUT_TILT - tilt_delta\n",
" initial_tilt_max = USER_INPUT_TILT + tilt_delta\n",
"\n",
"\n",
"# Initial wide search\n",
Expand Down Expand Up @@ -1189,23 +1188,23 @@
],
"source": [
"est_final = get_rooftop_data(\n",
" latitude, longitude, site_parameter_estimates, months, period, api_key\n",
" LATITUDE, LONGITUDE, site_parameter_estimates, months, PERIOD, API_KEY\n",
").tz_convert(None)[\"pv_power_rooftop\"]\n",
"\n",
"est_df = pd.DataFrame(\n",
" data={\n",
" \"meas\": measurement_data[power_column_name],\n",
" \"meas\": measurement_data[PV_POWER_COLUMN],\n",
" \"solcast_estimate\": est_final,\n",
" \"solcast_pre_tuned\": pre_tuned[\"solcast_pretuned_estimate\"],\n",
" },\n",
" index=measurement_data.index,\n",
")\n",
"if save_to_csv:\n",
"if SAVE_TO_CSV:\n",
" est_df.to_csv(\"Solcast_Tuned_Rooftop_PV.csv\")\n",
"\n",
"print(\"Tuned Parameter Estimates:\", site_parameter_estimates)\n",
"\n",
"results = calculate_stats(measurement_data[power_column_name], est_final, df=True)\n",
"results = calculate_stats(measurement_data[PV_POWER_COLUMN], est_final, df=True)\n",
"display_evaluation_plots(meas=measurement_data, est=est_final, untuned=pre_tuned)"
]
}
Expand Down
Loading

0 comments on commit 2c4a407

Please sign in to comment.