-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_defaults.py
170 lines (127 loc) · 9.6 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
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])
for name,td_name,full_name in [("wind","onwind","Onshore wind turbine"),
("solar","solar-utility","Utility-scale solar PV"),
("hydrogen_electrolyser","electrolysis","Hydrogen electrolyser"),
("desalination","seawater desalination","Seawater desalination"),
("hydrogen_turbine","CCGT","Hydrogen combined cycle turbine"),
("hydrogen_storage_tank","hydrogen storage tank type 1","Compressed hydrogen storage tank"),
("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"),
("reformer","SMR CC","Steam methanol reformer with carbon capture"),
("methanolisation","methanolisation","Methanol synthesis"),
("hydrogen_liquefaction","H2 liquefaction","Hydrogen liquefaction"),
("liquid_hydrogen_storage","H2 (l) storage tank","Liquid hydrogen storage tank"),
]:
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"]]
for year in years:
df.loc[("reformer_capture_rate",str(year)),:] = ["f",
td[year].loc[("SMR CC","capture_rate"),"value"],
td[year].loc[("SMR CC","capture_rate"),"unit"],
"reformer capture rate",
td[year].loc[("SMR CC","capture_rate"),"source"]]
df.loc[("dac_electricity",str(year)),:] = ["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",str(year)),:] = ["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"]]
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"),
("reformer_efficiency","SMR CC","Steam methane reformer with carbon capture"),
("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]]
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]]
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]]
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(2)
df.to_csv("defaults.csv")