Skip to content

Commit

Permalink
Merge branch 'dev' into features/release-0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Nov 14, 2023
2 parents d475538 + a98017f commit c977b35
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions etrago/tools/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ def calc_network_expansion(network, method="abs", ext_min=0.1):
return network, extension_lines, extension_links


def plot_background_grid(network, ax):
def plot_background_grid(network, ax, geographical_boundaries):
"""Plots grid topology in background of other network.plot
Parameters
Expand All @@ -1760,6 +1760,8 @@ def plot_background_grid(network, ax):
Overall container of PyPSA
ax : matplotlib.axes._subplots.AxesSubplot
axes of plot
geographical_boundaries : list
Set georaphical boundaries for the plots
Returns
-------
Expand All @@ -1780,7 +1782,7 @@ def plot_background_grid(network, ax):
geomap=True,
projection=ccrs.PlateCarree(),
color_geomap=True,
boundaries=[-2.5, 16, 46.8, 58],
boundaries=geographical_boundaries,
)
else:
network.plot(
Expand Down Expand Up @@ -2319,11 +2321,8 @@ def plot_grid(
ext_min=0.1,
ext_width=False,
legend_entries="all",
scaling_store_expansion={
"H2": 50,
"heat": 0.1,
"battery": 10,
},
scaling_store_expansion=False,
geographical_boundaries=[-2.5, 16, 46.8, 58],
):
"""Function that plots etrago.network and results for lines and buses
Expand Down Expand Up @@ -2384,7 +2383,11 @@ def plot_grid(
scaling_store_expansion : dict, optional
Set scaling values to be used per technology for the plots
storage_expansion and h2_battery_storage_expansion. The default is
False, it could be assinged like this:
{"H2": 50, "heat": 0.1, "battery": 10}
geographical_boundaries : list, optional
Set georaphical boundaries for the plots The default is
[-2.5, 16, 46.8, 58]
Returns
-------
Expand Down Expand Up @@ -2439,7 +2442,7 @@ def plot_grid(
link_widths = link_colors.apply(lambda x: 10 if x != 0 else 0)
line_widths = 10
label = "line loading in p.u."
plot_background_grid(network, ax)
plot_background_grid(network, ax, geographical_boundaries)
# Only active flow direction is displayed!
flow = pd.Series(1, index=network.branches().index, dtype="float64")
flow.iloc[flow.index.get_level_values("component") == "Line"] = (
Expand Down Expand Up @@ -2478,14 +2481,14 @@ def plot_grid(
label = "v_nom in kV"
line_colors = network.lines.v_nom
link_colors = pd.Series(data=0, index=network.links.index)
plot_background_grid(network, ax)
plot_background_grid(network, ax, geographical_boundaries)
elif line_colors == "expansion_abs":
title = "Network expansion"
label = "network expansion in GVA"
all_network, line_colors, link_colors = calc_network_expansion(
network, method="abs", ext_min=ext_min
)
plot_background_grid(all_network, ax)
plot_background_grid(all_network, ax, geographical_boundaries)

if ext_width is not False:
line_widths = line_colors / ext_width
Expand All @@ -2507,7 +2510,7 @@ def plot_grid(
all_network, line_colors, link_colors = calc_network_expansion(
network, method="rel", ext_min=ext_min
)
plot_background_grid(all_network, ax)
plot_background_grid(all_network, ax, geographical_boundaries)
if ext_width is not False:
line_widths = 0.5 + (line_colors / ext_width)
link_widths = link_colors.apply(
Expand All @@ -2527,11 +2530,11 @@ def plot_grid(
if ext_width is not False:
line_widths = 0.5 + (line_colors / ext_width)
link_colors = pd.Series(data=0, index=network.links.index)
plot_background_grid(network, ax)
plot_background_grid(network, ax, geographical_boundaries)
elif line_colors == "dlr":
title = "Dynamic line rating"
label = "TWh above nominal capacity"
plot_background_grid(network, ax)
plot_background_grid(network, ax, geographical_boundaries)

# calc min capacity per line in the given period: Since lines with
# different original voltage level could be aggregated during the
Expand Down Expand Up @@ -2564,7 +2567,7 @@ def plot_grid(
label = ""
line_colors = "grey"
link_colors = "grey"
plot_background_grid(network, ax)
plot_background_grid(network, ax, geographical_boundaries)
link_widths = 0
line_widths = 0

Expand Down Expand Up @@ -2592,7 +2595,7 @@ def plot_grid(
)
bus_scaling = bus_sizes
bus_sizes = bus_scaling * calc_storage_expansion_per_bus(network)
for store_carrier in ["H2", "heat", "battery"]:
for store_carrier in scaling_store_expansion.keys():
bus_sizes[
bus_sizes.index.get_level_values("carrier").str.contains(
store_carrier
Expand Down Expand Up @@ -2715,7 +2718,7 @@ def plot_grid(
geomap=False,
projection=ccrs.PlateCarree(),
color_geomap=True,
boundaries=[-2.5, 16, 46.8, 58],
boundaries=geographical_boundaries,
)
else:
ll = network.plot(
Expand All @@ -2730,7 +2733,7 @@ def plot_grid(
flow=flow,
title=title,
geomap=False,
boundaries=[-2.5, 16, 46.8, 58],
boundaries=geographical_boundaries,
)
l3 = None

Expand Down

0 comments on commit c977b35

Please sign in to comment.