From 7f1ff0c3240b545fc5d93eeb8fdef28ef328975a Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Fri, 16 Feb 2024 16:41:21 +0100 Subject: [PATCH] Fix plotting of retrofitted hydrogen pipelines with pathway optimisation. --- doc/release_notes.rst | 2 ++ scripts/plot_hydrogen_network.py | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index b4425308..7feb4d72 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -19,6 +19,8 @@ Upcoming Release today to tomorrow's energy consumption is set with the ``industry: sector_ratios_fraction_future:`` parameter. +* Fix plotting of retrofitted hydrogen pipelines with pathway optimisation. + * Bugfix: Correct units of subtracted chlorine and methanol demand in :mod:`build_industry_sector_ratios`. diff --git a/scripts/plot_hydrogen_network.py b/scripts/plot_hydrogen_network.py index 95741170..c6b90ceb 100644 --- a/scripts/plot_hydrogen_network.py +++ b/scripts/plot_hydrogen_network.py @@ -24,6 +24,7 @@ def group_pipes(df, drop_direction=False): """ Group pipes which connect same buses and return overall capacity. """ + df = df.copy() if drop_direction: positive_order = df.bus0 < df.bus1 df_p = df[positive_order] @@ -32,12 +33,13 @@ def group_pipes(df, drop_direction=False): df = pd.concat([df_p, df_n]) # there are pipes for each investment period rename to AC buses name for plotting + df["index_orig"] = df.index df.index = df.apply( lambda x: f"H2 pipeline {x.bus0.replace(' H2', '')} -> {x.bus1.replace(' H2', '')}", axis=1, ) return df.groupby(level=0).agg( - {"p_nom_opt": "sum", "bus0": "first", "bus1": "first"} + {"p_nom_opt": "sum", "bus0": "first", "bus1": "first", "index_orig": "first"} ) @@ -95,17 +97,18 @@ def plot_h2_map(n, regions): ) if not h2_retro.empty: - positive_order = h2_retro.bus0 < h2_retro.bus1 - h2_retro_p = h2_retro[positive_order] - swap_buses = {"bus0": "bus1", "bus1": "bus0"} - h2_retro_n = h2_retro[~positive_order].rename(columns=swap_buses) - h2_retro = pd.concat([h2_retro_p, h2_retro_n]) + if snakemake.params.foresight != "myopic": + positive_order = h2_retro.bus0 < h2_retro.bus1 + h2_retro_p = h2_retro[positive_order] + swap_buses = {"bus0": "bus1", "bus1": "bus0"} + h2_retro_n = h2_retro[~positive_order].rename(columns=swap_buses) + h2_retro = pd.concat([h2_retro_p, h2_retro_n]) - h2_retro["index_orig"] = h2_retro.index - h2_retro.index = h2_retro.apply( - lambda x: f"H2 pipeline {x.bus0.replace(' H2', '')} -> {x.bus1.replace(' H2', '')}", - axis=1, - ) + h2_retro["index_orig"] = h2_retro.index + h2_retro.index = h2_retro.apply( + lambda x: f"H2 pipeline {x.bus0.replace(' H2', '')} -> {x.bus1.replace(' H2', '')}", + axis=1, + ) retro_w_new_i = h2_retro.index.intersection(h2_new.index) h2_retro_w_new = h2_retro.loc[retro_w_new_i]