forked from PyPSA/pypsa-eur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
279 lines (252 loc) · 11.1 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
configfile: "config.yaml"
COSTS="data/costs.csv"
wildcard_constraints:
lv="[0-9\.]+|inf|all",
simpl="[a-zA-Z0-9]*|all",
clusters="[0-9]+m?|all",
sectors="[+a-zA-Z0-9]+",
opts="[-+a-zA-Z0-9]*"
rule cluster_all_elec_networks:
input:
expand("networks/elec_s{simpl}_{clusters}_lv{lv}_{opts}.nc",
**config['scenario'])
rule solve_all_elec_networks:
input:
expand("results/networks/elec_s{simpl}_{clusters}_lv{lv}_{opts}.nc",
**config['scenario'])
if config['enable']['prepare_links_p_nom']:
rule prepare_links_p_nom:
output: 'data/links_p_nom.csv'
threads: 1
resources: mem=500
# group: 'nonfeedin_preparation'
script: 'scripts/prepare_links_p_nom.py'
if config['enable']['powerplantmatching']:
rule build_powerplants:
input: base_network="networks/base.nc"
output: "resources/powerplants.csv"
threads: 1
resources: mem=500
# group: 'nonfeedin_preparation'
script: "scripts/build_powerplants.py"
rule base_network:
input:
eg_buses='data/entsoegridkit/buses.csv',
eg_lines='data/entsoegridkit/lines.csv',
eg_links='data/entsoegridkit/links.csv',
eg_converters='data/entsoegridkit/converters.csv',
eg_transformers='data/entsoegridkit/transformers.csv',
parameter_corrections='data/parameter_corrections.yaml',
links_p_nom='data/links_p_nom.csv',
links_tyndp='data/links_tyndp.csv',
country_shapes='resources/country_shapes.geojson',
offshore_shapes='resources/offshore_shapes.geojson',
europe_shape='resources/europe_shape.geojson'
output: "networks/base.nc"
benchmark: "benchmarks/base_network"
threads: 1
resources: mem=500
# group: 'nonfeedin_preparation'
script: "scripts/base_network.py"
rule build_shapes:
input:
naturalearth='data/bundle/naturalearth/ne_10m_admin_0_countries.shp',
eez='data/bundle/eez/World_EEZ_v8_2014.shp',
nuts3='data/bundle/NUTS_2013_60M_SH/data/NUTS_RG_60M_2013.shp',
nuts3pop='data/bundle/nama_10r_3popgdp.tsv.gz',
nuts3gdp='data/bundle/nama_10r_3gdp.tsv.gz',
ch_cantons='data/bundle/ch_cantons.csv',
ch_popgdp='data/bundle/je-e-21.03.02.xls'
output:
country_shapes='resources/country_shapes.geojson',
offshore_shapes='resources/offshore_shapes.geojson',
europe_shape='resources/europe_shape.geojson',
nuts3_shapes='resources/nuts3_shapes.geojson'
threads: 1
resources: mem=500
# group: 'nonfeedin_preparation'
script: "scripts/build_shapes.py"
rule build_bus_regions:
input:
country_shapes='resources/country_shapes.geojson',
offshore_shapes='resources/offshore_shapes.geojson',
base_network="networks/base.nc"
output:
regions_onshore="resources/regions_onshore.geojson",
regions_offshore="resources/regions_offshore.geojson"
resources: mem=1000
# group: 'nonfeedin_preparation'
script: "scripts/build_bus_regions.py"
rule build_cutout:
output: "cutouts/{cutout}"
resources: mem=5000
threads: config['atlite'].get('nprocesses', 4)
benchmark: "benchmarks/build_cutout_{cutout}"
# group: 'feedin_preparation'
script: "scripts/build_cutout.py"
def memory_build_renewable_potentials(wildcards):
corine_config = config["renewable"][wildcards.technology]["corine"]
return 12000 if corine_config.get("distance") is None else 24000
rule build_renewable_potentials:
input:
cutout=lambda wildcards: "cutouts/" + config["renewable"][wildcards.technology]['cutout'],
corine="data/bundle/corine/g250_clc06_V18_5.tif",
natura="data/bundle/natura/Natura2000_end2015.shp"
output: "resources/potentials_{technology}.nc"
resources: mem=memory_build_renewable_potentials
benchmark: "benchmarks/build_renewable_potentials_{technology}"
# group: 'feedin_preparation'
script: "scripts/build_renewable_potentials.py"
rule build_renewable_profiles:
input:
base_network="networks/base.nc",
potentials="resources/potentials_{technology}.nc",
regions=lambda wildcards: ("resources/regions_onshore.geojson"
if wildcards.technology in ('onwind', 'solar')
else "resources/regions_offshore.geojson"),
cutout=lambda wildcards: "cutouts/" + config["renewable"][wildcards.technology]['cutout']
output:
profile="resources/profile_{technology}.nc",
resources: mem=5000
benchmark: "benchmarks/build_renewable_profiles_{technology}"
# group: 'feedin_preparation'
script: "scripts/build_renewable_profiles.py"
rule build_hydro_profile:
input:
country_shapes='resources/country_shapes.geojson',
eia_hydro_generation='data/bundle/EIA_hydro_generation_2000_2014.csv',
cutout="cutouts/" + config["renewable"]['hydro']['cutout']
output: 'resources/profile_hydro.nc'
resources: mem=5000
# group: 'feedin_preparation'
script: 'scripts/build_hydro_profile.py'
rule add_electricity:
input:
base_network='networks/base.nc',
tech_costs=COSTS,
regions="resources/regions_onshore.geojson",
powerplants='resources/powerplants.csv',
hydro_capacities='data/bundle/hydro_capacities.csv',
opsd_load='data/bundle/time_series_60min_singleindex_filtered.csv',
nuts3_shapes='resources/nuts3_shapes.geojson',
**{'profile_' + t: "resources/profile_" + t + ".nc"
for t in config['renewable']}
output: "networks/elec.nc"
benchmark: "benchmarks/add_electricity"
threads: 1
resources: mem=3000
# group: 'build_pypsa_networks'
script: "scripts/add_electricity.py"
rule simplify_network:
input:
network='networks/{network}.nc',
regions_onshore="resources/regions_onshore.geojson",
regions_offshore="resources/regions_offshore.geojson"
output:
network='networks/{network}_s{simpl}.nc',
regions_onshore="resources/regions_onshore_{network}_s{simpl}.geojson",
regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson",
clustermaps='resources/clustermaps_{network}_s{simpl}.h5'
benchmark: "benchmarks/simplify_network/{network}_s{simpl}"
threads: 1
resources: mem=4000
# group: 'build_pypsa_networks'
script: "scripts/simplify_network.py"
rule cluster_network:
input:
network='networks/{network}_s{simpl}.nc',
regions_onshore="resources/regions_onshore_{network}_s{simpl}.geojson",
regions_offshore="resources/regions_offshore_{network}_s{simpl}.geojson",
clustermaps=ancient('resources/clustermaps_{network}_s{simpl}.h5')
output:
network='networks/{network}_s{simpl}_{clusters}.nc',
regions_onshore="resources/regions_onshore_{network}_s{simpl}_{clusters}.geojson",
regions_offshore="resources/regions_offshore_{network}_s{simpl}_{clusters}.geojson",
clustermaps='resources/clustermaps_{network}_s{simpl}_{clusters}.h5'
benchmark: "benchmarks/cluster_network/{network}_s{simpl}_{clusters}"
threads: 1
resources: mem=3000
# group: 'build_pypsa_networks'
script: "scripts/cluster_network.py"
# rule add_sectors:
# input:
# network="networks/elec_{cost}_{resarea}_{opts}.nc",
# emobility="data/emobility"
# output: "networks/sector_{cost}_{resarea}_{sectors}_{opts}.nc"
# benchmark: "benchmarks/add_sectors/sector_{resarea}_{sectors}_{opts}"
# threads: 1
# resources: mem=1000
# script: "scripts/add_sectors.py"
rule prepare_network:
input: 'networks/{network}_s{simpl}_{clusters}.nc', tech_costs=COSTS
output: 'networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc'
threads: 1
resources: mem=1000
# benchmark: "benchmarks/prepare_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}"
script: "scripts/prepare_network.py"
def memory(w):
factor = 3.
for o in w.opts.split('-'):
m = re.match(r'^(\d+)h$', o, re.IGNORECASE)
if m is not None:
factor /= int(m.group(1))
break
if w.clusters.endswith('m'):
return int(factor * (18000 + 180 * int(w.clusters[:-1])))
else:
return int(factor * (10000 + 190 * int(w.clusters)))
# return 4890+310 * int(w.clusters)
rule solve_network:
input: "networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"
output: "results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"
shadow: "shallow"
log:
solver="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_solver.log",
python="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_python.log",
memory="logs/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_memory.log"
benchmark: "benchmarks/solve_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}"
threads: 4
resources: mem=memory
# group: "solve" # with group, threads is ignored https://bitbucket.org/snakemake/snakemake/issues/971/group-job-description-does-not-contain
script: "scripts/solve_network.py"
rule solve_operations_network:
input:
unprepared="networks/{network}_s{simpl}_{clusters}.nc",
optimized="results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc"
output: "results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_op.nc"
shadow: "shallow"
log:
solver="logs/solve_operations_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_op_solver.log",
python="logs/solve_operations_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_op_python.log",
memory="logs/solve_operations_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_op_memory.log"
benchmark: "benchmarks/solve_operations_network/{network}_s{simpl}_{clusters}_lv{lv}_{opts}"
threads: 4
resources: mem=(lambda w: 5000 + 372 * int(w.clusters))
# group: "solve_operations"
script: "scripts/solve_operations_network.py"
rule plot_network:
input:
network="results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc",
tech_costs=COSTS
output:
only_map="results/plots/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{attr}.{ext}",
ext="results/plots/{network}_s{simpl}_{clusters}_lv{lv}_{opts}_{attr}_ext.{ext}"
script: "scripts/plot_network.py"
def summary_networks(w):
# It's mildly hacky to include the separate costs input as first entry
return ([COSTS] +
expand("results/networks/{network}_s{simpl}_{clusters}_lv{lv}_{opts}.nc",
network=w.network,
**{k: config["scenario"][k] if getattr(w, k) == "all" else getattr(w, k)
for k in ["simpl", "clusters", "lv", "opts"]}))
rule make_summary:
input: summary_networks
output: directory("results/summaries/{network}_s{simpl}_{clusters}_lv{lv}_{opts}")
script: "scripts/make_summary.py"
rule plot_summary:
input: directory("results/summaries/{network}_s{simpl}_{clusters}_lv{lv}_{opts}")
output: "results/plots/summary_{summary}_{network}_s{simpl}_{clusters}_lv{lv}_{opts}.{ext}"
script: "scripts/plot_summary.py"
# Local Variables:
# mode: python
# End: