Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -313,7 +313,7 @@ elif section == 'Forecasts':
|
|
| 313 |
operation_forecast_res.columns = [col.replace('_entsoe.', '_').replace('Naive.1D', 'DailyNaiveSeasonal') for col in operation_forecast_res.columns]
|
| 314 |
Historical_and_Load=add_feature(operation_forecast_load, historical_forecast)
|
| 315 |
Historical_and_operational=add_feature(operation_forecast_res, Historical_and_Load)
|
| 316 |
-
|
| 317 |
best_forecast = Historical_and_operational.filter(like='Forecast_elia', axis=1)
|
| 318 |
df_combined = Historical_and_operational.join(Data_BE, how='inner')
|
| 319 |
last_week_best_forecast = best_forecast.loc[best_forecast.index >= (best_forecast.index[-24] - pd.Timedelta(days=8))]
|
|
@@ -505,7 +505,6 @@ elif section == 'Forecasts':
|
|
| 505 |
model_mae = calculate_mae(aligned_actual_values, aligned_model_predictions)
|
| 506 |
# Calculate MAE for the entsoe forecast
|
| 507 |
entsoe_forecast = real_values_df[f'{category_prefix}_forecast_entsoe'].loc[common_indices]
|
| 508 |
-
#print(entsoe_forecast.index)
|
| 509 |
entsoe_mae = calculate_mae(aligned_actual_values, entsoe_forecast)
|
| 510 |
# Calculate MAE ratio
|
| 511 |
mae_ratio = model_mae / entsoe_mae
|
|
@@ -559,13 +558,10 @@ elif section == 'Forecasts':
|
|
| 559 |
hours_with_data = []
|
| 560 |
mae_ratios = []
|
| 561 |
|
| 562 |
-
#print(f"Processing {model_key}...") # Debugging print
|
| 563 |
-
|
| 564 |
for hour in hours:
|
| 565 |
file_name = f'Predictions_{hour}h.csv'
|
| 566 |
df = df_dict.get(file_name, None)
|
| 567 |
if df is None:
|
| 568 |
-
#print(f"No data for hour {hour}. Skipping...")
|
| 569 |
continue
|
| 570 |
|
| 571 |
if isinstance(df.index, pd.DatetimeIndex):
|
|
@@ -596,7 +592,6 @@ elif section == 'Forecasts':
|
|
| 596 |
hours_with_data.append(hour)
|
| 597 |
|
| 598 |
if mae_ratios:
|
| 599 |
-
print(f"Adding {model_key} to the plot with {len(mae_ratios)} points.") # Debugging print
|
| 600 |
fig.add_trace(go.Scatterpolar(
|
| 601 |
r=mae_ratios + [mae_ratios[0]], # Ensure closure of the polar plot
|
| 602 |
theta=[h * 15 for h in hours_with_data] + [0], # Ensure closure at 0 degrees
|
|
@@ -623,36 +618,6 @@ elif section == 'Forecasts':
|
|
| 623 |
|
| 624 |
|
| 625 |
if country_code == "BE":
|
| 626 |
-
#-------------------------------------------------
|
| 627 |
-
#st.header('EDS Forecasts by Hour')
|
| 628 |
-
|
| 629 |
-
#solar_fig = plot_category(forecast_dict, 'Solar', 'Solar Predictions')
|
| 630 |
-
#st.plotly_chart(solar_fig)
|
| 631 |
-
|
| 632 |
-
#wind_offshore_fig = plot_category(forecast_dict, 'Wind_offshore', 'Wind Offshore Predictions')
|
| 633 |
-
#st.plotly_chart(wind_offshore_fig)
|
| 634 |
-
|
| 635 |
-
#wind_onshore_fig = plot_category(forecast_dict, 'Wind_onshore', 'Wind Onshore Predictions')
|
| 636 |
-
#st.plotly_chart(wind_onshore_fig)
|
| 637 |
-
|
| 638 |
-
#load_fig = plot_category(forecast_dict, 'Load', 'Load Predictions')
|
| 639 |
-
#st.plotly_chart(load_fig)
|
| 640 |
-
|
| 641 |
-
#-------------------------------------------------
|
| 642 |
-
#st.header('MAE Ratio Comparison by Forecast Hour')
|
| 643 |
-
#st.write("This graph shows the relative Mean Absolute Error (rMAE) of different forecasting models "
|
| 644 |
-
#"compared to the ENTSO-E forecast, by the hour at which the forecast was made. "
|
| 645 |
-
#"The rMAE is calculated as the ratio of the model's MAE to the ENTSO-E forecast's MAE.")
|
| 646 |
-
#mae_comparison_fig = plot_mae_comparison(forecast_dict, 'Solar', 'rMAE Ratio Comparison for Solar', real_values_df=Data_BE)
|
| 647 |
-
#st.plotly_chart(mae_comparison_fig)
|
| 648 |
-
# Similarly for Wind_onshore, Wind_offshore, and Load
|
| 649 |
-
#mae_comparison_fig_wind_onshore = plot_mae_comparison(forecast_dict, 'Wind_onshore', 'MAE Ratio Comparison for Wind Onshore', real_values_df=Data_BE)
|
| 650 |
-
#st.plotly_chart(mae_comparison_fig_wind_onshore)
|
| 651 |
-
#mae_comparison_fig_wind_offshore = plot_mae_comparison(forecast_dict, 'Wind_offshore', 'MAE Ratio Comparison for Wind Offshore', real_values_df=Data_BE)
|
| 652 |
-
#st.plotly_chart(mae_comparison_fig_wind_offshore)
|
| 653 |
-
#mae_comparison_fig_load = plot_mae_comparison(forecast_dict, 'Load', 'MAE Ratio Comparison for Load', real_values_df=Data_BE)
|
| 654 |
-
#st.plotly_chart(mae_comparison_fig_load)
|
| 655 |
-
#-------------------------------------------------
|
| 656 |
|
| 657 |
st.header('MAE Ratio Comparison by Forecast Hour')
|
| 658 |
st.write("These clock-plots shows the relative Mean Absolute Error (rMAE) of different forecasting models compared to the ENTSO-E forecast, by the hour at which the forecast was made. "
|
|
@@ -793,7 +758,6 @@ elif section == 'Forecasts':
|
|
| 793 |
|
| 794 |
# Convert the dictionaries to DataFrames and sort by rMAE
|
| 795 |
df_wind_onshore = pd.DataFrame.from_dict(results_wind_onshore, orient='index').sort_values(by='rMAE')
|
| 796 |
-
print(df_wind_onshore)
|
| 797 |
df_wind_offshore = pd.DataFrame.from_dict(results_wind_offshore, orient='index').sort_values(by='rMAE')
|
| 798 |
df_load = pd.DataFrame.from_dict(results_load, orient='index').sort_values(by='rMAE')
|
| 799 |
df_solar = pd.DataFrame.from_dict(results_solar, orient='index').sort_values(by='rMAE')
|
|
@@ -941,4 +905,5 @@ elif section == 'Insights':
|
|
| 941 |
fig.update_layout(title=f'{weather_col} vs {actual_col}')
|
| 942 |
st.plotly_chart(fig)
|
| 943 |
|
|
|
|
| 944 |
|
|
|
|
| 313 |
operation_forecast_res.columns = [col.replace('_entsoe.', '_').replace('Naive.1D', 'DailyNaiveSeasonal') for col in operation_forecast_res.columns]
|
| 314 |
Historical_and_Load=add_feature(operation_forecast_load, historical_forecast)
|
| 315 |
Historical_and_operational=add_feature(operation_forecast_res, Historical_and_Load)
|
| 316 |
+
|
| 317 |
best_forecast = Historical_and_operational.filter(like='Forecast_elia', axis=1)
|
| 318 |
df_combined = Historical_and_operational.join(Data_BE, how='inner')
|
| 319 |
last_week_best_forecast = best_forecast.loc[best_forecast.index >= (best_forecast.index[-24] - pd.Timedelta(days=8))]
|
|
|
|
| 505 |
model_mae = calculate_mae(aligned_actual_values, aligned_model_predictions)
|
| 506 |
# Calculate MAE for the entsoe forecast
|
| 507 |
entsoe_forecast = real_values_df[f'{category_prefix}_forecast_entsoe'].loc[common_indices]
|
|
|
|
| 508 |
entsoe_mae = calculate_mae(aligned_actual_values, entsoe_forecast)
|
| 509 |
# Calculate MAE ratio
|
| 510 |
mae_ratio = model_mae / entsoe_mae
|
|
|
|
| 558 |
hours_with_data = []
|
| 559 |
mae_ratios = []
|
| 560 |
|
|
|
|
|
|
|
| 561 |
for hour in hours:
|
| 562 |
file_name = f'Predictions_{hour}h.csv'
|
| 563 |
df = df_dict.get(file_name, None)
|
| 564 |
if df is None:
|
|
|
|
| 565 |
continue
|
| 566 |
|
| 567 |
if isinstance(df.index, pd.DatetimeIndex):
|
|
|
|
| 592 |
hours_with_data.append(hour)
|
| 593 |
|
| 594 |
if mae_ratios:
|
|
|
|
| 595 |
fig.add_trace(go.Scatterpolar(
|
| 596 |
r=mae_ratios + [mae_ratios[0]], # Ensure closure of the polar plot
|
| 597 |
theta=[h * 15 for h in hours_with_data] + [0], # Ensure closure at 0 degrees
|
|
|
|
| 618 |
|
| 619 |
|
| 620 |
if country_code == "BE":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
|
| 622 |
st.header('MAE Ratio Comparison by Forecast Hour')
|
| 623 |
st.write("These clock-plots shows the relative Mean Absolute Error (rMAE) of different forecasting models compared to the ENTSO-E forecast, by the hour at which the forecast was made. "
|
|
|
|
| 758 |
|
| 759 |
# Convert the dictionaries to DataFrames and sort by rMAE
|
| 760 |
df_wind_onshore = pd.DataFrame.from_dict(results_wind_onshore, orient='index').sort_values(by='rMAE')
|
|
|
|
| 761 |
df_wind_offshore = pd.DataFrame.from_dict(results_wind_offshore, orient='index').sort_values(by='rMAE')
|
| 762 |
df_load = pd.DataFrame.from_dict(results_load, orient='index').sort_values(by='rMAE')
|
| 763 |
df_solar = pd.DataFrame.from_dict(results_solar, orient='index').sort_values(by='rMAE')
|
|
|
|
| 905 |
fig.update_layout(title=f'{weather_col} vs {actual_col}')
|
| 906 |
st.plotly_chart(fig)
|
| 907 |
|
| 908 |
+
|
| 909 |
|