update solve smk files to properly consider scenanrios

This commit is contained in:
Fabian 2023-09-22 13:58:08 +02:00
parent c7e6d36014
commit f96c2d0589
5 changed files with 44 additions and 37 deletions

View File

@ -10,6 +10,9 @@ def get_config(config, keys, default=None):
"""Retrieve a nested value from a dictionary using a tuple of keys."""
value = config
for key in keys:
if isinstance(value, list):
value = value[key]
else:
value = value.get(key, default)
if value == default:
return default
@ -40,7 +43,7 @@ def static_getter(wildcards, keys, default):
def dynamic_getter(wildcards, keys, default):
"""Getter function for dynamic config values based on scenario."""
if "run" not in wildcards:
if "run" not in wildcards.keys():
return get_config(config, keys, default)
scenario_name = wildcards.run
if scenario_name not in scenarios:

View File

@ -5,11 +5,11 @@
rule solve_network:
params:
solving=config["solving"],
foresight=config["foresight"],
planning_horizons=config["scenario"]["planning_horizons"],
co2_sequestration_potential=config["sector"].get(
"co2_sequestration_potential", 200
solving=config_provider("solving"),
foresight=config_provider("foresight"),
planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config_provider(
"sector", "co2_sequestration_potential", default=200
),
input:
network=resources("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"),
@ -27,7 +27,7 @@ rule solve_network:
threads: 4
resources:
mem_mb=memory,
walltime=config["solving"].get("walltime", "12:00:00"),
walltime=config_provider("solving", "walltime", default="12:00:00"),
shadow:
"minimal"
conda:
@ -38,7 +38,7 @@ rule solve_network:
rule solve_operations_network:
params:
options=config["solving"]["options"],
options=config_provider("solving", "options"),
input:
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
output:
@ -58,7 +58,7 @@ rule solve_operations_network:
threads: 4
resources:
mem_mb=(lambda w: 10000 + 372 * int(w.clusters)),
walltime=config["solving"].get("walltime", "12:00:00"),
walltime=config_provider("solving", "walltime", default="12:00:00"),
shadow:
"minimal"
conda:

View File

@ -5,10 +5,10 @@
rule add_existing_baseyear:
params:
baseyear=config["scenario"]["planning_horizons"][0],
sector=config["sector"],
existing_capacities=config["existing_capacities"],
costs=config["costs"],
baseyear=config_provider("scenario", "planning_horizons", 0),
sector=config_provider("sector"),
existing_capacities=config_provider("existing_capacities"),
costs=config_provider("costs"),
input:
network=RESULTS
+ "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
@ -16,7 +16,9 @@ rule add_existing_baseyear:
busmap_s=resources("busmap_elec_s{simpl}.csv"),
busmap=resources("busmap_elec_s{simpl}_{clusters}.csv"),
clustered_pop_layout=resources("pop_layout_elec_s{simpl}_{clusters}.csv"),
costs="data/costs_{}.csv".format(config["scenario"]["planning_horizons"][0]),
costs=lambda w: "data/costs_{}.csv".format(
config_provider("scenario", "planning_horizons", 0)(w)
),
cop_soil_total=resources("cop_soil_total_elec_s{simpl}_{clusters}.nc"),
cop_air_total=resources("cop_air_total_elec_s{simpl}_{clusters}.nc"),
existing_heating="data/existing_infrastructure/existing_heating_raw.csv",
@ -27,7 +29,7 @@ rule add_existing_baseyear:
RESULTS
+ "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
wildcard_constraints:
planning_horizons=config["scenario"]["planning_horizons"][0], #only applies to baseyear
planning_horizons=config_provider("scenario", "planning_horizons", 0), #only applies to baseyear
threads: 1
resources:
mem_mb=2000,
@ -47,9 +49,11 @@ rule add_existing_baseyear:
rule add_brownfield:
params:
H2_retrofit=config["sector"]["H2_retrofit"],
H2_retrofit_capacity_per_CH4=config["sector"]["H2_retrofit_capacity_per_CH4"],
threshold_capacity=config["existing_capacities"]["threshold_capacity"],
H2_retrofit=config_provider("sector", "H2_retrofit"),
H2_retrofit_capacity_per_CH4=config_provider(
"sector", "H2_retrofit_capacity_per_CH4"
),
threshold_capacity=config_provider("existing_capacities", " threshold_capacity"),
input:
network=RESULTS
+ "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
@ -82,11 +86,11 @@ ruleorder: add_existing_baseyear > add_brownfield
rule solve_sector_network_myopic:
params:
solving=config["solving"],
foresight=config["foresight"],
planning_horizons=config["scenario"]["planning_horizons"],
co2_sequestration_potential=config["sector"].get(
"co2_sequestration_potential", 200
solving=config_provider("solving"),
foresight=config_provider("foresight"),
planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config_provider(
"sector", "co2_sequestration_potential", default=200
),
input:
network=RESULTS
@ -105,8 +109,8 @@ rule solve_sector_network_myopic:
+ "elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}_python.log",
threads: 4
resources:
mem_mb=config["solving"]["mem"],
walltime=config["solving"].get("walltime", "12:00:00"),
mem_mb=config_provider("solving", "mem"),
walltime=config_provider("solving", "walltime", default="12:00:00"),
benchmark:
(
BENCHMARKS

View File

@ -5,11 +5,11 @@
rule solve_sector_network:
params:
solving=config["solving"],
foresight=config["foresight"],
planning_horizons=config["scenario"]["planning_horizons"],
co2_sequestration_potential=config["sector"].get(
"co2_sequestration_potential", 200
solving=config_provider("solving"),
foresight=config_provider("foresight"),
planning_horizons=config_provider("scenario", "planning_horizons"),
co2_sequestration_potential=config_provider(
"sector", "co2_sequestration_potential", default=200
),
input:
network=RESULTS
@ -27,8 +27,8 @@ rule solve_sector_network:
+ "elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}_python.log",
threads: config["solving"]["solver"].get("threads", 4)
resources:
mem_mb=config["solving"]["mem"],
walltime=config["solving"].get("walltime", "12:00:00"),
mem_mb=config_provider("solving", "mem"),
walltime=config_provider("solving", "walltime", default="12:00:00"),
benchmark:
(
BENCHMARKS

View File

@ -137,10 +137,10 @@ def add_co2_sequestration_limit(n, limit=200):
n.add(
"GlobalConstraint",
"co2_sequestration_limit",
sense="<=",
constant=limit,
type="primary_energy",
carrier_attribute="co2_absorptions",
sense=">=",
constant=-limit,
type="operational_limit",
carrier_attribute="co2 sequestered",
)