Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes minutes to hours on forecast horizons tables/plots #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,28 @@ def metric_page():
make_recent_summary_stats(values=y_mae)
make_recent_summary_stats(values=y_rmse, title="Recent RMSE")

def convert_minutes_to_hours(minutes):
return round(minutes / 60, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably only define this once

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps import from src/plots/forecast_horizon


# Generate forecast horizons in minutes
forecast_horizons_in_minutes = list(range(0, 480, 30)) + list(range(480, 36 * 60, 180))

# Convert them to hours
forecast_horizons_in_hours = [convert_minutes_to_hours(minutes) for minutes in forecast_horizons_in_minutes]

# Default selection also converted to hours
default_selection_in_hours = [convert_minutes_to_hours(minutes) for minutes in [60, 120, 240, 420]]

st.sidebar.subheader("Select Forecast Horizon")
forecast_horizon_selection = st.sidebar.multiselect(
"Select",
# 0-8 hours in 30 mintue chunks, 8-36 hours in 3 hour chunks
list(range(0, 480, 30)) + list(range(480, 36 * 60, 180)),
[60, 120, 240, 420],
forecast_horizons_in_hours,
default_selection_in_hours,
)

# Convert selected forecast horizons back to minutes for further processing
forecast_horizon_selection_in_minutes = [int(hours * 60) for hours in forecast_horizon_selection]

df_mae = pd.DataFrame(
{
"MAE": y_mae,
Expand Down
25 changes: 17 additions & 8 deletions src/plots/forecast_horizon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

from plots.utils import line_color, get_x_y, MAE_LIMIT_DEFAULT

def convert_minutes_to_hours(minutes):
return round(minutes / 60, 1)


def make_mae_by_forecast_horizon(
df_mae, forecast_horizon_selection, metric_values_by_forecast_horizon
Expand Down Expand Up @@ -39,12 +42,14 @@ def make_mae_by_forecast_horizon(
}
)

forecast_horizon_hours = convert_minutes_to_hours(forecast_horizon)

fig2.add_traces(
[
go.Scatter(
x=df["datetime_utc"],
y=df["MAE"],
name=f"{forecast_horizon}-minute horizon",
name=f"{forecast_horizon_hours}-hour horizon",
mode="lines",
line=dict(color=line_color[i%len(line_color)]),
)
Expand All @@ -64,19 +69,21 @@ def make_mae_forecast_horizon_group_by_forecast_horizon(
text="Quartz Solar MAE by Forecast Horizon for Date Range(selected in sidebar)"
),
xaxis=go.layout.XAxis(title=go.layout.xaxis.Title(text="MAE (MW)")),
yaxis=go.layout.YAxis(title=go.layout.yaxis.Title(text="Forecast Horizon (minutes)")),
yaxis=go.layout.YAxis(title=go.layout.yaxis.Title(text="Forecast Horizon (hours)")),
)
)
for i, forecast_horizon in enumerate(forecast_horizon_selection):
metric_values = metric_values_by_forecast_horizon[forecast_horizon]
x_mae_horizon = [value.datetime_interval.start_datetime_utc for value in metric_values]
y_mae_horizon = [round(float(value.value), 2) for value in metric_values]

forecast_horizon_hours = convert_minutes_to_hours(forecast_horizon)

df_mae_horizon = pd.DataFrame(
{
"MAE": y_mae_horizon,
"datetime_utc": x_mae_horizon,
"forecast_horizon": forecast_horizon,
"forecast_horizon": forecast_horizon_hours,
}
)

Expand All @@ -85,20 +92,21 @@ def make_mae_forecast_horizon_group_by_forecast_horizon(
go.Scatter(
x=df_mae_horizon["MAE"],
y=df_mae_horizon["forecast_horizon"],
name=f"{forecast_horizon}-minute horizon",
name=f"{forecast_horizon_hours}-hour horizon",
mode="markers",
line=dict(color=line_color[i%len(line_color)]),
),
]
)
fig.update_layout(
xaxis=dict(tickmode="linear", tick0=0, dtick=50),
yaxis=dict(tickmode="linear", tick0=0, dtick=60),
yaxis=dict(tickmode="linear", tick0=0, dtick=1),
)
fig.update_layout(xaxis_range=[0, MAE_LIMIT_DEFAULT])
return fig



def make_mae_vs_forecast_horizon_group_by_date(
forecast_horizon_selection, metric_values_by_forecast_horizon
):
Expand All @@ -109,7 +117,7 @@ def make_mae_vs_forecast_horizon_group_by_date(
fig = go.Figure(
layout=go.Layout(
title=go.layout.Title(text="Quartz Solar MAE Forecast Horizon Values by Date"),
xaxis=go.layout.XAxis(title=go.layout.xaxis.Title(text="Forecast Horizon (minutes)")),
xaxis=go.layout.XAxis(title=go.layout.xaxis.Title(text="Forecast Horizon (hours)")),
yaxis=go.layout.YAxis(title=go.layout.yaxis.Title(text="MAE (MW)")),
legend=go.layout.Legend(title=go.layout.legend.Title(text="Date")),
)
Expand All @@ -124,7 +132,7 @@ def make_mae_vs_forecast_horizon_group_by_date(
metric_values = metric_values_by_forecast_horizon[forecast_horizon]
dates = [value.datetime_interval.start_datetime_utc for value in metric_values]
mae_value = [round(float(value.value), 2) for value in metric_values]
forecast_horizons = [value.forecast_horizon_minutes for value in metric_values]
forecast_horizons = [convert_minutes_to_hours(value.forecast_horizon_minutes) for value in metric_values]

# create dataframe for each date with a value for each forecast horizon
data = pd.DataFrame(
Expand Down Expand Up @@ -160,8 +168,9 @@ def make_mae_vs_forecast_horizon_group_by_date(
)
fig.add_traces(traces)
fig.update_layout(
xaxis=dict(tickmode="linear", tick0=0, dtick=60),
xaxis=dict(tickmode="linear", tick0=0, dtick=1),
yaxis=dict(tickmode="linear", tick0=0, dtick=50),
)
fig.update_layout(yaxis_range=[0, MAE_LIMIT_DEFAULT])
return all_forecast_horizons_df, fig

4 changes: 4 additions & 0 deletions src/tables/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def get_recent_daily_values(values):

return day_before_yesterday, yesterday, today

def convert_minutes_to_hours(minutes):
return round(minutes / 60, 1)

def make_forecast_horizon_table(all_forecast_horizons_df, y_plive_mae):
st.subheader("Data - forecast horizon averaged")
Expand All @@ -52,6 +54,8 @@ def make_forecast_horizon_table(all_forecast_horizons_df, y_plive_mae):
df_mae_horizon_mean.rename(columns={"MAE": "mean"}, inplace=True)
df_mae_horizon_std = all_forecast_horizons_df.groupby(["forecast_horizon"]).std().reset_index()
df_mae_horizon_mean["std"] = df_mae_horizon_std["MAE"]
# Convert forecast_horizon from minutes to hours
df_mae_horizon_mean["forecast_horizon"] = df_mae_horizon_mean["forecast_horizon"].apply(convert_minutes_to_hours)
pv_live_mae = np.round(np.mean(y_plive_mae), 2)
st.write(f"PV LIVE Mae {pv_live_mae} MW (intraday - day after)")
st.write(df_mae_horizon_mean)