From 42d190b56fb6b9e68b99b703c7f1a9c0fe89d503 Mon Sep 17 00:00:00 2001 From: Maxime Charriere <51918753+maximecharriere@users.noreply.github.com> Date: Fri, 30 Aug 2024 23:52:30 +0200 Subject: [PATCH] Update --- 00_Scripts/SolarClique_implementation.ipynb | 178 ++++++++++---------- 1 file changed, 91 insertions(+), 87 deletions(-) diff --git a/00_Scripts/SolarClique_implementation.ipynb b/00_Scripts/SolarClique_implementation.ipynb index 1907571..6cf773e 100644 --- a/00_Scripts/SolarClique_implementation.ipynb +++ b/00_Scripts/SolarClique_implementation.ipynb @@ -1956,101 +1956,86 @@ ] }, { - "cell_type": "raw", - "metadata": { - "vscode": { - "languageId": "raw" - } - }, + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "selected_system = 'a001267'\n", + "\n", + "# Prepare the measured data\n", + "measuredDailyEnergy = systemsData_MeasuredDailyEnergy[selected_system].dropna()\n", + "\n", + "# Anomalies (manipulated data)\n", + "colors = pd.Series(index=measuredDailyEnergy.index, data=\"DarkTurquoise\", name='Anomalies')\n", + "colors.loc[['2024-05-24', '2024-06-26']] = 'red'\n", + "\n", + "measuredDailyEnergy.loc['2024-05-24'] *= 0.8\n", + "measuredDailyEnergy.loc['2024-06-26'] *= 0.1\n", + "\n", + "\n", "fig1 = go.Figure(layout_yaxis_title=\"Daily Energy (kWh)\")\n", "\n", "# remove nan from systemsData_EstimatedMaxDailyEnergy[selected_system]\n", "\n", - "first_trace = True\n", - "\n", - "for start_date, value in pv_gis_pred_a001267_april_july.items():\n", - " end_date = (pd.to_datetime(start_date) + pd.DateOffset(months=1) - pd.DateOffset(days=1)).strftime('%Y-%m-%d')\n", - " fig1.add_trace(go.Scatter(\n", - " x=[start_date, end_date],\n", - " y=[value, value],\n", - " mode='lines',\n", - " name='Actual Prediction from PV GIS' if first_trace else '',\n", - " line=dict(color='yellow'),\n", - " showlegend=first_trace # Only show legend for the first trace\n", - " ))\n", - " first_trace = False\n", - "\n", - "try:\n", - " estimatedMaxDailyEnergy = normalizer_estimated_max_daily_energy[selected_system].dropna()\n", - " fig1.add_trace(go.Scatter(\n", - " x=estimatedMaxDailyEnergy.index,\n", - " y=estimatedMaxDailyEnergy,\n", - " mode='lines',\n", - " name='Estimated Max Daily Energy',\n", - " marker_color='LightSeaGreen'\n", - " ))\n", - "except:\n", - " pass\n", - "\n", - "try:\n", - " measuredDailyEnergy = systemsData_MeasuredDailyEnergy[selected_system].dropna()\n", - " measuredDailyEnergy.loc['2024-05-24'] *= 0.8\n", - " measuredDailyEnergy.loc['2024-06-26'] *= 0.1\n", - " fig1.add_trace(go.Bar(\n", - " x=measuredDailyEnergy.index,\n", - " y=measuredDailyEnergy,\n", - " # mode='markers',\n", - " name='Measured Daily Energy',\n", - " marker_color='blue'\n", - " ))\n", - "except:\n", - " pass\n", + "# first_trace = True\n", "\n", - "fig1.add_trace(go.Scatter(x=['2024-05-24','2024-06-26'],y=[measuredDailyEnergy.loc['2024-05-24'],measuredDailyEnergy.loc['2024-06-26']],mode='markers',name='Detected Anomalies',marker_color='lightgreen'))\n", - "# try:\n", - "# measuredDailyEnergy_train_outliers = systemsData_MeasuredDailyEnergy_train_outliers[selected_system].dropna()\n", + "# for start_date, value in pv_gis_pred_a001267_april_july.items():\n", + "# end_date = (pd.to_datetime(start_date) + pd.DateOffset(months=1) - pd.DateOffset(days=1)).strftime('%Y-%m-%d')\n", "# fig1.add_trace(go.Scatter(\n", - "# x=measuredDailyEnergy_train_outliers.index,\n", - "# y=measuredDailyEnergy_train_outliers,\n", - "# mode='markers',\n", - "# name='Outliers',\n", - "# marker_color='yellow'\n", + "# x=[start_date, end_date],\n", + "# y=[value, value],\n", + "# mode='lines',\n", + "# name='Actual Prediction from PV GIS' if first_trace else '',\n", + "# line=dict(color='yellow'),\n", + "# showlegend=first_trace # Only show legend for the first trace\n", "# ))\n", - "# except:\n", - "# pass\n", - "# try:\n", - "# expectedDailyEnergy_train = systemsData_ExpectedDailyEnergy_train[selected_system].dropna()\n", - "# fig1.add_trace(go.Scatter(\n", - "# x=expectedDailyEnergy_train.index,\n", - "# y=expectedDailyEnergy_train,\n", - "# mode='markers',\n", - "# name='Expected Daily Energy',\n", - "# marker_color='red'\n", - "# ))\n", - "# except:\n", - "# pass\n", - "\n", - "try:\n", - " expectedDailyEnergy_test_mean = systemsData_ExpectedDailyEnergy_test_mean[selected_system].dropna()\n", - " expectedDailyEnergy_test_std = systemsData_ExpectedDailyEnergy_test_std[selected_system].dropna()\n", - " fig1.add_trace(go.Bar(\n", - " x=expectedDailyEnergy_test_mean.index,\n", - " y=expectedDailyEnergy_test_mean,\n", - " # mode='markers',\n", - " name='Expected Daily Energy',\n", - " marker_color='red',\n", - " error_y=dict(\n", - " type='data',\n", - " array=expectedDailyEnergy_test_std*1.65,\n", - " visible=True,\n", - " thickness = 1.5,\n", - " width=4\n", - " )\n", - " ))\n", - "except:\n", - " pass\n", + "# first_trace = False\n", + "\n", + "estimatedMaxDailyEnergy = normalizer_estimated_max_daily_energy[selected_system].dropna()\n", + "fig1.add_trace(go.Scatter(\n", + " x=estimatedMaxDailyEnergy.index,\n", + " y=estimatedMaxDailyEnergy,\n", + " mode='lines',\n", + " name='Estimated Production',\n", + " marker_color='orange'\n", + "))\n", + "\n", + "\n", + "# Add normal data trace\n", + "fig1.add_trace(go.Bar(\n", + " x=measuredDailyEnergy.index,\n", + " y=measuredDailyEnergy,\n", + " name='Measured Production',\n", + " marker_color=colors\n", + "))\n", + "fig1.add_trace(go.Scatter(\n", + " x=[None], y=[None],\n", + " mode='markers',\n", + " name='Detected Anomalies',\n", + " marker_color='red',\n", + " showlegend=True\n", + "))\n", + "\n", + "\n", + "expectedDailyEnergy_test_mean = systemsData_ExpectedDailyEnergy_test_mean[selected_system].dropna()\n", + "expectedDailyEnergy_test_std = systemsData_ExpectedDailyEnergy_test_std[selected_system].dropna()\n", + "fig1.add_trace(go.Bar(\n", + " x=expectedDailyEnergy_test_mean.index,\n", + " y=expectedDailyEnergy_test_mean,\n", + " # mode='markers',\n", + " name='Expected Daily Energy',\n", + " # color in fec214\n", + " marker_color='rgb(254, 194, 20)',\n", + " error_y=dict(\n", + " type='data',\n", + " array=expectedDailyEnergy_test_std*1.65,\n", + " visible=True,\n", + " thickness = 1.5,\n", + " width=4\n", + " )\n", + "))\n", + "\n", "\n", "# Update layout for legend position\n", "fig1.update_layout(\n", @@ -2062,9 +2047,28 @@ " orientation='h'\n", " )\n", ")\n", + "\n", "#set size to 1000x666\n", "fig1.update_layout(width=1000, height=666)\n", - "fig1.show()" + "\n", + "\n", + "\n", + "config = {\n", + " 'toImageButtonOptions': {\n", + " 'format': 'png', # one of png, svg, jpeg, webp\n", + " 'filename': 'custom_image',\n", + " 'height': 666,\n", + " 'width': 1000,\n", + " 'scale':6 # Multiply title/legend/axis/canvas sizes by this factor\n", + " }\n", + "}\n", + "\n", + "\n", + "fig1.show(config=config)\n", + "\n", + "\n", + "\n", + "\n" ] }, {