From 45fce9cdfcdb9e088630b80db0593bb6871d73e2 Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Fri, 15 Nov 2024 16:59:52 +0500 Subject: [PATCH 1/5] remove H2 and battery related techs from elec-only model before re-addition --- scripts/prepare_sector_network.py | 36 +++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 88caefb9f..e8a276d6b 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -186,9 +186,9 @@ def H2_liquid_fossil_conversions(n, costs): def add_hydrogen(n, costs): "function to add hydrogen as an energy carrier with its conversion technologies from and to AC" + logger.info("Adding hydrogen") - if not "H2" in n.carriers.index: - n.add("Carrier", "H2") + n.add("Carrier", "H2") n.madd( "Bus", @@ -1096,9 +1096,9 @@ def add_aviation(n, cost): def add_storage(n, costs): "function to add the different types of storage systems" + logger.info("Add battery storage") - if not "battery" in n.carriers.index: - n.add("Carrier", "battery") + n.add("Carrier", "battery") n.madd( "Bus", @@ -2763,6 +2763,31 @@ def remove_elec_base_techs(n): n.carriers.drop(to_remove, inplace=True, errors="ignore") +def remove_carrier_related_components(n, carriers_to_drop): + """ + Removes carrier related components, such as "Carrier", "Generator", "Link", "Store", and "Storage Unit" + """ + # remove carriers + n.carriers.drop(carriers_to_drop, inplace=True, errors="ignore") + + # remove buses, generators, stores, and storage units with carrier to remote + for c in n.iterate_components(["Bus", "Generator", "Store", "StorageUnit"]): + logger.info(f"Removing {c.list_name} with carrier {list(carriers_to_drop)}") + names = c.df.index[c.df.carrier.isin(carriers_to_drop)] + if c.name == "Bus": + buses_to_remove = names + n.mremove(c.name, names) + + # remove links connected to buses that were removed + links_to_remove = n.links.query( + "bus0 in @buses_to_remove or bus1 in @buses_to_remove or bus2 in @buses_to_remove or bus3 in @buses_to_remove or bus4 in @buses_to_remove" + ).index + logger.info( + f"Removing links with carrier {list(n.links.loc[links_to_remove].carrier.unique())}" + ) + n.mremove("Link", links_to_remove) + + if __name__ == "__main__": if "snakemake" not in globals(): # from helper import mock_snakemake #TODO remove func from here to helper script @@ -2906,6 +2931,9 @@ def remove_elec_base_techs(n): add_generation(n, costs, existing_capacities, existing_efficiencies, existing_nodes) + # remove H2 and battery technologies added in elec-only model + remove_carrier_related_components(n, carriers_to_drop=["H2", "battery"]) + add_hydrogen(n, costs) # TODO add costs add_storage(n, costs) From 9fd7e521bb4f924a0d4c40e9c2ecff7fd159b08b Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Fri, 15 Nov 2024 23:49:00 +0500 Subject: [PATCH 2/5] use repurposed H2 pipeline if specified --- scripts/prepare_sector_network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index e8a276d6b..014bae5d9 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -517,7 +517,7 @@ def add_links_elec_routing_new_H2_pipelines(): if len(h2_links) > 0: if snakemake.config["sector"]["hydrogen"]["gas_network_repurposing"]: - add_links_elec_routing_new_H2_pipelines() + add_links_repurposed_H2_pipelines() if snakemake.config["sector"]["hydrogen"]["network_routes"] == "greenfield": add_links_elec_routing_new_H2_pipelines() else: From 0d12bb167770803e8d4dc0cfaaddbb83b57728c4 Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Sun, 17 Nov 2024 13:36:05 +0500 Subject: [PATCH 3/5] store gas network with two letter buses not three letter --- scripts/prepare_gas_network.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/prepare_gas_network.py b/scripts/prepare_gas_network.py index cbdcd120a..27071c1f3 100644 --- a/scripts/prepare_gas_network.py +++ b/scripts/prepare_gas_network.py @@ -23,6 +23,7 @@ BASE_DIR, content_retrieve, progress_retrieve, + three_2_two_digits_country, two_2_three_digits_country, ) from build_shapes import gadm @@ -915,13 +916,17 @@ def check_existence(row): ) # Conversion of GADM id to from 3 to 2-digit - # pipelines["bus0"] = pipelines["bus0"].apply( - # lambda id: three_2_two_digits_country(id[:3]) + id[3:] - # ) + pipelines["bus0"] = ( + pipelines["bus0"] + .str.split(".") + .apply(lambda id: three_2_two_digits_country(id[0]) + "." + id[1]) + ) - # pipelines["bus1"] = pipelines["bus1"].apply( - # lambda id: three_2_two_digits_country(id[:3]) + id[3:] - # ) + pipelines["bus1"] = ( + pipelines["bus1"] + .str.split(".") + .apply(lambda id: three_2_two_digits_country(id[0]) + "." + id[1]) + ) pipelines.to_csv(snakemake.output.clustered_gas_network, index=False) From 7fe8b97d78fef2bc50bd347015cec478bc1558b2 Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Sun, 17 Nov 2024 19:19:23 +0500 Subject: [PATCH 4/5] use _AC in buses of h2_links --- scripts/prepare_gas_network.py | 12 ++++-------- scripts/prepare_sector_network.py | 19 +++---------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/scripts/prepare_gas_network.py b/scripts/prepare_gas_network.py index 27071c1f3..2ef30d0ff 100644 --- a/scripts/prepare_gas_network.py +++ b/scripts/prepare_gas_network.py @@ -916,16 +916,12 @@ def check_existence(row): ) # Conversion of GADM id to from 3 to 2-digit - pipelines["bus0"] = ( - pipelines["bus0"] - .str.split(".") - .apply(lambda id: three_2_two_digits_country(id[0]) + "." + id[1]) + pipelines["bus0"] = pipelines["bus0"].apply( + lambda id: three_2_two_digits_country(id[:3]) + id[3:] ) - pipelines["bus1"] = ( - pipelines["bus1"] - .str.split(".") - .apply(lambda id: three_2_two_digits_country(id[0]) + "." + id[1]) + pipelines["bus1"] = pipelines["bus1"].apply( + lambda id: three_2_two_digits_country(id[:3]) + id[3:] ) pipelines.to_csv(snakemake.output.clustered_gas_network, index=False) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 014bae5d9..01ab70a7b 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -488,22 +488,9 @@ def add_links_elec_routing_new_H2_pipelines(): # Order buses to detect equal pairs for bidirectional pipelines buses_ordered = h2_links.apply(lambda p: sorted([p.bus0, p.bus1]), axis=1) - if snakemake.config["build_osm_network"]["force_ac"]: - # Appending string for carrier specification '_AC' - h2_links["bus0"] = buses_ordered.str[0] + "_AC" - h2_links["bus1"] = buses_ordered.str[1] + "_AC" - - # # Conversion of GADM id to from 3 to 2-digit - # h2_links["bus0"] = ( - # h2_links["bus0"] - # .str.split(".") - # .apply(lambda id: three_2_two_digits_country(id[0]) + "." + id[1]) - # ) - # h2_links["bus1"] = ( - # h2_links["bus1"] - # .str.split(".") - # .apply(lambda id: three_2_two_digits_country(id[0]) + "." + id[1]) - # ) + # Appending string for carrier specification '_AC', because hydrogen has _AC in bus names + h2_links["bus0"] = buses_ordered.str[0] + "_AC" + h2_links["bus1"] = buses_ordered.str[1] + "_AC" # Create index column h2_links["buses_idx"] = ( From e817da78385388fe042a3604e93d4c1d6fed13ab Mon Sep 17 00:00:00 2001 From: yerbol-akhmetov Date: Thu, 28 Nov 2024 17:49:43 +0500 Subject: [PATCH 5/5] add release notes --- doc/release_notes.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 3f1318334..25cef4746 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -30,6 +30,8 @@ E.g. if a new rule becomes available describe how to use it `make test` and in o * Enable sector rules import in subworkflow `PR #1178 `__ +* Remove elec-based H2 and battery technologies before addition in `prepare_sector_network.py` script and fix bus names for links that models H2 repuspose network `PR #1198 `__ + **Minor Changes and bug-fixing** * The default configuration for `electricity:estimate_renewable_capacities:year` was updated from 2020 to 2023. `PR #1106 `__