-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSnakefile
92 lines (77 loc) · 2.84 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
from snakemake.utils import validate
configfile: "config/default.yaml"
validate(config, "config/schema.yaml")
include: "rules/data-preprocessing.smk"
include: "rules/sonnendach.smk"
include: "rules/capacityfactors.smk"
include: "rules/potential.smk"
include: "rules/sync.smk"
localrules: all, clean
root_dir = config["root-directory"] + "/" if config["root-directory"] not in ["", "."] else ""
__version__ = open(f"{root_dir}VERSION").readlines()[0].strip()
script_dir = f"{root_dir}scripts/"
wildcard_constraints:
layer = "({layer_list})".format(layer_list="|".join((f"({layer})" for layer in config["layers"]))),
scenario = "({scenario_list})".format(scenario_list="|".join((f"({scenario})" for scenario in config["scenarios"])))
onstart:
shell("mkdir -p build/logs")
onsuccess:
if "pushcut_secret" in config.keys():
trigger_pushcut(event_name="snakemake_succeeded", secret=config["pushcut_secret"])
onerror:
if "pushcut_secret" in config.keys():
trigger_pushcut(event_name="snakemake_failed", secret=config["pushcut_secret"])
rule all:
message: "Run entire analysis and compile report."
input:
"build/logs/test-report.html",
expand(
"build/{layer}/{scenario}/potentials.csv",
scenario=config["scenarios"],
layer=config["layers"]
),
expand(
"build/{layer}/{scenario}/capacities.csv",
scenario=config["scenarios"],
layer=config["layers"]
),
expand(
"build/{layer}/{scenario}/areas.csv",
scenario=config["scenarios"],
layer=config["layers"]
)
rule clean: # removes all generated results
shell:
"""
rm -r ./build/*
echo "Data downloaded to data/ has not been cleaned."
"""
rule test:
message: "Run tests."
input:
expand("build/{layer}/technical-potential/potentials.csv", layer=config["layers"]),
"build/technically-eligible-land.tif",
"build/technically-eligible-area-km2.tif",
"build/technically-eligible-electricity-yield-pv-prio-twh.tif",
"build/administrative-borders.gpkg",
"data/automatic/sonnendach/total-rooftop-area-km2.txt",
"data/automatic/sonnendach/total-yield-twh.txt"
output: "build/logs/test-report.html"
conda: "envs/default.yaml"
shell:
"py.test --html={output} --self-contained-html"
rule build_metadata:
message: "Generate build metadata."
input:
script = script_dir + "metadata.py"
params:
config = config,
version = __version__
output: "build/model/build-metadata.yaml"
conda: "envs/metadata.yaml"
script: "scripts/metadata.py"
def trigger_pushcut(event_name, secret):
import requests
response = requests.post(
f'https://api.pushcut.io/{secret}/notifications/{event_name}'
)