Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_sector.smk: simplify gas infrastructure rules #846

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 52 additions & 67 deletions rules/build_sector.smk
Original file line number Diff line number Diff line change
Expand Up @@ -67,76 +67,60 @@ 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"
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"

gas_infrastructure = {
**rules.cluster_gas_network.output,
**rules.build_gas_input_locations.output,
}

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"

if not (config["sector"]["gas_network"] or config["sector"]["H2_retrofit"]):
# this is effecively an `else` statement which is however not liked by snakefmt

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:
Expand Down Expand Up @@ -722,7 +706,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",
Expand Down
2 changes: 1 addition & 1 deletion rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions rules/retrieve.smk
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ 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",
Expand Down
4 changes: 1 addition & 3 deletions scripts/add_brownfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions scripts/prepare_sector_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -3412,6 +3413,7 @@ def define_clustering(attributes, aggregate_dict):
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 ", "")

Expand Down
2 changes: 1 addition & 1 deletion scripts/solve_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down