forked from PyPSA/pypsa-eur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
100 lines (69 loc) · 2.25 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
from os.path import normpath, exists
from shutil import copyfile, move, rmtree
from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider
HTTP = HTTPRemoteProvider()
from snakemake.utils import min_version
min_version("7.7")
if not exists("config/config.yaml"):
copyfile("config/config.default.yaml", "config/config.yaml")
configfile: "config/config.yaml"
COSTS = f"data/costs_{config['costs']['year']}.csv"
ATLITE_NPROCESSES = config["atlite"].get("nprocesses", 4)
run = config.get("run", {})
RDIR = run["name"] + "/" if run.get("name") else ""
CDIR = RDIR if not run.get("shared_cutouts") else ""
LOGS = "logs/" + RDIR
BENCHMARKS = "benchmarks/" + RDIR
RESOURCES = "resources/" + RDIR if not run.get("shared_resources") else "resources/"
RESULTS = "results/" + RDIR
localrules:
purge,
wildcard_constraints:
simpl="[a-zA-Z0-9]*",
clusters="[0-9]+m?|all",
ll="(v|c)([0-9\.]+|opt)",
opts="[-+a-zA-Z0-9\.]*",
sector_opts="[-+a-zA-Z0-9\.\s]*",
include: "rules/common.smk"
include: "rules/collect.smk"
include: "rules/retrieve.smk"
include: "rules/build_electricity.smk"
include: "rules/build_sector.smk"
include: "rules/solve_electricity.smk"
include: "rules/postprocess.smk"
if config["foresight"] == "overnight":
include: "rules/solve_overnight.smk"
if config["foresight"] == "myopic":
include: "rules/solve_myopic.smk"
rule purge:
message:
"Purging generated resources, results and docs. Downloads are kept."
run:
rmtree("resources/", ignore_errors=True)
rmtree("results/", ignore_errors=True)
rmtree("doc/_build", ignore_errors=True)
rule dag:
message:
"Creating DAG of workflow."
output:
dot=RESOURCES + "dag.dot",
pdf=RESOURCES + "dag.pdf",
png=RESOURCES + "dag.png",
conda:
"envs/environment.yaml"
shell:
"""
snakemake --rulegraph all | sed -n "/digraph/,\$p" > {output.dot}
dot -Tpdf -o {output.pdf} {output.dot}
dot -Tpng -o {output.png} {output.dot}
"""
rule doc:
message:
"Build documentation."
output:
directory("doc/_build"),
shell:
"make -C doc html"