From 879c896bea45ca6908a96ddb7d6cdb8111220e77 Mon Sep 17 00:00:00 2001 From: "daniel.rdt" Date: Tue, 10 Sep 2024 13:51:34 +0200 Subject: [PATCH 1/2] fix bug for plotting of hydrogen network with myopic foresight. --- scripts/plot_hydrogen_network.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/plot_hydrogen_network.py b/scripts/plot_hydrogen_network.py index b4585fb2..d7e42ff8 100644 --- a/scripts/plot_hydrogen_network.py +++ b/scripts/plot_hydrogen_network.py @@ -115,7 +115,7 @@ def plot_h2_map(n, regions): retro_wo_new_i = h2_retro.index.difference(h2_new.index) h2_retro_wo_new = h2_retro.loc[retro_wo_new_i] - h2_retro_wo_new.index = h2_retro_wo_new.index_orig + h2_retro_wo_new.index = h2_retro_wo_new.index_orig.apply(lambda x: x.split('-2')[0]) to_concat = [h2_new, h2_retro_w_new, h2_retro_wo_new] h2_total = pd.concat(to_concat).p_nom_opt.groupby(level=0).sum() @@ -126,7 +126,10 @@ def plot_h2_map(n, regions): link_widths_total = h2_total / linewidth_factor n.links.rename(index=lambda x: x.split("-2")[0], inplace=True) - n.links = n.links.groupby(level=0).first() + # group links by summing up p_nom values and taking the first value of the rest of the columns + other_cols = dict.fromkeys(n.links.columns.drop(["p_nom_opt", "p_nom"]), "first") + n.links = n.links.groupby(level=0).agg({"p_nom_opt": "sum", "p_nom": "sum", **other_cols}) + link_widths_total = link_widths_total.reindex(n.links.index).fillna(0.0) link_widths_total[n.links.p_nom_opt < line_lower_threshold] = 0.0 From e89027e9466c70ca47600fb543cd592d73848dec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Sep 2024 12:04:16 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/plot_hydrogen_network.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/plot_hydrogen_network.py b/scripts/plot_hydrogen_network.py index d7e42ff8..6d666acd 100644 --- a/scripts/plot_hydrogen_network.py +++ b/scripts/plot_hydrogen_network.py @@ -115,7 +115,9 @@ def plot_h2_map(n, regions): retro_wo_new_i = h2_retro.index.difference(h2_new.index) h2_retro_wo_new = h2_retro.loc[retro_wo_new_i] - h2_retro_wo_new.index = h2_retro_wo_new.index_orig.apply(lambda x: x.split('-2')[0]) + h2_retro_wo_new.index = h2_retro_wo_new.index_orig.apply( + lambda x: x.split("-2")[0] + ) to_concat = [h2_new, h2_retro_w_new, h2_retro_wo_new] h2_total = pd.concat(to_concat).p_nom_opt.groupby(level=0).sum() @@ -128,8 +130,10 @@ def plot_h2_map(n, regions): n.links.rename(index=lambda x: x.split("-2")[0], inplace=True) # group links by summing up p_nom values and taking the first value of the rest of the columns other_cols = dict.fromkeys(n.links.columns.drop(["p_nom_opt", "p_nom"]), "first") - n.links = n.links.groupby(level=0).agg({"p_nom_opt": "sum", "p_nom": "sum", **other_cols}) - + n.links = n.links.groupby(level=0).agg( + {"p_nom_opt": "sum", "p_nom": "sum", **other_cols} + ) + link_widths_total = link_widths_total.reindex(n.links.index).fillna(0.0) link_widths_total[n.links.p_nom_opt < line_lower_threshold] = 0.0