From 62bcded8001f2a3ff31b218ab0225594b1adedb3 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 4 Jan 2024 19:12:04 +0100 Subject: [PATCH 1/3] build_sector.smk: simplify gas infrastructure rules --- rules/build_sector.smk | 126 +++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 68 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index ab8ff4ed..23ea604c 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -67,76 +67,65 @@ rule build_simplified_population_layouts: "../scripts/build_clustered_population_layouts.py" -if config["sector"]["gas_network"] or config["sector"]["H2_retrofit"]: - - rule build_gas_network: - input: - gas_network="data/gas_network/scigrid-gas/data/IGGIELGN_PipeSegments.geojson", - output: - cleaned_gas_network=RESOURCES + "gas_network.csv", - resources: - mem_mb=4000, - log: - LOGS + "build_gas_network.log", - conda: - "../envs/environment.yaml" - script: - "../scripts/build_gas_network.py" - - rule build_gas_input_locations: - input: - gem=HTTP.remote( - "https://globalenergymonitor.org/wp-content/uploads/2023/07/Europe-Gas-Tracker-2023-03-v3.xlsx", - keep_local=True, - ), - entry="data/gas_network/scigrid-gas/data/IGGIELGN_BorderPoints.geojson", - storage="data/gas_network/scigrid-gas/data/IGGIELGN_Storages.geojson", - regions_onshore=RESOURCES - + "regions_onshore_elec_s{simpl}_{clusters}.geojson", - regions_offshore=RESOURCES - + "regions_offshore_elec_s{simpl}_{clusters}.geojson", - output: - gas_input_nodes=RESOURCES - + "gas_input_locations_s{simpl}_{clusters}.geojson", - gas_input_nodes_simplified=RESOURCES - + "gas_input_locations_s{simpl}_{clusters}_simplified.csv", - resources: - mem_mb=2000, - log: - LOGS + "build_gas_input_locations_s{simpl}_{clusters}.log", - conda: - "../envs/environment.yaml" - script: - "../scripts/build_gas_input_locations.py" - - rule cluster_gas_network: - input: - cleaned_gas_network=RESOURCES + "gas_network.csv", - regions_onshore=RESOURCES - + "regions_onshore_elec_s{simpl}_{clusters}.geojson", - regions_offshore=RESOURCES - + "regions_offshore_elec_s{simpl}_{clusters}.geojson", - output: - clustered_gas_network=RESOURCES + "gas_network_elec_s{simpl}_{clusters}.csv", - resources: - mem_mb=4000, - log: - LOGS + "cluster_gas_network_s{simpl}_{clusters}.log", - conda: - "../envs/environment.yaml" - script: - "../scripts/cluster_gas_network.py" - - gas_infrastructure = { - **rules.cluster_gas_network.output, - **rules.build_gas_input_locations.output, - } +rule build_gas_network: + input: + gas_network="data/gas_network/scigrid-gas/data/IGGIELGN_PipeSegments.geojson", + output: + cleaned_gas_network=RESOURCES + "gas_network.csv", + resources: + mem_mb=4000, + log: + LOGS + "build_gas_network.log", + conda: + "../envs/environment.yaml" + script: + "../scripts/build_gas_network.py" -if not (config["sector"]["gas_network"] or config["sector"]["H2_retrofit"]): - # this is effecively an `else` statement which is however not liked by snakefmt +rule build_gas_input_locations: + input: + gem=HTTP.remote( + "https://globalenergymonitor.org/wp-content/uploads/2023/07/Europe-Gas-Tracker-2023-03-v3.xlsx", + keep_local=True, + ), + entry="data/gas_network/scigrid-gas/data/IGGIELGN_BorderPoints.geojson", + storage="data/gas_network/scigrid-gas/data/IGGIELGN_Storages.geojson", + regions_onshore=RESOURCES + + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + regions_offshore=RESOURCES + + "regions_offshore_elec_s{simpl}_{clusters}.geojson", + output: + gas_input_nodes=RESOURCES + + "gas_input_locations_s{simpl}_{clusters}.geojson", + gas_input_nodes_simplified=RESOURCES + + "gas_input_locations_s{simpl}_{clusters}_simplified.csv", + resources: + mem_mb=2000, + log: + LOGS + "build_gas_input_locations_s{simpl}_{clusters}.log", + conda: + "../envs/environment.yaml" + script: + "../scripts/build_gas_input_locations.py" - gas_infrastructure = {} + +rule cluster_gas_network: + input: + cleaned_gas_network=RESOURCES + "gas_network.csv", + regions_onshore=RESOURCES + + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + regions_offshore=RESOURCES + + "regions_offshore_elec_s{simpl}_{clusters}.geojson", + output: + clustered_gas_network=RESOURCES + "gas_network_elec_s{simpl}_{clusters}.csv", + resources: + mem_mb=4000, + log: + LOGS + "cluster_gas_network_s{simpl}_{clusters}.log", + conda: + "../envs/environment.yaml" + script: + "../scripts/cluster_gas_network.py" rule build_heat_demands: @@ -722,7 +711,8 @@ rule prepare_sector_network: input: **build_retro_cost_output, **build_biomass_transport_costs_output, - **gas_infrastructure, + **rules.cluster_gas_network.output, + **rules.build_gas_input_locations.output, **build_sequestration_potentials_output, network=RESOURCES + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", energy_totals_name=RESOURCES + "energy_totals.csv", From 9d0040912b8b50ca2d69ae4c2720a486d7b98502 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 4 Jan 2024 19:14:11 +0100 Subject: [PATCH 2/3] retrieve.smk: simplify gas infrastructure retrieve rules --- rules/retrieve.smk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rules/retrieve.smk b/rules/retrieve.smk index e062091e..198edf97 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -162,9 +162,8 @@ if config["enable"]["retrieve"] and config["enable"].get( "../scripts/retrieve_sector_databundle.py" -if config["enable"]["retrieve"] and ( - config["sector"]["gas_network"] or config["sector"]["H2_retrofit"] -): +if config["enable"]["retrieve"]: + datafiles = [ "IGGIELGN_LNGs.geojson", "IGGIELGN_BorderPoints.geojson", From 7b1600164fa292eb1ba2288340340deaf1cb3f59 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Jan 2024 19:18:59 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rules/build_sector.smk | 15 +++++---------- rules/common.smk | 2 +- rules/retrieve.smk | 1 - scripts/add_brownfield.py | 4 +--- scripts/prepare_sector_network.py | 6 ++++-- scripts/solve_network.py | 2 +- 6 files changed, 12 insertions(+), 18 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 23ea604c..ef2fc6c8 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -90,13 +90,10 @@ rule build_gas_input_locations: ), entry="data/gas_network/scigrid-gas/data/IGGIELGN_BorderPoints.geojson", storage="data/gas_network/scigrid-gas/data/IGGIELGN_Storages.geojson", - regions_onshore=RESOURCES - + "regions_onshore_elec_s{simpl}_{clusters}.geojson", - regions_offshore=RESOURCES - + "regions_offshore_elec_s{simpl}_{clusters}.geojson", + regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + regions_offshore=RESOURCES + "regions_offshore_elec_s{simpl}_{clusters}.geojson", output: - gas_input_nodes=RESOURCES - + "gas_input_locations_s{simpl}_{clusters}.geojson", + gas_input_nodes=RESOURCES + "gas_input_locations_s{simpl}_{clusters}.geojson", gas_input_nodes_simplified=RESOURCES + "gas_input_locations_s{simpl}_{clusters}_simplified.csv", resources: @@ -112,10 +109,8 @@ rule build_gas_input_locations: rule cluster_gas_network: input: cleaned_gas_network=RESOURCES + "gas_network.csv", - regions_onshore=RESOURCES - + "regions_onshore_elec_s{simpl}_{clusters}.geojson", - regions_offshore=RESOURCES - + "regions_offshore_elec_s{simpl}_{clusters}.geojson", + regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + regions_offshore=RESOURCES + "regions_offshore_elec_s{simpl}_{clusters}.geojson", output: clustered_gas_network=RESOURCES + "gas_network_elec_s{simpl}_{clusters}.csv", resources: diff --git a/rules/common.smk b/rules/common.smk index 0e85b620..2298ff91 100644 --- a/rules/common.smk +++ b/rules/common.smk @@ -4,7 +4,7 @@ import os, sys, glob -helper_source_path = [match for match in glob.glob('**/_helpers.py', recursive=True)] +helper_source_path = [match for match in glob.glob("**/_helpers.py", recursive=True)] for path in helper_source_path: path = os.path.dirname(os.path.abspath(path)) diff --git a/rules/retrieve.smk b/rules/retrieve.smk index 198edf97..7a180e22 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -163,7 +163,6 @@ if config["enable"]["retrieve"] and config["enable"].get( if config["enable"]["retrieve"]: - datafiles = [ "IGGIELGN_LNGs.geojson", "IGGIELGN_BorderPoints.geojson", diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index e151c441..cb1f51c8 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -133,9 +133,7 @@ def disable_grid_expansion_if_LV_limit_hit(n): # allow small numerical differences if lv_limit - total_expansion < 1: - logger.info( - f"LV is already reached, disabling expansion and LV limit" - ) + logger.info(f"LV is already reached, disabling expansion and LV limit") extendable_acs = n.lines.query("s_nom_extendable").index n.lines.loc[extendable_acs, "s_nom_extendable"] = False n.lines.loc[extendable_acs, "s_nom"] = n.lines.loc[extendable_acs, "s_nom_min"] diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 17eb832d..70f57953 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -2998,8 +2998,9 @@ def add_industry(n, costs): if options["co2_spatial"] or options["co2network"]: p_set = ( - -industrial_demand.loc[nodes, "process emission"] - .rename(index=lambda x: x + " process emissions") + -industrial_demand.loc[nodes, "process emission"].rename( + index=lambda x: x + " process emissions" + ) / nhours ) else: @@ -3412,6 +3413,7 @@ def cluster_heat_buses(n): pnl = c.pnl agg = define_clustering(pd.Index(pnl.keys()), aggregate_dict) for k in pnl.keys(): + def renamer(s): return s.replace("residential ", "").replace("services ", "") diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 203d8b0f..aa802ea8 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -856,7 +856,7 @@ def solve_network(n, config, solving, opts="", **kwargs): kwargs["assign_all_duals"] = cf_solving.get("assign_all_duals", False) if kwargs["solver_name"] == "gurobi": - logging.getLogger('gurobipy').setLevel(logging.CRITICAL) + logging.getLogger("gurobipy").setLevel(logging.CRITICAL) rolling_horizon = cf_solving.pop("rolling_horizon", False) skip_iterations = cf_solving.pop("skip_iterations", False)