Skip to content

Commit

Permalink
Updated Overview page
Browse files Browse the repository at this point in the history
  • Loading branch information
pclemow committed Aug 7, 2024
1 parent 3c3f799 commit 2ce368b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 47 deletions.
47 changes: 34 additions & 13 deletions app/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ def combine_left_right_subplots(fig_left: go.Figure, fig_right: go.Figure) -> go
"Gas Generation",
]

power_sources_names = [
"Battery",
"Interconnectors",
"Offshore Wind",
"Onshore Wind",
"Other",
"Pumped Hydro",
"Solar PV",
"Nuclear",
"Hydro",
"Gas",
]

power_sources_colors = {
s: c for s, c in zip(power_sources, DEFAULT_PLOTLY_COLORS[: len(power_sources)])
}
Expand Down Expand Up @@ -373,7 +386,7 @@ def generate_total_gen_fig(df: pd.DataFrame) -> px.line:

@figure("Demand Total")
@legend(show_legend=False)
@axes(ylabel="Total Demand (GW)", yrange=[-5, 70])
@axes(ylabel="Total Demand (GW)", yrange=[30, 60])
def generate_total_dem_fig(df: pd.DataFrame) -> px.line:
"""Creates Plotly figure for Total Demand graph.
Expand Down Expand Up @@ -426,7 +439,7 @@ def generate_system_freq_fig(df: pd.DataFrame) -> px.line:
return system_freq_fig


@axes(ylabel="MW", yrange=[-100, 100], xdomain=[0, 0.43])
@axes(ylabel="Power (MW)", yrange=[-100, 100], xdomain=[0, 0.43])
def generate_intraday_market_sys_fig_left(df: pd.DataFrame) -> go.Figure:
"""Generate left panel of Intraday Market System figure.
Expand All @@ -444,22 +457,27 @@ def generate_intraday_market_sys_fig_left(df: pd.DataFrame) -> go.Figure:
"Intra-Day Market Storage",
"Intra-Day Market Demand",
]
col_names = [
"Gen.",
"Sto.",
"DSR",
]
intraday_market_sys_fig_left = go.Figure(
[
go.Scatter(
x=df["Time"],
y=df[c],
y=df[columns[c]],
mode="lines",
name=c,
name=col_names[c],
showlegend=True,
)
for c in columns
for c in [0, 1, 2]
]
)
return intraday_market_sys_fig_left


@axes(ylabel="Intra-Day Market Value (£/MW)", yrange=[-10000, 10000], xdomain=[0.57, 1])
@axes(ylabel="Value (£/MW)", yrange=[-50000, 50000], xdomain=[0.57, 1])
def generate_intraday_market_sys_fig_right(df: pd.DataFrame) -> px.line:
"""Generate right panel of Intraday Market System figure.
Expand Down Expand Up @@ -502,7 +520,7 @@ def generate_intraday_market_sys_fig(df: pd.DataFrame) -> go.Figure:
return intraday_market_sys_fig


@axes(ylabel="MW", yrange=[-250, 250], xdomain=[0, 0.43])
@axes(ylabel="Power (MW)", yrange=[-250, 250], xdomain=[0, 0.43])
def generate_balancing_market_fig_left(df: pd.DataFrame) -> go.Figure:
"""Generate left panel for Balancing Market figure.
Expand All @@ -520,24 +538,27 @@ def generate_balancing_market_fig_left(df: pd.DataFrame) -> go.Figure:
"Balancing Mechanism Storage",
"Balancing Mechanism Demand",
]
col_names = [
"Gen.",
"Sto.",
"DSR",
]
balancing_market_fig_left = go.Figure(
[
go.Scatter(
x=df["Time"],
y=df[c],
y=df[columns[c]],
mode="lines",
name=c,
name=col_names[c],
showlegend=True,
)
for c in columns
for c in [0, 1, 2]
]
)
return balancing_market_fig_left


@axes(
ylabel="Balancing Mechanism Value (£/MW)", yrange=[-50000, 50000], xdomain=[0.57, 1]
)
@axes(ylabel="Value (£/MW)", yrange=[-50000, 50000], xdomain=[0.57, 1])
def generate_balancing_market_fig_right(df: pd.DataFrame) -> go.Figure:
"""Generate right panel for Balancing Market figure.
Expand Down
78 changes: 44 additions & 34 deletions app/pages/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
generate_energy_deficit_fig,
generate_ev_charging_breakdown_fig,
generate_intraday_market_sys_fig,
generate_map_fig,
generate_total_dem_fig,
generate_total_gen_fig,
)
Expand All @@ -30,6 +31,7 @@

df = pd.DataFrame({"Col": [0]})

map_fig = generate_map_fig(df)
total_gen_fig = generate_total_gen_fig(df)
total_dem_fig = generate_total_dem_fig(df)
energy_deficit_fig = generate_energy_deficit_fig(df)
Expand All @@ -39,33 +41,42 @@
agent_activity_breakdown_fig = generate_agent_activity_breakdown_fig(df)
ev_charging_breakdown_fig = generate_ev_charging_breakdown_fig(df)

grid = GridBuilder(rows=4, cols=2)
grid = GridBuilder(rows=3, cols=3, row_heights=["25vh", "25vh", "50vh"])
grid.add_element(
dcc.Graph(
id="ov-generation",
figure=total_gen_fig,
id="ov-map-fig",
figure=map_fig,
style={"height": "100%", "width": "100%"},
),
row=0,
row=2,
col=0,
)
grid.add_element(
dcc.Graph(
id="ov-demand",
figure=total_dem_fig,
id="ov-generation",
figure=total_gen_fig,
style={"height": "100%", "width": "100%"},
),
row=1,
col=0,
row=0,
col=1,
)
# grid.add_element(
# dcc.Graph(
# id="ov-demand",
# figure=total_dem_fig,
# style={"height": "100%", "width": "100%"},
# ),
# row=1,
# col=1,
# )
grid.add_element(
dcc.Graph(
id="ov-energy-deficit",
figure=energy_deficit_fig,
style={"height": "100%", "width": "100%"},
),
row=2,
col=0,
row=1,
col=1,
)
grid.add_element(
dcc.Graph(
Expand All @@ -74,7 +85,7 @@
style={"height": "100%", "width": "100%"},
),
row=0,
col=1,
col=2,
)
grid.add_element(
dcc.Graph(
Expand All @@ -83,56 +94,53 @@
style={"height": "100%", "width": "100%"},
),
row=1,
col=1,
)
grid.add_element(
dcc.Graph(
id="ov-dsr",
figure=dsr_commands_fig,
style={"height": "100%", "width": "100%"},
),
row=2,
col=1,
col=2,
)
# grid.add_element(
# dcc.Graph(
# id="ov-dsr",
# figure=dsr_commands_fig,
# style={"height": "100%", "width": "100%"},
# ),
# row=2,
# col=2,
# )
grid.add_element(
dcc.Graph(
id="ov-agent-waffle",
figure=agent_activity_breakdown_fig,
style={"height": "100%", "width": "100%"},
),
row=3,
col=0,
row=2,
col=1,
)
grid.add_element(
dcc.Graph(
id="ov-ev-waffle",
figure=ev_charging_breakdown_fig,
style={"height": "100%", "width": "100%"},
),
row=3,
col=1,
row=2,
col=2,
)
layout = grid.layout


@callback(
[
Output("ov-map-fig", "figure"),
Output("ov-generation", "figure"),
Output("ov-demand", "figure"),
Output("ov-energy-deficit", "figure"),
Output("ov-bm", "figure"),
Output("ov-id", "figure"),
Output("ov-dsr", "figure"),
Output("ov-agent-waffle", "figure"),
Output("ov-ev-waffle", "figure"),
],
[Input("figure_interval", "data")],
)
def update_figures(
n_intervals: int,
) -> tuple[
px.line, px.line, px.line, go.Figure, go.Figure, px.line, go.Figure, go.Figure
]:
) -> tuple[go.Figure, px.line, px.line, go.Figure, go.Figure, go.Figure, go.Figure]:
"""Function to update the plots in this page.
Args:
Expand All @@ -152,23 +160,25 @@ def update_figures(
"""
from ..data import DF_OPAL

map_fig = generate_map_fig(DF_OPAL)
total_gen_fig = generate_total_gen_fig(DF_OPAL)
total_dem_fig = generate_total_dem_fig(DF_OPAL)
# total_dem_fig = generate_total_dem_fig(DF_OPAL)
energy_deficit_fig = generate_energy_deficit_fig(DF_OPAL)
balancing_market_fig = generate_balancing_market_fig(DF_OPAL)
intraday_market_sys_fig = generate_intraday_market_sys_fig(DF_OPAL)
dsr_commands_fig = generate_dsr_commands_fig(DF_OPAL)
# dsr_commands_fig = generate_dsr_commands_fig(DF_OPAL)
agent_activity_breakdown_fig = generate_agent_activity_breakdown_fig(DF_OPAL)
ev_charging_breakdown_fig = generate_ev_charging_breakdown_fig(DF_OPAL)

log.debug("Updating figures on Overview page")
return (
map_fig,
total_gen_fig,
total_dem_fig,
# total_dem_fig,
energy_deficit_fig,
balancing_market_fig,
intraday_market_sys_fig,
dsr_commands_fig,
# dsr_commands_fig,
agent_activity_breakdown_fig,
ev_charging_breakdown_fig,
)

0 comments on commit 2ce368b

Please sign in to comment.