-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
173 lines (154 loc) · 5.68 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Download files using Snakemake
from snakemake.remote.HTTP import RemoteProvider as HTTPRemoteProvider
HTTP = HTTPRemoteProvider()
# Filesystem operations
import shutil
# Extract zip files
import zipfile
configfile: "config.yaml"
wildcard_constraints:
scenario="[a-zA-Z0-9\.\-\_]+",
country="[a-zA-Z]+"
# Download timeseries Bloomfield and Brayshaw (2021) fomr https://doi.org/10.17864/1947.000321
rule download_timeseries:
input:
HTTP.remote(
"researchdata.reading.ac.uk/321/4/ERA5_data_1950-2020.zip",
),
output:
solar="data/NUTS_0_sp_historical.nc",
onwind0="data/NUTS_0_wp_ons_sim_0_historical_loc_weighted.nc",
onwind1="data/NUTS_0_wp_ons_sim_1_historical_loc_weighted.nc",
temperature="data/NUTS_0_t2m_detrended_timeseries_historical_pop_weighted.nc",
run:
# Files to extract
fps = [
"ERA5_data_1950-2020/solar_power_capacity_factor/NUTS_0_sp_historical.nc",
"ERA5_data_1950-2020/wp_onshore/NUTS_0_wp_ons_sim_0_historical_loc_weighted.nc",
"ERA5_data_1950-2020/wp_onshore/NUTS_0_wp_ons_sim_1_historical_loc_weighted.nc",
"ERA5_data_1950-2020/t2m/NUTS_0_t2m_detrended_timeseries_historical_pop_weighted.nc",
]
# extract and move files to this dir
output_dir = "data/"
with zipfile.ZipFile(input[0], "r") as zf:
for fp in fps:
zf.extract(fp, output_dir)
shutil.move(output_dir + fp, output_dir + str(Path(fp).name))
# Delete folders created from extracting zip file
shutil.rmtree("data/ERA5_data_1950-2020")
rule solve_all:
input:
statistics="summaries/" + config['run'] + "/statistics.csv",
balances="summaries/" + config['run'] + "/balances.csv",
config="summaries/" + config['run'] + "/config.yaml"
rule copy_config:
output: "summaries/" + config['run'] + "/config.yaml"
threads: 1
resources: mem_mb=1000
script: "copy_config.py"
rule summarise_networks:
input:
expand("summaries/" + config['run'] + "/statistics-{country}-{scenario}.csv",
**config['run_settings'])
output: "summaries/" + config['run'] + "/statistics.csv"
group: "results"
threads: 1
resources:
mem_mb=2000
script: "summarise_networks.py"
rule summarise_network:
input: "networks/" + config['run'] + "/{country}-{scenario}.nc"
output: "summaries/" + config['run'] + "/statistics-{country}-{scenario}.csv"
group: "scenario"
resources:
mem_mb=50000
script: "summarise_network.py"
rule balances_networks:
input:
expand("summaries/" + config['run'] + "/balances-{country}-{scenario}.csv",
**config['run_settings'])
output: "summaries/" + config['run'] + "/balances.csv"
group: "results"
threads: 1
resources:
mem_mb=2000
script: "summarise_networks.py"
rule balances_network:
input: "networks/" + config['run'] + "/{country}-{scenario}.nc"
output: "summaries/" + config['run'] + "/balances-{country}-{scenario}.csv"
group: "scenario"
resources:
mem_mb=50000
script: "balances_network.py"
rule get_fillings:
input:
expand("filling/" + config['run'] + "/filling-{country}-{scenario}.csv",
**config['run_settings'])
rule get_filling:
input: "networks/" + config['run'] + "/{country}-{scenario}.nc"
output: "filling/" + config['run'] + "/filling-{country}-{scenario}.csv"
group: "scenario"
resources:
mem_mb=50000
script: "get_filling.py"
rule solve:
input:
solar=rules.download_timeseries.output.solar,
onwind0=rules.download_timeseries.output.onwind0,
onwind1=rules.download_timeseries.output.onwind1,
temperature=rules.download_timeseries.output.temperature,
output:
"networks/" + config['run'] + "/{country}-{scenario}.nc"
group: "scenario"
threads: 4
resources:
mem_mb=50000
benchmark:
"benchmarks/" + config['run'] + "/{country}-{scenario}.tsv"
log:
solver="logs/" + config['run'] + "/{country}-{scenario}-solver.log",
python="logs/" + config['run'] + "/{country}-{scenario}-python.log",
memory="logs/" + config['run'] + "/{country}-{scenario}-memory.log",
script: "solve.py"
rule plot_cost:
input:
statistics="summaries/" + config['run'] + "/statistics.csv",
output:
costs="summaries/" + config['run'] + "/costs.pdf",
group: "results"
script:
"plot_costs.py"
rule plot_cascade:
input:
statistics="summaries/" + config['run'] + "/statistics.csv",
output:
scenarios=[
'summaries/'+config['run']+'/cascade-DE-71a-1H-H2u.pdf',
'summaries/'+config['run']+'/cascade-DE-71a-1H-H2s.pdf',
'summaries/'+config['run']+'/cascade-DE-71a-1H-H2s-wm-nH2t-mflex0-ramp10.pdf',
'summaries/'+config['run']+'/cascade-DE-71a-1H-H2s-wm-nH2t-mflex50-ramp5.pdf',
'summaries/'+config['run']+'/cascade-DE-71a-1H-H2s-wm-nH2t-mflex0-ramp10-ccgt.pdf']
group: "results"
script:
"plot_cascade.py"
rule plot_storage_filling_level:
input:
methanol="networks/" + config['run'] + "/DE-71a-1H-H2s-wm-nH2t-mflex0-ramp10.nc",
hydrogen="networks/" + config['run'] + "/DE-71a-1H-H2u.nc",
output:
figure="summaries/" + config['run'] + "/storage_filling_level.pdf"
group: "results"
script:
"plot_storage_filling_level.py"
rule plot_all:
input:
rules.plot_cost.output,
rules.plot_cascade.output,
rules.plot_storage_filling_level.output,
group: "results"
rule all:
input:
rules.solve_all.input,
rules.plot_all.input,
# default_target: True
# localrule: True