Merge branch 'master' into validation

This commit is contained in:
Fabian Hofmann 2023-08-03 18:28:10 +02:00 committed by GitHub
commit 6e7bbe1e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 43 deletions

View File

@ -395,7 +395,7 @@ rule simplify_network:
BENCHMARKS + "simplify_network/elec_s{simpl}" BENCHMARKS + "simplify_network/elec_s{simpl}"
threads: 1 threads: 1
resources: resources:
mem_mb=10000, mem_mb=12000,
conda: conda:
"../envs/environment.yaml" "../envs/environment.yaml"
script: script:

View File

@ -295,7 +295,7 @@ rule build_biomass_potentials:
"../scripts/build_biomass_potentials.py" "../scripts/build_biomass_potentials.py"
if config["sector"]["biomass_transport"]: if config["sector"]["biomass_transport"] or config["sector"]["biomass_spatial"]:
rule build_biomass_transport_costs: rule build_biomass_transport_costs:
input: input:
@ -320,9 +320,8 @@ if config["sector"]["biomass_transport"]:
build_biomass_transport_costs_output = rules.build_biomass_transport_costs.output build_biomass_transport_costs_output = rules.build_biomass_transport_costs.output
if not config["sector"]["biomass_transport"]: if not (config["sector"]["biomass_transport"] or config["sector"]["biomass_spatial"]):
# this is effecively an `else` statement which is however not liked by snakefmt # this is effecively an `else` statement which is however not liked by snakefmt
build_biomass_transport_costs_output = {} build_biomass_transport_costs_output = {}

View File

@ -39,7 +39,7 @@ rule copy_config:
params: params:
RDIR=RDIR, RDIR=RDIR,
output: output:
RESULTS + "config/config.yaml", RESULTS + "config.yaml",
threads: 1 threads: 1
resources: resources:
mem_mb=1000, mem_mb=1000,
@ -51,22 +51,6 @@ rule copy_config:
"../scripts/copy_config.py" "../scripts/copy_config.py"
rule copy_conda_env:
output:
RESULTS + "config/environment.yaml",
threads: 1
resources:
mem_mb=500,
log:
LOGS + "copy_conda_env.log",
benchmark:
BENCHMARKS + "copy_conda_env"
conda:
"../envs/environment.yaml"
shell:
"conda env export -f {output} --no-builds"
rule make_summary: rule make_summary:
params: params:
foresight=config["foresight"], foresight=config["foresight"],

View File

@ -13,6 +13,7 @@ rule solve_network:
), ),
input: input:
network=RESOURCES + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", network=RESOURCES + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
config=RESULTS + "config.yaml",
output: output:
network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", network=RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc",
log: log:

View File

@ -92,7 +92,7 @@ rule solve_sector_network_myopic:
network=RESULTS network=RESULTS
+ "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "prenetworks-brownfield/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
costs="data/costs_{planning_horizons}.csv", costs="data/costs_{planning_horizons}.csv",
config=RESULTS + "config/config.yaml", config=RESULTS + "config.yaml",
output: output:
RESULTS RESULTS
+ "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",

View File

@ -14,9 +14,7 @@ rule solve_sector_network:
input: input:
network=RESULTS network=RESULTS
+ "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",
costs="data/costs_{}.csv".format(config["costs"]["year"]), config=RESULTS + "config.yaml",
config=RESULTS + "config/config.yaml",
#env=RDIR + 'config/environment.yaml',
output: output:
RESULTS RESULTS
+ "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc",

View File

@ -11,25 +11,13 @@ from shutil import copy
import yaml import yaml
files = {
"config/config.yaml": "config.yaml",
"Snakefile": "Snakefile",
"scripts/solve_network.py": "solve_network.py",
"scripts/prepare_sector_network.py": "prepare_sector_network.py",
}
if __name__ == "__main__": if __name__ == "__main__":
if "snakemake" not in globals(): if "snakemake" not in globals():
from _helpers import mock_snakemake from _helpers import mock_snakemake
snakemake = mock_snakemake("copy_config") snakemake = mock_snakemake("copy_config")
basepath = Path(f"results/{snakemake.params.RDIR}config/") with open(snakemake.output[0], "w") as yaml_file:
for f, name in files.items():
copy(f, basepath / name)
with open(basepath / "config.snakemake.yaml", "w") as yaml_file:
yaml.dump( yaml.dump(
snakemake.config, snakemake.config,
yaml_file, yaml_file,

View File

@ -2156,12 +2156,11 @@ def add_biomass(n, costs):
) )
if options["biomass_transport"]: if options["biomass_transport"]:
transport_costs = pd.read_csv(
snakemake.input.biomass_transport_costs,
index_col=0,
).squeeze()
# add biomass transport # add biomass transport
transport_costs = pd.read_csv(
snakemake.input.biomass_transport_costs, index_col=0
)
transport_costs = transport_costs.squeeze()
biomass_transport = create_network_topology( biomass_transport = create_network_topology(
n, "biomass transport ", bidirectional=False n, "biomass transport ", bidirectional=False
) )
@ -2185,6 +2184,27 @@ def add_biomass(n, costs):
carrier="solid biomass transport", carrier="solid biomass transport",
) )
elif options["biomass_spatial"]:
# add artificial biomass generators at nodes which include transport costs
transport_costs = pd.read_csv(
snakemake.input.biomass_transport_costs, index_col=0
)
transport_costs = transport_costs.squeeze()
bus_transport_costs = spatial.biomass.nodes.to_series().apply(
lambda x: transport_costs[x[:2]]
)
average_distance = 200 # km #TODO: validate this assumption
n.madd(
"Generator",
spatial.biomass.nodes,
bus=spatial.biomass.nodes,
carrier="solid biomass",
p_nom=10000,
marginal_cost=costs.at["solid biomass", "fuel"]
+ bus_transport_costs * average_distance,
)
# AC buses with district heating # AC buses with district heating
urban_central = n.buses.index[n.buses.carrier == "urban central heat"] urban_central = n.buses.index[n.buses.carrier == "urban central heat"]
if not urban_central.empty and options["chp"]: if not urban_central.empty and options["chp"]: