Skip to content

Commit

Permalink
Add option to plot maximum line loading
Browse files Browse the repository at this point in the history
  • Loading branch information
birgits committed Sep 4, 2024
1 parent 0fec352 commit 8c40e2d
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions etrago/analyze/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,37 @@ def calc_ac_loading(network, timesteps):
return loading_lines / network.lines.s_nom_opt


def calc_ac_max_loading(network, timesteps):
"""Calculates loading of AC-lines
Parameters
----------
network : :class:`pypsa.Network
Overall container of PyPSA
timesteps : range
Defines which timesteps are considered. If more than one, an
average line loading is calculated.
Returns
-------
pandas.Series
AC line loading in MVA
"""

loading_lines = (
network.lines_t.p0.loc[network.snapshots[timesteps]]
).abs()

if not network.lines_t.q0.empty:
loading_lines = np.sqrt(
loading_lines**2
+ network.lines_t.q0.loc[network.snapshots[timesteps]]** 2
)

return loading_lines.max() / network.lines.s_nom_opt


def calc_dc_loading(network, timesteps):
"""Calculates loading of DC-lines
Expand Down Expand Up @@ -1649,6 +1680,41 @@ def calc_dc_loading(network, timesteps):
return dc_load


def calc_dc_max_loading(network, timesteps):
"""Calculates loading of DC-lines
Parameters
----------
network : :class:`pypsa.Network
Overall container of PyPSA
timesteps : range
Defines which timesteps are considered. If more than one, an
average line loading is calculated.
Returns
-------
pandas.Series
DC line loading in MW
"""
dc_links = network.links.loc[network.links.carrier == "DC", :]
ts = network.snapshots[timesteps]

link_load = network.links_t.p0.loc[ts, dc_links.index].abs()

dc_load = pd.Series(index=network.links.index, data=0.0)
dc_load.loc[dc_links.index] = (
(
link_load.max() / dc_links.p_nom_opt
)
.fillna(0)
.values
)

return dc_load


def plotting_colors(network):
"""Add color values to network.carriers
Expand Down Expand Up @@ -2469,6 +2535,7 @@ def plot_grid(
Current options:
* 'line_loading': mean line loading in p.u. in selected timesteps
* 'max_line_loading': maximum line loading in p.u. in selected timesteps
* 'v_nom': nominal voltage of lines
* 'expansion_abs': absolute network expansion in MVA
* 'expansion_rel': network expansion in p.u. of existing capacity
Expand Down Expand Up @@ -2630,6 +2697,23 @@ def plot_grid(
flow[flow < 0] = -1
flow[flow > 0] = 1

elif line_colors == "max_line_loading":
title = "Maximum line loading"
line_colors = calc_ac_max_loading(network, timesteps)
link_colors = calc_dc_max_loading(network, timesteps)
if ext_width is not False:
link_widths = link_colors.apply(
lambda x: 1 + (x / ext_width) if x != 0 else 0
)
line_widths = 1 + (line_colors / ext_width)
else:
link_widths = link_colors.apply(lambda x: 1 if x != 0 else 0)
line_widths = 1
label = "max. line loading in p.u."
plot_background_grid(network, ax, geographical_boundaries, osm)
# Only active flow direction is displayed!
flow = None

elif line_colors == "v_nom":
title = "Voltage levels"
label = "v_nom in kV"
Expand Down

0 comments on commit 8c40e2d

Please sign in to comment.