forked from open-energy-transition/pypsa-eur
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsolve_myopic.smk
More file actions
194 lines (182 loc) · 8.21 KB
/
Copy pathsolve_myopic.smk
File metadata and controls
194 lines (182 loc) · 8.21 KB
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
# SPDX-FileCopyrightText: Contributors to Open-TYNDP <https://github.com/open-energy-transition/open-tyndp>
# SPDX-FileCopyrightText: Contributors to PyPSA-Eur <https://github.com/pypsa/pypsa-eur>
#
# SPDX-License-Identifier: MIT
rule add_existing_baseyear:
input:
unpack(input_conventional),
network=resources(
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
),
powerplants=branch(
lambda w: config_provider("electricity", "conventional_carriers")(w)
or config_provider("electricity", "extendable_carriers", "Generator")(w),
resources("powerplants_s_{clusters}.csv"),
),
costs=lambda w: resources(
f"costs_{config_provider('scenario', 'planning_horizons',0)(w)}_processed.csv"
),
cop_profiles=resources("cop_profiles_base_s_{clusters}_{planning_horizons}.nc"),
existing_heating_distribution=resources(
"existing_heating_distribution_base_s_{clusters}_{planning_horizons}.csv"
),
heating_efficiencies=resources("heating_efficiencies.csv"),
output:
resources(
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_brownfield.nc"
),
log:
logs(
"add_existing_baseyear_base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.log"
),
benchmark:
benchmarks(
"performances/add_existing_baseyear/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}"
)
wildcard_constraints:
# TODO: The first planning_horizon needs to be aligned across scenarios
# snakemake does not support passing functions to wildcard_constraints
# reference: https://github.com/snakemake/snakemake/issues/2703
planning_horizons=config["scenario"]["planning_horizons"][0], #only applies to baseyear
threads: 1
resources:
mem_mb=3000,
params:
baseyear=config_provider("scenario", "planning_horizons", 0),
sector=config_provider("sector"),
existing_capacities=config_provider("existing_capacities"),
carriers=config_provider("electricity", "renewable_carriers"),
costs=config_provider("costs"),
heat_pump_sources=config_provider("sector", "heat_pump_sources"),
energy_totals_year=config_provider("energy", "energy_totals_year"),
load_source=config_provider("load", "source"),
conventional=config_provider("conventional"),
conventional_carriers=config_provider("electricity", "conventional_carriers"),
message:
"Adding existing infrastructure for base year for {wildcards.clusters} clusters, {wildcards.planning_horizons} planning horizons, {wildcards.opts} electric options and {wildcards.sector_opts} sector options"
script:
scripts("add_existing_baseyear.py")
def input_profile_tech_brownfield(w):
return {
f"profile_{tech}": resources("profile_{clusters}_" + tech + ".nc")
for tech in (set(config_provider("electricity", "renewable_carriers")(w)))
if tech != "hydro"
}
def input_profile_tech_brownfield_pecd(w):
return {
f"profile_{tech}": resources("profile_pecd_{clusters}_" + tech + ".nc")
for tech in pecd_techs(w)
}
rule add_brownfield:
input:
unpack(input_profile_tech_brownfield),
unpack(input_profile_tech_brownfield_pecd),
network=resources(
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
),
network_p=solved_previous_horizon, #solved network at previous time step
carrier_mapping="data/tyndp_technology_map.csv",
output:
resources(
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_brownfield.nc"
),
log:
logs(
"add_brownfield_base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.log"
),
benchmark:
benchmarks(
"performances/add_brownfield/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}"
)
threads: 4
resources:
mem_mb=10000,
params:
H2_retrofit=config_provider("sector", "H2_retrofit"),
H2_retrofit_capacity_per_CH4=config_provider(
"sector", "H2_retrofit_capacity_per_CH4"
),
threshold_capacity=config_provider("existing_capacities", "threshold_capacity"),
snapshots=config_provider("snapshots"),
drop_leap_day=config_provider("enable", "drop_leap_day"),
carriers=config_provider("electricity", "renewable_carriers"),
heat_pump_sources=config_provider("sector", "heat_pump_sources"),
tes=config_provider("sector", "tes"),
dynamic_ptes_capacity=config_provider(
"sector", "district_heating", "ptes", "dynamic_capacity"
),
offshore_hubs_tyndp=config_provider("sector", "offshore_hubs_tyndp", "enable"),
h2_topology_tyndp=config_provider("sector", "h2_topology_tyndp"),
carriers_tyndp=config_provider("electricity", "tyndp_renewable_carriers"),
tyndp_conventional_carriers=config_provider(
"electricity", "tyndp_conventional_carriers"
),
tyndp_renewable_carriers=config_provider(
"electricity", "tyndp_renewable_carriers"
),
hydrogen_fuel_cell=config_provider("sector", "hydrogen_fuel_cell"),
hydrogen_turbine=config_provider("sector", "hydrogen_turbine"),
group_tyndp_conventionals=config_provider(
"electricity", "group_tyndp_conventionals"
),
uniform_renewable_profiles=config_provider(
"existing_capacities", "uniform_renewable_profiles"
),
message:
"Adding brownfield constraints for existing infrastructure for {wildcards.clusters} clusters, {wildcards.planning_horizons} planning horizons, {wildcards.opts} electric options and {wildcards.sector_opts} sector options"
script:
scripts("add_brownfield.py")
ruleorder: add_existing_baseyear > add_brownfield
rule solve_sector_network_myopic:
input:
network=resources(
"networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_brownfield.nc"
),
offshore_zone_trajectories=branch(
config_provider("sector", "offshore_hubs_tyndp", "enable"),
resources("offshore_zone_trajectories.csv"),
),
output:
network=RESULTS
+ "networks/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc",
config=RESULTS
+ "configs/config.base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.yaml",
model=(
RESULTS
+ "models/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}.nc"
if config["solving"]["options"]["store_model"]
else []
),
log:
solver=RESULTS
+ "logs/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_solver.log",
memory=RESULTS
+ "logs/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_memory.log",
python=RESULTS
+ "logs/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}_python.log",
benchmark:
(
RESULTS
+ "benchmarks/performances/solve_sector_network/base_s_{clusters}_{opts}_{sector_opts}_{planning_horizons}"
)
shadow:
shadow_config
threads: solver_threads
resources:
mem_mb=config_provider("solving", "mem_mb"),
runtime=config_provider("solving", "runtime", default="6h"),
params:
solving=config_provider("solving"),
foresight=config_provider("foresight"),
co2_sequestration_potential=config_provider(
"sector", "co2_sequestration_potential", default=200
),
custom_extra_functionality=input_custom_extra_functionality,
renewable_carriers=config_provider("electricity", "renewable_carriers"),
renewable_carriers_tyndp=config_provider(
"electricity", "tyndp_renewable_carriers"
),
message:
"Solving sector-coupled network with myopic foresight for {wildcards.clusters} clusters, {wildcards.planning_horizons} planning horizons, {wildcards.opts} electric options and {wildcards.sector_opts} sector options"
script:
scripts("solve_network.py")