-
Notifications
You must be signed in to change notification settings - Fork 0
/
DecarbonizationFunctions.py
514 lines (450 loc) · 18.4 KB
/
DecarbonizationFunctions.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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
import pandas as pd
import functions
from EnergyFlows import Country_List
def calculate_community_battery_size(
demand,
total_rooftop_PV_capacity_MW,
technical_pot,
rooftop_size,
res_battery_size,
total_storage_days=5,
):
number_of_homes = total_rooftop_PV_capacity_MW * 1000 / rooftop_size
total_res_storage_capacity_GWh = number_of_homes * res_battery_size / 1000000
average_daily_demand = demand / 365 # GWH/day
if demand <= technical_pot:
total_storage_capacity_GWh = average_daily_demand * total_storage_days
elif demand > technical_pot:
total_storage_capacity_GWh = (average_daily_demand * total_storage_days) * (
technical_pot / demand
)
community_battery = max(
total_storage_capacity_GWh - total_res_storage_capacity_GWh, 0
)
return community_battery, total_res_storage_capacity_GWh
def calculate_demand(country, demand_scenario):
if demand_scenario == "Decarbonization":
demand = functions.fetch_single_country_demand(Country=country, Year=2019)[0]
elif demand_scenario == "Electrification":
demand = functions.fetch_single_country_demand(Country=country, Year=2019)[1]
elif demand_scenario == "Net_zero":
demand = functions.fetch_single_country_demand(Country=country, Year=2019)[2]
return demand
def calculate_renewable_technical_potential(
country, available_land, avaialble_coastline, avaialble_buildings=0.3, PV_size=2.5
):
technical_potential_df = functions.calculate_PV_Wind_potential(
available_land=available_land, available_coastline=avaialble_coastline
)
PV_technical_potential = technical_potential_df[
technical_potential_df["Country"] == country
]["PV_technical_GWh"].values[0]
Wind_technical_potential = technical_potential_df[
technical_potential_df["Country"] == country
]["Wind_technical_GWh"].values[0]
rooftop_df = functions.calculate_rooftop_PV_potential(
available_buildings=avaialble_buildings, PV_size=PV_size
)
rooftop_potential = rooftop_df[rooftop_df["Country"] == country][
"Generation_GWh"
].values[0]
total = PV_technical_potential + Wind_technical_potential + rooftop_potential
return {
"PV_tech_GWh": PV_technical_potential,
"Wind_tech_GWh": Wind_technical_potential,
"Rooftop_GWh": rooftop_potential,
"Total": total,
}
def calculate_capacity_of_each_technology(
country, dic_potential, demand, demand_scenario, cost_dic
):
rooftop_PV_GWh = min(dic_potential["Rooftop_GWh"], demand)
rooftop_PV_GWh = max(0, rooftop_PV_GWh)
large_PV_GWh = min(dic_potential["PV_tech_GWh"], demand - rooftop_PV_GWh)
large_PV_GWh = max(0, large_PV_GWh)
wind_GWh = min(
dic_potential["Wind_tech_GWh"], demand - rooftop_PV_GWh - large_PV_GWh
)
wind_GWh = max(0, wind_GWh)
diesel_GWh = calculate_demand(country, demand_scenario) - calculate_demand(
country, "Decarbonization"
)
df_potentials = pd.read_excel("Data/Potentials.xlsx")
PV_pot = df_potentials.iloc[0, 2:] # GWh/MW/year
Wind_pot = df_potentials.iloc[2, 2:] # GWh/MW/year
PV_pot = PV_pot[country]
Wind_pot = Wind_pot[country]
rooftop_MW = rooftop_PV_GWh / PV_pot # MW
large_PV_MW = large_PV_GWh / PV_pot # MW
wind_MW = wind_GWh / Wind_pot
total_GWh = wind_GWh + large_PV_GWh + rooftop_PV_GWh
community_battery_GWh, res_battery_GWh = calculate_community_battery_size(
demand=demand,
total_rooftop_PV_capacity_MW=rooftop_MW,
technical_pot=total_GWh,
total_storage_days=cost_dic["storage_days"],
rooftop_size=cost_dic["rooftop_size"],
res_battery_size=cost_dic["res_battery_size"],
)
return {
"Rooftop_MW": round(rooftop_MW, 2),
"Large_PV_MW": round(large_PV_MW,2),
"Wind_MW": round(wind_MW,2),
"residential_battery_GWh": res_battery_GWh,
"total_GWh": total_GWh,
"Community_battery_GWh": community_battery_GWh,
"diesel_GWh": diesel_GWh,
}
def create_yearly_df(
country,
decarb_year,
capacity_dic,
cost_dic,
diesel_price,
):
from datetime import datetime
now = datetime.now().year
number_of_years = decarb_year - 2022
year_list = []
installation_df = pd.DataFrame()
for i in range(0, 31):
now += 1
year_list.append(now)
installation_df["Year"] = year_list
installation_df["rooftop_MW"] = capacity_dic["Rooftop_MW"] / number_of_years
installation_df["resid_battery_GWh"] = (
capacity_dic["residential_battery_GWh"] / number_of_years
)
installation_df["PV_MW"] = capacity_dic["Large_PV_MW"] / number_of_years
installation_df["wind_MW"] = capacity_dic["Wind_MW"] / number_of_years
installation_df["Community_battery_GWh"] = (
capacity_dic["Community_battery_GWh"] / number_of_years
)
installation_df["Diesel_GWh"] = capacity_dic["diesel_GWh"] / number_of_years
installation_df["Diesel_MW"] = (installation_df["Diesel_GWh"] / (0.7 * 8760)) * 1000
installation_df.loc[number_of_years:, "rooftop_MW"] = 0
installation_df.loc[number_of_years:, "resid_battery_GWh"] = 0
installation_df.loc[number_of_years:, "PV_MW"] = 0
installation_df.loc[number_of_years:, "wind_MW"] = 0
installation_df.loc[number_of_years:, "Community_battery_GWh"] = 0
installation_df.loc[number_of_years:, "Diesel_MW"] = 0
# costs are $/W - 1000000/MW
# The output is #$
installation_df["installation_Cost"] = (
installation_df["rooftop_MW"] * cost_dic["rooftop"]
+ installation_df["resid_battery_GWh"] * cost_dic["resid_battery"] * 1000
+ installation_df["Community_battery_GWh"] * 1000 * cost_dic["comm_battery"]
+ installation_df["PV_MW"] * cost_dic["large_PV"]
+ installation_df["wind_MW"] * cost_dic["wind"]
- installation_df["Diesel_MW"] * cost_dic["diesel_cap"]
) * 1000000 # Convert to $/MW #in the cost dic, are costs are $/W
installation_df["installation_Cost_original"] = installation_df["installation_Cost"]
installation_df["avoided_demand_GWh"] = capacity_dic["total_GWh"] / number_of_years
installation_df.loc[number_of_years:, "avoided_demand_GWh"] = 0
installation_df["avoided_emissions_tonne"] = (
installation_df["avoided_demand_GWh"] * cost_dic["emissiont/GWh_diesel"]
)
installation_df["cumulative_avoided_emissions_tonne"] = installation_df[
"avoided_emissions_tonne"
].cumsum(axis=0)
installation_df["emission_cost_$"] = (
installation_df["cumulative_avoided_emissions_tonne"] * cost_dic["carbon_price"]
)
diesel_generation = 2.5 # kWh/Liter
installation_df["avoided_diesel_liter"] = installation_df["avoided_demand_GWh"] / (
diesel_generation / 1000000
)
installation_df["cumulative_avoided_diesel_liter"] = installation_df[
"avoided_diesel_liter"
].cumsum(axis=0)
installation_df["avoided_diesel_savings"] = (
installation_df["cumulative_avoided_diesel_liter"] * diesel_price
)
if country == "New Caledonia":
# coal price is 400 USD/Tonne
# 47% demand is met by diesel, and 53% by coal
# 0.00814 GWh energy in one tonne coal.
df = pd.read_csv("Data/Sankey/csv/{}/{}.csv".format(2019, country))
to_power_stations = df[df[" (to)"] == "PowerStations"][" (weight)"].values[0]
coal = df[
(df[" (to)"] == "PowerStations") & (df[" (from)"] == "Coal: Supplied")
][" (weight)"].values[0]
oil = df[(df[" (to)"] == "PowerStations") & (df[" (from)"] == "Oil: Supplied")][
" (weight)"
].values[0]
installation_df["avoided_diesel_liter"] = installation_df[
"avoided_diesel_liter"
] * (oil / to_power_stations)
installation_df["avoided_emissions_tonne"] = installation_df[
"avoided_demand_GWh"
] * (
(oil / to_power_stations) * cost_dic["emissiont/GWh_diesel"]
+ (coal / to_power_stations) * cost_dic["emissiont/GWh_blackCoal"]
)
installation_df["cumulative_avoided_emissions_tonne"] = installation_df[
"avoided_emissions_tonne"
].cumsum(axis=0)
installation_df["emission_cost_$"] = (
installation_df["cumulative_avoided_emissions_tonne"]
* cost_dic["carbon_price"]
)
installation_df["avoided_coal_tonne"] = (
installation_df["avoided_demand_GWh"] * (coal / to_power_stations)
) / (0.00814 * 0.35)
installation_df["cumulative_avoided_diesel_liter"] = installation_df[
"avoided_diesel_liter"
].cumsum(axis=0)
installation_df["cumulative_avoided_coal_tonne"] = installation_df[
"avoided_coal_tonne"
].cumsum(axis=0)
installation_df["avoided_diesel_savings"] = (
installation_df["cumulative_avoided_diesel_liter"] * diesel_price
)
installation_df["avoided_coal_savings"] = (
installation_df["cumulative_avoided_coal_tonne"] * cost_dic["coal"]
)
installation_df["avoided_diesel_savings"] = (
installation_df["avoided_diesel_savings"]
+ installation_df["avoided_coal_savings"]
)
if country == "PNG":
df = pd.read_csv("Data/Sankey/csv/{}/{}.csv".format(2019, country))
to_power_stations = df[df[" (to)"] == "PowerStations"][" (weight)"].values[0]
oil = df[(df[" (to)"] == "PowerStations") & (df[" (from)"] == "Oil: Supplied")][
" (weight)"
].values[0]
natural_gas = df[
(df[" (to)"] == "PowerStations")
& (df[" (from)"] == "Natural Gas: Supplied")
][" (weight)"].values[0]
perc_oil = oil / to_power_stations
perc_gas = natural_gas / to_power_stations
installation_df["avoided_diesel_liter"] = (
(perc_oil + perc_gas)
* installation_df["avoided_demand_GWh"]
/ (diesel_generation / 1000000)
)
# site for natural gass generation
# https: // www.eia.gov / tools / faqs / faq.php?id = 667 & t = 8
# Electricity generation from natural gas# 0.14 kWh/cf3 = 4.94 kWh/m3 = 4.94e-6 GWh/m3
# NAtural gas thermal energy kWh to m3: 10kWh/m3
# Natural gas price:
# https: // www.globalpetrolprices.com / Papua - New - Guinea / natural_gas_prices /
# installation_df["avoided_gas_m3"] = (
# perc_gas * (installation_df["avoided_demand_GWh"]) * 1000000 / 4.94
# )
installation_df["cumulative_avoided_diesel_liter"] = installation_df[
"avoided_diesel_liter"
].cumsum(axis=0)
# installation_df["cumulative_avoided_gas_m3"] = installation_df[
# "avoided_gas_m3"
# ].cumsum(axis=0)
#
installation_df["avoided_emissions_tonne"] = installation_df[
"avoided_demand_GWh"
] * ((perc_oil + perc_gas) * cost_dic["emissiont/GWh_diesel"])
installation_df["cumulative_avoided_emissions_tonne"] = installation_df[
"avoided_emissions_tonne"
].cumsum(axis=0)
installation_df["emission_cost_$"] = (
installation_df["cumulative_avoided_emissions_tonne"]
* cost_dic["carbon_price"]
)
installation_df["avoided_diesel_savings"] = (
installation_df["cumulative_avoided_diesel_liter"] * diesel_price
)
#
# installation_df["avoided_gas_savings"] = (
# installation_df["cumulative_avoided_gas_m3"] * cost_dic["gas$/m3"]
# )
installation_df["avoided_diesel_savings"] = (
installation_df["avoided_diesel_savings"] + installation_df["emission_cost_$"]
)
installation_df["Cumulative_avoided_cost"] = installation_df[
"avoided_diesel_savings"
].cumsum(axis=0)
inflation_rate = cost_dic["inflation_rate"] / 100
discount_rate = cost_dic["discount_rate"] / 100
for i, row in installation_df.iterrows():
installation_df.at[i, "Cumulative_avoided_cost"] = (
installation_df.at[i, "Cumulative_avoided_cost"]
* ((1 + inflation_rate) / (1 + discount_rate)) ** i
)
installation_df.at[i, "installation_Cost"] = (
installation_df.at[i, "installation_Cost"]
* ((1 + inflation_rate) / (1 + discount_rate)) ** i
)
installation_df["Annual_Net_saving"] = (
installation_df["Cumulative_avoided_cost"]
- installation_df["installation_Cost"]
) # $MM
installation_df["Cumulative_net_saving"] = installation_df[
"Annual_Net_saving"
].cumsum(axis=0)
return installation_df
def calculate_diesel_price(country,cost_dic):
diesel_df = pd.read_csv("Data/Diesel.csv")
if country in diesel_df["Country"].to_list():
diesel_price = diesel_df[diesel_df["Country"] == country][
"Tax included"
].values[0]
else:
diesel_price = diesel_df["Tax included"].mean()
diesel_price = diesel_price # 20c less than retails price
diesel_price = diesel_price / 100 # convert to $ from cents
return diesel_price
def run_decarbonization_scenario(
cost_scenario,
country_list,
demand_scenario="Decarbonization",
available_land=0.02,
avaialble_coastline=0.1,
avaialble_buildings=0.3,
PV_size=2.5,
decarb_year=2030,
input_dicts=None,
):
df_GDP = pd.read_csv("Data/Economic Indicators.csv")
costs = {
"optimistic": {
"diesel_cap": 3,
"rooftop": 2.5,
"resid_battery": 2.5,
"comm_battery": 1.5,
"large_PV": 2.5,
"wind": 3,
"coal": 400,
"discount_rate": 6,
"inflation_rate": 3,
"diesel_dif": 0,
"storage_days": 4,
"gas$/m3": "Nan",
"emissiont/GWh_diesel": 1100, # AEMO:0.7-1.5
"emissiont/GWh_blackCoal": 900, # AEMO:0.7-1.5
"emissiont/GWh_brownCoal": 1200, # AEMO:1.1-1.3
"carbon_price": 0, # $/tonne
"rooftop_size": 2.5,
"res_battery_size": 5
}, # $/W
"pessimistic": {
"diesel_cap": 2,
"rooftop": 4.5,
"resid_battery": 4,
"comm_battery": 3,
"large_PV": 4.5,
"wind": 6,
"coal": 400,
"discount_rate": 6,
"inflation_rate": 3,
"diesel_dif": 20,
"storage_days": 5,
"gas$/m3": "Nan",
"emissiont/GWh_diesel": 1100, # AEMO:0.7-1.5
"emissiont/GWh_blackCoal": 1000, # AEMO:0.7-1.5
"emissiont/GWh_brownCoal": 1200, # AEMO:1.1-1.3
"carbon_price": 0, # $/tonne
"rooftop_size": 2.5,
"res_battery_size": 5
},
}
all_countries_result = pd.DataFrame()
all_countries_result["Technology"] = [
"Rooftop_MW",
"Large_PV_MW",
"Wind_MW",
"resid_battery_GWh",
"Community_battery_GWh",
"total_GWh",
"Payback period (years)",
"installation_cost ($)",
"GDP ($)",
"GDP/installation_cost",
"Total_storage_GWh",
]
if input_dicts is None:
cost_dic = costs[
cost_scenario
] # Here I should create the cost dic after entering in the GUI
else:
cost_dic = input_dicts
for country in country_list:
GDP = df_GDP[df_GDP["Country"] == country]["GDP(million$)2019"].values[0]
if input_dicts is None:
diesel_price = calculate_diesel_price(country=country, cost_dic=cost_dic)
else:
diesel_price = cost_dic["diesel_price"]
pot = calculate_renewable_technical_potential(
country,
available_land=available_land,
avaialble_coastline=avaialble_coastline,
avaialble_buildings=avaialble_buildings,
PV_size=PV_size,
)
demand = calculate_demand(country, demand_scenario)
capacity_dic = calculate_capacity_of_each_technology(
country, pot, demand, demand_scenario, cost_dic
)
final_df = create_yearly_df(
country=country,
decarb_year=decarb_year,
capacity_dic=capacity_dic,
cost_dic=cost_dic,
diesel_price=diesel_price,
)
if input_dicts is None:
final_df.to_csv(
"Results/{}/Simulation_result_{}.csv".format(demand_scenario, country)
)
total_cost = final_df["installation_Cost_original"].sum()
try:
payback_period = final_df[
final_df.Cumulative_net_saving < 0
].index.values.max()
except:
payback_period = 0
gdp_to_cost = int(100 * GDP / (total_cost / 1000000))
all_countries_result[country] = [
round(capacity_dic["Rooftop_MW"],2),
round(capacity_dic["Large_PV_MW"],2),
round(capacity_dic["Wind_MW"],1),
round(capacity_dic["residential_battery_GWh"],5),
round(capacity_dic["Community_battery_GWh"],5),
capacity_dic["total_GWh"],
int(payback_period),
total_cost,
GDP,
gdp_to_cost,
capacity_dic["residential_battery_GWh"]
+ capacity_dic["Community_battery_GWh"],
]
all_countries_result.reset_index(drop=True, inplace=True)
if input_dicts is None:
all_countries_result.to_excel(
"Results/{}/{}_simulation_result_{}_wind_{}_PV_{}_carbon_{}.xlsx".format(
demand_scenario,
cost_scenario,
demand_scenario,
avaialble_coastline,
available_land,
cost_dic["carbon_price"],
)
)
if input_dicts is None:
return final_df
else:
return final_df, all_countries_result
if __name__ == "__main__":
for cost_scenario in ["optimistic", "pessimistic"]:
for demand_sceanrio in ["Decarbonization", "Electrification", "Net_zero"]:
run_decarbonization_scenario(
cost_scenario=cost_scenario,
country_list=Country_List,
demand_scenario=demand_sceanrio,
available_land=0.02,
avaialble_coastline=0.1,
avaialble_buildings=0.3,
PV_size=2.5,
decarb_year=2040,
input_dicts=None
)
# check community battery