From cc162a9e028fb7a2bac5289e27b90ab57e46f10b Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 31 Jul 2023 17:09:59 +0200 Subject: [PATCH 01/16] option for losses on bidirectional links via link splitting --- config/config.default.yaml | 5 ++++ scripts/prepare_sector_network.py | 40 +++++++++++++++++++++++++++++++ scripts/solve_network.py | 22 +++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/config/config.default.yaml b/config/config.default.yaml index b162b75d..4413b8f5 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -478,6 +478,11 @@ sector: electricity_distribution_grid: true electricity_distribution_grid_cost_factor: 1.0 electricity_grid_connection: true + transmission_losses: + # per 1000 km + DC: 0 + H2 pipeline: 0 + gas pipeline: 0 H2_network: true gas_network: false H2_retrofit: false diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 11406bff..8719c281 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3280,6 +3280,34 @@ def set_temporal_aggregation(n, opts, solver_name): return n +def lossy_bidirectional_links(n, carrier, losses_per_thousand_km=0.0): + "Split bidirectional links into two unidirectional links to include transmission losses." + + carrier_i = n.links.query("carrier == @carrier").index + + if not losses_per_thousand_km or carrier_i.empty: + return + + logger.info( + f"Specified losses for {carrier} transmission. Splitting bidirectional links." + ) + + carrier_i = n.links.query("carrier == @carrier").index + n.links.loc[carrier_i, "p_min_pu"] = 0 + n.links["reversed"] = False + n.links.loc[carrier_i, "efficiency"] = ( + 1 - n.links.loc[carrier_i, "length"] * losses_per_thousand_km / 1e3 + ) + rev_links = ( + n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) + ) + rev_links.capital_cost = 0 + rev_links.reversed = True + rev_links.index = rev_links.index.map(lambda x: x + "-reversed") + + n.links = pd.concat([n.links, rev_links], sort=False) + + if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake @@ -3446,6 +3474,18 @@ if __name__ == "__main__": if options["electricity_grid_connection"]: add_electricity_grid_connection(n, costs) + for k, v in options["transmission_losses"].items(): + lossy_bidirectional_links(n, k, v) + + # Workaround: Remove lines with conflicting (and unrealistic) properties + # cf. https://github.com/PyPSA/pypsa-eur/issues/444 + if snakemake.config["solving"]["options"]["transmission_losses"]: + idx = n.lines.query("num_parallel == 0").index + logger.info( + f"Removing {len(idx)} line(s) with properties conflicting with transmission losses functionality." + ) + n.mremove("Line", idx) + first_year_myopic = (snakemake.params.foresight == "myopic") and ( snakemake.params.planning_horizons[0] == investment_year ) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 836544b4..a68ca074 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -494,6 +494,27 @@ def add_battery_constraints(n): n.model.add_constraints(lhs == 0, name="Link-charger_ratio") +def add_lossy_bidirectional_link_constraints(n): + if not n.links.p_nom_extendable.any() or not "reversed" in n.links.columns: + return + + carriers = n.links.loc[n.links.reversed, "carrier"].unique() + + backward_i = n.links.query( + "carrier in @carriers and reversed and p_nom_extendable" + ).index + forward_i = n.links.query( + "carrier in @carriers and ~reversed and p_nom_extendable" + ).index + + assert len(forward_i) == len(backward_i) + + lhs = n.model["Link-p_nom"].loc[backward_i] + rhs = n.model["Link-p_nom"].loc[forward_i] + + n.model.add_constraints(lhs == rhs, name="Link-bidirectional_sync") + + def add_chp_constraints(n): electric = ( n.links.index.str.contains("urban central") @@ -593,6 +614,7 @@ def extra_functionality(n, snapshots): if "EQ" in o: add_EQ_constraints(n, o) add_battery_constraints(n) + add_lossy_bidirectional_link_constraints(n) add_pipe_retrofit_constraint(n) From e4eff27e508406055284ba77f4727df7e2dcbc6c Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 3 Aug 2023 13:09:12 +0200 Subject: [PATCH 02/16] fix capacity synchronisation between forward and backward lossy links --- scripts/prepare_sector_network.py | 4 ++-- scripts/solve_network.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 8719c281..b8eb8bc1 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3294,7 +3294,6 @@ def lossy_bidirectional_links(n, carrier, losses_per_thousand_km=0.0): carrier_i = n.links.query("carrier == @carrier").index n.links.loc[carrier_i, "p_min_pu"] = 0 - n.links["reversed"] = False n.links.loc[carrier_i, "efficiency"] = ( 1 - n.links.loc[carrier_i, "length"] * losses_per_thousand_km / 1e3 ) @@ -3302,10 +3301,11 @@ def lossy_bidirectional_links(n, carrier, losses_per_thousand_km=0.0): n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) ) rev_links.capital_cost = 0 - rev_links.reversed = True + rev_links["reversed"] = True rev_links.index = rev_links.index.map(lambda x: x + "-reversed") n.links = pd.concat([n.links, rev_links], sort=False) + n.links["reversed"] = n.links["reversed"].fillna(False) if __name__ == "__main__": diff --git a/scripts/solve_network.py b/scripts/solve_network.py index a68ca074..5e8c0356 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -500,14 +500,10 @@ def add_lossy_bidirectional_link_constraints(n): carriers = n.links.loc[n.links.reversed, "carrier"].unique() - backward_i = n.links.query( - "carrier in @carriers and reversed and p_nom_extendable" - ).index forward_i = n.links.query( "carrier in @carriers and ~reversed and p_nom_extendable" ).index - - assert len(forward_i) == len(backward_i) + backward_i = forward_i + "-reversed" lhs = n.model["Link-p_nom"].loc[backward_i] rhs = n.model["Link-p_nom"].loc[forward_i] From d7cb13246b807e7907c49ad1214559be92d2f363 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 7 Aug 2023 14:31:19 +0200 Subject: [PATCH 03/16] link losses: exponential rather than linear model --- config/config.default.yaml | 13 ++++++++----- scripts/prepare_sector_network.py | 15 ++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 4413b8f5..1b0a2260 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -478,11 +478,14 @@ sector: electricity_distribution_grid: true electricity_distribution_grid_cost_factor: 1.0 electricity_grid_connection: true - transmission_losses: - # per 1000 km - DC: 0 - H2 pipeline: 0 - gas pipeline: 0 + transmission_efficiency: + DC: + efficiency_static: 0.98 + efficiency_per_1000km: 0.977 + H2 pipeline: + efficiency_per_1000km: 0.979 + gas pipeline: + efficiency_per_1000km: 0.977 H2_network: true gas_network: false H2_retrofit: false diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index b8eb8bc1..48f5f41f 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3280,22 +3280,27 @@ def set_temporal_aggregation(n, opts, solver_name): return n -def lossy_bidirectional_links(n, carrier, losses_per_thousand_km=0.0): +def lossy_bidirectional_links(n, carrier, efficiencies={}): "Split bidirectional links into two unidirectional links to include transmission losses." carrier_i = n.links.query("carrier == @carrier").index - if not losses_per_thousand_km or carrier_i.empty: + if not any(v != 1. for v in efficiencies.values()) or carrier_i.empty: return + efficiency_static = efficiencies.get("efficiency_static", 1) + efficiency_per_1000km = efficiencies.get("efficiency_per_1000km", 1) + logger.info( - f"Specified losses for {carrier} transmission. Splitting bidirectional links." + f"Specified losses for {carrier} transmission" + f"(static: {efficiency_static}, per 1000km: {efficiency_per_1000km})." + "Splitting bidirectional links." ) carrier_i = n.links.query("carrier == @carrier").index n.links.loc[carrier_i, "p_min_pu"] = 0 n.links.loc[carrier_i, "efficiency"] = ( - 1 - n.links.loc[carrier_i, "length"] * losses_per_thousand_km / 1e3 + efficiency_static * efficiency_per_1000km ** (n.links.loc[carrier_i, "length"] / 1e3) ) rev_links = ( n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) @@ -3474,7 +3479,7 @@ if __name__ == "__main__": if options["electricity_grid_connection"]: add_electricity_grid_connection(n, costs) - for k, v in options["transmission_losses"].items(): + for k, v in options["transmission_efficiency"].items(): lossy_bidirectional_links(n, k, v) # Workaround: Remove lines with conflicting (and unrealistic) properties From 118cabe8a60b238ef11aafc980a406011ea9f0fb Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 8 Aug 2023 17:56:22 +0200 Subject: [PATCH 04/16] add option to consider compression losses in pipelines as electricity demand --- config/config.default.yaml | 6 ++++-- scripts/prepare_sector_network.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 1b0a2260..81a26a0b 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -483,9 +483,11 @@ sector: efficiency_static: 0.98 efficiency_per_1000km: 0.977 H2 pipeline: - efficiency_per_1000km: 0.979 + efficiency_per_1000km: 1 # 0.979 + compression_per_1000km: 0.019 gas pipeline: - efficiency_per_1000km: 0.977 + efficiency_per_1000km: 1 #0.977 + compression_per_1000km: 0.01 H2_network: true gas_network: false H2_retrofit: false diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 48f5f41f..7b58329c 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3285,11 +3285,16 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): carrier_i = n.links.query("carrier == @carrier").index +<<<<<<< HEAD if not any(v != 1. for v in efficiencies.values()) or carrier_i.empty: +======= + if not any((v != 1.0) or (v >= 0) for v in efficiencies.values()) or carrier_i.empty: +>>>>>>> 5822adb0 (add option to consider compression losses in pipelines as electricity demand) return efficiency_static = efficiencies.get("efficiency_static", 1) efficiency_per_1000km = efficiencies.get("efficiency_per_1000km", 1) + compression_per_1000km = efficiencies.get("compression_per_1000km", 0) logger.info( f"Specified losses for {carrier} transmission" @@ -3297,7 +3302,6 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): "Splitting bidirectional links." ) - carrier_i = n.links.query("carrier == @carrier").index n.links.loc[carrier_i, "p_min_pu"] = 0 n.links.loc[carrier_i, "efficiency"] = ( efficiency_static * efficiency_per_1000km ** (n.links.loc[carrier_i, "length"] / 1e3) @@ -3312,6 +3316,11 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): n.links = pd.concat([n.links, rev_links], sort=False) n.links["reversed"] = n.links["reversed"].fillna(False) + # do compression losses after concatenation to take electricity consumption at bus0 in either direction + carrier_i = n.links.query("carrier == @carrier").index + if compression_per_1000km > 0: + n.links.loc[carrier_i, "bus2"] = n.links.loc[carrier_i, "bus0"].map(n.buses.location) # electricity + n.links.loc[carrier_i, "efficiency2"] = - compression_per_1000km * n.links.loc[carrier_i, "length"] / 1e3 if __name__ == "__main__": if "snakemake" not in globals(): From 592bc4eee7f57ef93e104f266595cb6d8ded754d Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 12 Sep 2023 17:28:42 +0200 Subject: [PATCH 05/16] cherry-pick --- scripts/prepare_sector_network.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 7b58329c..de02095d 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3285,11 +3285,10 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): carrier_i = n.links.query("carrier == @carrier").index -<<<<<<< HEAD - if not any(v != 1. for v in efficiencies.values()) or carrier_i.empty: -======= - if not any((v != 1.0) or (v >= 0) for v in efficiencies.values()) or carrier_i.empty: ->>>>>>> 5822adb0 (add option to consider compression losses in pipelines as electricity demand) + if ( + not any((v != 1.0) or (v >= 0) for v in efficiencies.values()) + or carrier_i.empty + ): return efficiency_static = efficiencies.get("efficiency_static", 1) @@ -3303,8 +3302,10 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): ) n.links.loc[carrier_i, "p_min_pu"] = 0 - n.links.loc[carrier_i, "efficiency"] = ( - efficiency_static * efficiency_per_1000km ** (n.links.loc[carrier_i, "length"] / 1e3) + n.links.loc[ + carrier_i, "efficiency" + ] = efficiency_static * efficiency_per_1000km ** ( + n.links.loc[carrier_i, "length"] / 1e3 ) rev_links = ( n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) @@ -3319,8 +3320,13 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): # do compression losses after concatenation to take electricity consumption at bus0 in either direction carrier_i = n.links.query("carrier == @carrier").index if compression_per_1000km > 0: - n.links.loc[carrier_i, "bus2"] = n.links.loc[carrier_i, "bus0"].map(n.buses.location) # electricity - n.links.loc[carrier_i, "efficiency2"] = - compression_per_1000km * n.links.loc[carrier_i, "length"] / 1e3 + n.links.loc[carrier_i, "bus2"] = n.links.loc[carrier_i, "bus0"].map( + n.buses.location + ) # electricity + n.links.loc[carrier_i, "efficiency2"] = ( + -compression_per_1000km * n.links.loc[carrier_i, "length"] / 1e3 + ) + if __name__ == "__main__": if "snakemake" not in globals(): From 666e79e2fdb7b86348a81e097a0c6e200872b661 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 10 Aug 2023 17:13:19 +0200 Subject: [PATCH 06/16] improve logging for lossy bidirectional links --- scripts/prepare_sector_network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index de02095d..6355f603 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3296,8 +3296,8 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): compression_per_1000km = efficiencies.get("compression_per_1000km", 0) logger.info( - f"Specified losses for {carrier} transmission" - f"(static: {efficiency_static}, per 1000km: {efficiency_per_1000km})." + f"Specified losses for {carrier} transmission " + f"(static: {efficiency_static}, per 1000km: {efficiency_per_1000km}, compression per 1000km: {compression_per_1000km}). " "Splitting bidirectional links." ) From bde04eeac9dad86b9d05ce6d23f48d98a728ba7f Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 29 Aug 2023 16:32:01 +0200 Subject: [PATCH 07/16] lossy_bidirectional_links: set length of reversed lines to 0 to avoid double counting in line volume limit --- scripts/prepare_sector_network.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 6355f603..cd5d9570 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3311,6 +3311,7 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) ) rev_links.capital_cost = 0 + rev_links.length = 0 rev_links["reversed"] = True rev_links.index = rev_links.index.map(lambda x: x + "-reversed") From 014a4cd62e3bc2f41e9e0ccd8e04ff6c169e9a60 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Sun, 12 Nov 2023 18:42:53 +0100 Subject: [PATCH 08/16] fix for losses with multi-period investment --- scripts/solve_network.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 83281284..fa59f7a3 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -697,7 +697,8 @@ def add_lossy_bidirectional_link_constraints(n): if not n.links.p_nom_extendable.any() or not "reversed" in n.links.columns: return - carriers = n.links.loc[n.links.reversed, "carrier"].unique() + reversed_links = n.links.reversed.fillna(0).astype(bool) + carriers = n.links.loc[reversed_links, "carrier"].unique() forward_i = n.links.query( "carrier in @carriers and ~reversed and p_nom_extendable" From 0d03d384cc0ce27e681b76d14418b6d1b5cf9d1c Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 3 Jan 2024 09:07:08 +0100 Subject: [PATCH 09/16] lossy_bidirectional_links: use original length for loss calculation --- scripts/prepare_sector_network.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 998f954e..09de541a 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3309,15 +3309,16 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): n.links.loc[carrier_i, "length"] / 1e3 ) rev_links = ( - n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) + n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0", "length": "length_original"}, axis=1) ) - rev_links.capital_cost = 0 - rev_links.length = 0 + rev_links["capital_cost"] = 0 + rev_links["length"] = 0 rev_links["reversed"] = True rev_links.index = rev_links.index.map(lambda x: x + "-reversed") n.links = pd.concat([n.links, rev_links], sort=False) n.links["reversed"] = n.links["reversed"].fillna(False) + n.links["length_original"] = n.links["length_original"].fillna(n.links.length) # do compression losses after concatenation to take electricity consumption at bus0 in either direction carrier_i = n.links.query("carrier == @carrier").index @@ -3326,7 +3327,7 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): n.buses.location ) # electricity n.links.loc[carrier_i, "efficiency2"] = ( - -compression_per_1000km * n.links.loc[carrier_i, "length"] / 1e3 + -compression_per_1000km * n.links.loc[carrier_i, "length_original"] / 1e3 ) From 2b2bad392f6c83771472d93ca2df597608ea6b26 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Jan 2024 08:08:21 +0000 Subject: [PATCH 10/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/prepare_sector_network.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 09de541a..bab8de7b 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3309,7 +3309,9 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): n.links.loc[carrier_i, "length"] / 1e3 ) rev_links = ( - n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0", "length": "length_original"}, axis=1) + n.links.loc[carrier_i] + .copy() + .rename({"bus0": "bus1", "bus1": "bus0", "length": "length_original"}, axis=1) ) rev_links["capital_cost"] = 0 rev_links["length"] = 0 From 075ffb5c043edf16b1a9b69c4be3ed31da7919b4 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 3 Jan 2024 09:26:08 +0100 Subject: [PATCH 11/16] add release notes and documentation --- doc/release_notes.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 505c747e..82f63252 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -10,6 +10,13 @@ Release Notes Upcoming Release ================ +* Add option to specify losses for bidirectional links, e.g. pipelines or HVDC + links, in configuration file under ``sector: transmission_efficiency:``. Users + can specify static or length-dependent values as well as a length-dependent + electricity demand for compression, which is implemented as a multi-link to + the local electricity buses. The bidirectional links will then be split into + two unidirectional links with linked capacities. + * Updated Global Energy Monitor LNG terminal data to March 2023 version. * For industry distribution, use EPRTR as fallback if ETS data is not available. From d829d6fd3da28cc7103648132b07726deda1b9c8 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 3 Jan 2024 09:28:24 +0100 Subject: [PATCH 12/16] add release notes and documentation --- doc/configtables/sector.csv | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/configtables/sector.csv b/doc/configtables/sector.csv index d610c862..2767c603 100644 --- a/doc/configtables/sector.csv +++ b/doc/configtables/sector.csv @@ -107,6 +107,11 @@ electricity_distribution _grid,--,"{true, false}",Add a simplified representatio electricity_distribution _grid_cost_factor,,,Multiplies the investment cost of the electricity distribution grid ,,, electricity_grid _connection,--,"{true, false}",Add the cost of electricity grid connection for onshore wind and solar +transmission_efficiency,,,Section to specify transmission losses or compression energy demands of bidirectional links. Splits them into two capacity-linked unidirectional links. +-- {carrier},--,str,The carrier of the link. +-- -- efficiency_static,p.u.,float,Length-independent transmission efficiency. +-- -- efficiency_per_1000km,p.u. per 1000 km,float,Length-dependent transmission efficiency ($\eta^{\text{length}}$) +-- -- compression_per_1000km,p.u. per 1000 km,float,Length-dependent electricity demand for compression ($\eta \cdot \text{length}$) implemented as multi-link to local electricity bus. H2_network,--,"{true, false}",Add option for new hydrogen pipelines gas_network,--,"{true, false}","Add existing natural gas infrastructure, incl. LNG terminals, production and entry-points. The existing gas network is added with a lossless transport model. A length-weighted `k-edge augmentation algorithm `_ can be run to add new candidate gas pipelines such that all regions of the model can be connected to the gas network. When activated, all the gas demands are regionally disaggregated as well." H2_retrofit,--,"{true, false}",Add option for retrofiting existing pipelines to transport hydrogen. From 29afffb4ca1b8480d88580769960b9536c17ef26 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 3 Jan 2024 11:31:56 +0100 Subject: [PATCH 13/16] fix potential duplicate renaming of length_original --- scripts/prepare_sector_network.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 2ba64e87..54d5d7c8 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3441,8 +3441,9 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): rev_links = ( n.links.loc[carrier_i] .copy() - .rename({"bus0": "bus1", "bus1": "bus0", "length": "length_original"}, axis=1) + .rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) ) + rev_links["length_original"] = rev_links["length"] rev_links["capital_cost"] = 0 rev_links["length"] = 0 rev_links["reversed"] = True From 4606cb131b292c02e95b2af3583e7df48561fcb9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Jan 2024 10:44:14 +0000 Subject: [PATCH 14/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- scripts/prepare_sector_network.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 54d5d7c8..815bf6ff 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3439,9 +3439,7 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}): n.links.loc[carrier_i, "length"] / 1e3 ) rev_links = ( - n.links.loc[carrier_i] - .copy() - .rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) + n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) ) rev_links["length_original"] = rev_links["length"] rev_links["capital_cost"] = 0 From 05495ce48413d2aee4c351da29b230cd62add824 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 3 Jan 2024 12:46:42 +0100 Subject: [PATCH 15/16] fix lossy bidirectional link coupling countraint for myopic --- scripts/solve_network.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index a2125895..0bfc68ff 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -691,13 +691,24 @@ def add_lossy_bidirectional_link_constraints(n): if not n.links.p_nom_extendable.any() or not "reversed" in n.links.columns: return - reversed_links = n.links.reversed.fillna(0).astype(bool) - carriers = n.links.loc[reversed_links, "carrier"].unique() + n.links["reversed"] = n.links.reversed.fillna(0).astype(bool) + carriers = n.links.loc[n.links.reversed, "carrier"].unique() forward_i = n.links.query( "carrier in @carriers and ~reversed and p_nom_extendable" ).index - backward_i = forward_i + "-reversed" + + def get_backward_i(forward_i): + return pd.Index( + [ + re.sub(r"-(\d{4})$", r"-reversed-\1", s) + if re.search(r"-\d{4}$", s) + else s + "-reversed" + for s in forward_i + ] + ) + + backward_i = get_backward_i(forward_i) lhs = n.model["Link-p_nom"].loc[backward_i] rhs = n.model["Link-p_nom"].loc[forward_i] From 80f9259bac4742b0f819ddc6542da458a7690874 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 3 Jan 2024 12:57:22 +0100 Subject: [PATCH 16/16] handle gas pipeline retrofitting with lossy links --- scripts/solve_network.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 0bfc68ff..98afd49d 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -774,9 +774,13 @@ def add_pipe_retrofit_constraint(n): """ Add constraint for retrofitting existing CH4 pipelines to H2 pipelines. """ - gas_pipes_i = n.links.query("carrier == 'gas pipeline' and p_nom_extendable").index + if "reversed" not in n.links.columns: + n.links["reversed"] = False + gas_pipes_i = n.links.query( + "carrier == 'gas pipeline' and p_nom_extendable and ~reversed" + ).index h2_retrofitted_i = n.links.query( - "carrier == 'H2 pipeline retrofitted' and p_nom_extendable" + "carrier == 'H2 pipeline retrofitted' and p_nom_extendable and ~reversed" ).index if h2_retrofitted_i.empty or gas_pipes_i.empty: