-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerate_defaults.py
321 lines (239 loc) · 19.3 KB
/
generate_defaults.py
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
import pandas as pd, urllib.request, os, yaml
df = pd.read_csv("defaults-initial.csv",
index_col=[0,1],
na_filter=False)
with open("config.yaml", "r") as f:
config = yaml.safe_load(f)
years = config["tech_years"]
df.at[("year",""),"text"] = df.at[("year",""),"text"].replace("weather_years",str(config["weather_years"])[1:-1])
#get technology data
td = {}
for year in years:
fn = f"costs_{year}.csv"
url = f"https://raw.githubusercontent.com/PyPSA/technology-data/{config['tech_data_commit']}/outputs/{fn}"
if not os.path.isfile(fn):
print("downloading",fn)
urllib.request.urlretrieve(url,fn)
td[year] = pd.read_csv(fn,
index_col=[0,1])
#get traces efficiencies
fn = "efficiencies.csv"
url = f"https://raw.githubusercontent.com/euronion/trace/{config['trace_commit']}/data/{fn}"
if not os.path.isfile(fn):
print("downloading",fn)
urllib.request.urlretrieve(url,fn)
eff = pd.read_csv(fn,
index_col=[0,1,2])
#get traces shipping data
fn = "shipping.csv"
url = f"https://raw.githubusercontent.com/euronion/trace/{config['trace_commit']}/data/{fn}"
if not os.path.isfile(fn):
print("downloading",fn)
urllib.request.urlretrieve(url,fn)
shipping = pd.read_csv(fn,
index_col=[0,1])
for name,td_name,full_name in [("methanolisation","methanolisation","Methanol synthesis"),
("methanation","methanation","Methanation"),
("methane_liquefaction","CH4 liquefaction","Methane liquefaction"),
("ft","Fischer-Tropsch","Fischer-Tropsch synthesis"),
("hydrogen_liquefaction","H2 liquefaction","Hydrogen liquefaction"),
("wind","onwind","Onshore wind turbine"),
("solar","solar-utility","Utility-scale solar PV"),
("hydrogen_electrolyser","electrolysis","Hydrogen electrolyser"),
("desalination","seawater desalination","Seawater desalination"),
("hydrogen_energy","hydrogen storage tank type 1","Hydrogen overground tank storage"),
("methane_storage","methane storage tank incl. compressor","Methane overground tank storage"),
("hydrogen_turbine","CCGT","Hydrogen combined cycle turbine"),
("hydrogen_submarine_pipeline","H2 (g) submarine pipeline","Hydrogen submarine pipeline"),
("hvdc_submarine_cable","HVDC submarine","HVDC submarine cable"),
("hvdc_inverter_pair","HVDC inverter pair","HVDC AC-DC inverter pair"),
("battery_energy","battery storage","Utility-scale battery energy"),
("battery_power","battery inverter","Utility-scale battery converter power"),
("dac","direct air capture","Direct air capture"),
("heat_pump","industrial heat pump medium temperature","Industrial heat pump up to 125 C"),
("liquid_carbonaceous_storage","General liquid hydrocarbon storage (product)","Liquid carbonaceous fuel storage tank"),
("air_separation_unit","air separation unit","Air separation unit for nitrogen"),
("haber_bosch","Haber-Bosch","Haber-Bosch ammonia synthesis"),
("ammonia_storage","NH3 (l) storage tank incl. liquefaction","Liquid ammonia storage"),
("co2_storage","CO2 storage tank","CO2 storage tank"),
("hydrogen_compressor","hydrogen storage compressor","Hydrogen storage compressor")]:
print(name,full_name)
df.loc[(name + "_discount",""),:] = ["f",5,"percent",full_name + " discount rate",""]
for year in years:
value = td[year].loc[(td_name,"investment"),"value"]
unit = td[year].loc[(td_name,"investment"),"unit"]
df.loc[(name + "_cost",str(year)),:] = ["f",
value,
unit,
full_name + " capital cost (overnight)",
td[year].loc[(td_name,"investment"),"source"]]
df.loc[(name + "_fom",str(year)),:] = ["f",
td[year].loc[(td_name,"FOM"),"value"] if (td_name,"FOM") in td[year].index else 0,
"percent of overnight cost per year",
full_name + " fixed operation and maintenance costs",
td[year].loc[(td_name,"FOM"),"source"] if (td_name,"FOM") in td[year].index else "default"]
df.loc[(name + "_lifetime",str(year)),:] = ["f",
td[year].loc[(td_name,"lifetime"),"value"],
td[year].loc[(td_name,"lifetime"),"unit"],
full_name + " lifetime",
td[year].loc[(td_name,"lifetime"),"source"]]
#fix mistake in TD
for year in years:
df.loc[("methanation_cost",str(year)),"unit"] = "EUR/kW_CH4"
for name,td_name,full_name in [("battery_power_efficiency_charging","battery inverter","Battery power charging efficiency"),
("battery_power_efficiency_discharging","battery inverter","Battery power discharging efficiency"),
("heat_pump_efficiency","industrial heat pump medium temperature","Industrial heat pump COP"),
("hydrogen_electrolyser_efficiency","electrolysis","Hydrogen electrolyser efficiency"),
("hydrogen_turbine_efficiency","CCGT","Hydrogen combined cycle turbine efficiency")]:
for year in years:
value = 100*td[year].loc[(td_name,"efficiency"),"value"]
unit = "percent"
if "battery" in name:
value = 100*((value/100.)**0.5)
elif "hydrogen" in name:
unit ='"percent, LHV"'
df.loc[(name,str(year)),:] = ["f",
value,
unit,
full_name,
td[year].loc[(td_name,"efficiency"),"source"]]
df.loc[("hydrogen_electrolyser_water",""),:] = ["f",
eff.loc[("electrolysis","all","water"),"from_amount"][0]/eff.loc[("electrolysis","all","water"),"to_amount"][0],
"m3-H2O/MWh-H2-LHV",
"Hydrogen electrolyser water input",
eff.loc[("electrolysis","all","water"),"source"][0]]
df.loc[("desalination_electricity",""),:] = ["f",
eff.loc[("seawater desalination","all","electricity"),"from_amount"][0]/eff.loc[("seawater desalination","all","electricity"),"to_amount"][0],
"MWh-el/m3-H2O",
"Seawater desalination electricity input",
eff.loc[("seawater desalination","all","electricity"),"source"][0]]
#hydrogen_submarine_pipeline_losses,,f,2.1,percent/1000km,Hydrogen submarine pipeline losses,
df.loc[("hydrogen_submarine_pipeline_losses",""),:] = ["f",
100*(1-eff.loc[("H2 (g) submarine pipeline","all","hydrogen (g) compressed submarine"),"efficiency"][0]),
"percent/1000km",
"Hydrogen submarine pipeline losses",
eff.loc[("H2 (g) submarine pipeline","all","hydrogen (g) compressed submarine"),"source"][0]]
df.loc[("hvdc_submarine_cable_losses",""),:] = ["f",
100*(1-eff.loc[("HVDC submarine","all","hvdc submarine"),"efficiency"][0]),
"percent/1000km",
"HVDC submarine cable losses",
eff.loc[("HVDC submarine","all","hvdc submarine"),"source"][0]]
df.loc[("methanolisation_efficiency",""),:] = ["f",
eff.loc[("methanolisation","all","hydrogen (g)"),"to_amount"][0]/eff.loc[("methanolisation","all","hydrogen (g)"),"from_amount"][0],
"MWh-MeOH-LHV/MWh-H2-LHV",
"Methanol synthesis efficiency wrt hydrogen",
eff.loc[("methanolisation","all","hydrogen (g)"),"source"][0]]
df.loc[("methanolisation_co2",""),:] = ["f",
eff.loc[("methanolisation","all","CO2 (g)"),"from_amount"][0]/eff.loc[("methanolisation","all","CO2 (g)"),"to_amount"][0],
"tCO2/MWh-MeOH-LHV",
"Methanol synthesis carbon dioxide input",
eff.loc[("methanolisation","all","CO2 (g)"),"source"][0]]
df.loc[("methanolisation_electricity",""),:] = ["f",
eff.loc[("methanolisation","all","electricity"),"from_amount"][0]/eff.loc[("methanolisation","all","electricity"),"to_amount"][0],
"MWhel/MWh-MeOH-LHV",
"Methanol synthesis electricity input",
eff.loc[("methanolisation","all","electricity"),"source"][0]]
df.loc[("ft_efficiency",""),:] = ["f",
eff.loc[("Fischer-Tropsch","all","hydrogen (g)"),"to_amount"][0]/eff.loc[("Fischer-Tropsch","all","hydrogen (g)"),"from_amount"][0],
"MWh-FT-LHV/MWh-H2-LHV",
"Fischer-Tropsch synthesis efficiency wrt hydrogen",
eff.loc[("Fischer-Tropsch","all","hydrogen (g)"),"source"][0]]
df.loc[("ft_co2",""),:] = ["f",
eff.loc[("Fischer-Tropsch","all","CO2 (g)"),"from_amount"][0]/eff.loc[("Fischer-Tropsch","all","CO2 (g)"),"to_amount"][0],
"tCO2/MWh-FT-LHV",
"Fischer-Tropsch synthesis carbon dioxide input",
eff.loc[("Fischer-Tropsch","all","CO2 (g)"),"source"][0]]
df.loc[("ft_electricity",""),:] = ["f",
eff.loc[("Fischer-Tropsch","all","electricity"),"from_amount"][0]/eff.loc[("Fischer-Tropsch","all","electricity"),"to_amount"][0],
"MWhel/MWh-FT-LHV",
"Fischer-Tropsch synthesis electricity input",
eff.loc[("Fischer-Tropsch","all","electricity"),"source"][0]]
df.loc[("methanation_efficiency",""),:] = ["f",
eff.loc[("methanation","all","hydrogen (g)"),"to_amount"][0]/eff.loc[("methanation","all","hydrogen (g)"),"from_amount"][0],
"MWh-CH4-LHV/MWh-H2-LHV",
"Methanation efficiency wrt hydrogen",
eff.loc[("methanation","all","hydrogen (g)"),"source"][0]]
df.loc[("methanation_co2",""),:] = ["f",
eff.loc[("methanation","all","CO2 (g)"),"from_amount"][0]/eff.loc[("methanation","all","CO2 (g)"),"to_amount"][0],
"tCO2/MWh-CH4-LHV",
"Methanation carbon dioxide input",
eff.loc[("methanation","all","CO2 (g)"),"source"][0]]
df.loc[("methane_liquefaction_electricity",""),:] = ["f",
eff.loc[("CH4 liquefaction","all","electricity"),"from_amount"][0]/eff.loc[("CH4 liquefaction","all","electricity"),"to_amount"][0]/config['mwh_per_t']['methane'],
"MWh-el/MWh-CH4-LHV",
"Methane liquefaction electricity input",
eff.loc[("CH4 liquefaction","all","electricity"),"source"][0]]
df.loc[("hydrogen_liquefaction_efficiency",""),:] = ["f",
eff.loc[("H2 liquefaction","all","hydrogen (g)"),"to_amount"][0]/eff.loc[("H2 liquefaction","all","hydrogen (g)"),"from_amount"][0],
"MWh-H2-liquid/MWh-H2-gas",
"Hydrogen liquefaction efficiency",
eff.loc[("H2 liquefaction","all","hydrogen (g)"),"source"][0]]
df.loc[("hydrogen_liquefaction_electricity",""),:] = ["f",
eff.loc[("H2 liquefaction","all","electricity"),"from_amount"][0]/eff.loc[("H2 liquefaction","all","electricity"),"to_amount"][0],
"MWh-el/MWh-H2-LHV",
"Hydrogen liquefaction electricity input",
eff.loc[("H2 liquefaction","all","electricity"),"source"][0]]
df.loc[("dac_electricity",""),:] = ["f",
td[year].loc[("direct air capture","electricity-input"),"value"],
td[year].loc[("direct air capture","electricity-input"),"unit"],
"Direct air capture electricity consumption",
td[year].loc[("direct air capture","electricity-input"),"source"]]
df.loc[("dac_heat",""),:] = ["f",
td[year].loc[("direct air capture","heat-input"),"value"],
td[year].loc[("direct air capture","heat-input"),"unit"],
"Direct air capture heat consumption",
td[year].loc[("direct air capture","heat-input"),"source"]]
df.loc[("air_separation_unit_efficiency",""),:] = ["f",
eff.loc[("air separation unit","all","electricity"),"to_amount"][0]/eff.loc[("air separation unit","all","electricity"),"from_amount"][0],
"tN2/MWhel",
"Air separation unit output",
eff.loc[("air separation unit","all","electricity"),"source"][0]]
df.loc[("haber_bosch_efficiency",""),:] = ["f",
eff.loc[("Haber-Bosch","all","hydrogen (g)"),"to_amount"][0]/eff.loc[("Haber-Bosch","all","hydrogen (g)"),"from_amount"][0],
"MWh-NH3-LHV/MWh-H2-LHV",
"Haber-Bosch ammonia synthesis hydrogen input",
eff.loc[("Haber-Bosch","all","hydrogen (g)"),"source"][0]]
df.loc[("haber_bosch_electricity",""),:] = ["f",
eff.loc[("Haber-Bosch","all","electricity"),"from_amount"][0]/eff.loc[("Haber-Bosch","all","electricity"),"to_amount"][0],
"MWhel/MWh-NH3-LHV",
"Haber-Bosch ammonia synthesis electricity input",
eff.loc[("Haber-Bosch","all","electricity"),"source"][0]]
df.loc[("haber_bosch_nitrogen",""),:] = ["f",
eff.loc[("Haber-Bosch","all","nitrogen (g)"),"from_amount"][0]/eff.loc[("Haber-Bosch","all","nitrogen (g)"),"to_amount"][0],
"tN2/MWh-NH3-LHV",
"Haber-Bosch ammonia synthesis nitrogen input",
eff.loc[("Haber-Bosch","all","nitrogen (g)"),"source"][0]]
df.loc[("hydrogen_compressor_electricity",""),:] = ["f",
eff.loc[("H2 storage compressor","all","electricity"),"from_amount"][0]/eff.loc[("H2 storage compressor","all","electricity"),"to_amount"][0],
"MWhel/MWh-H2-LHV",
"Hydrogen storage compressor electricity input",
eff.loc[("H2 storage compressor","all","electricity"),"source"][0]]
for name,td_name in [("methanol","MeOH"),("ammonia","NH3 (l)"),("methane","CH4 (l)"),("lh2","H2 (l)"),("ft","FT fuel")]:#,("lohc","LOHC")]
df.loc[(name + "_ship_discount",""),:] = ["f",5,"percent",name + " shipping discount rate",""]
fuel_df = shipping.loc[td_name + " transport ship"]
for attr,td_attr,full in [("loading_loss","(un-) loading losses","unloading/loading loss"),
("loading_time","(un-) loading time","unloading/loading time"),
("average_speed","average speed","average speed"),
("capacity_mwh","capacity","energy capacity"),
("energy_demand","energy demand","energy demand")]:
df.loc[(name + "_ship_" + attr,""),:] = ["f",
fuel_df.at[td_attr,"value"],
fuel_df.at[td_attr,"unit"],
name + " shipping " + full,
fuel_df.at[td_attr,"comment"]]
for attr,td_attr,full in [("fom","FOM","fixed operation and maintenance costs"),
("cost","investment","capital cost (overnight)"),
("lifetime","lifetime","lifetime"),
("capacity_t","capacity","mass capacity")]:
for year in years:
df.loc[(name + "_ship_" + attr,str(year)),:] = ["f",
td[year].loc[(td_name + " transport ship",td_attr),"value"],
td[year].loc[(td_name + " transport ship",td_attr),"unit"],
name + " shipping " + full,
td[year].loc[(td_name + " transport ship",td_attr),"source"]]
print(df)
cost_df = df.index[df.index.get_level_values(0).str.contains("cost") & (~df.index.get_level_values(0).str.contains("marginal_cost")) & (~df.index.get_level_values(0).str.contains("co2_cost"))]
inflation_factor = (1 + config["inflation"]/100)**(config["cost_year"] - config["cost_year_assumptions"])
print("inflation factor",inflation_factor)
df.loc[cost_df,"value"] = (inflation_factor*df.loc[cost_df,"value"].astype(float)).round(1)
df.to_csv("defaults.csv")