-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplan_baseline.py
285 lines (210 loc) · 8.64 KB
/
plan_baseline.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
# encoding: utf-8
#
# (c) Minh Ha-Duong 2017
# Creative Commons Attribution-ShareAlike 4.0 International
#
#
"""Define the baseline power plan.
Up to 2015-12-31, based on historical installed capacity listed in EVN 2016 report
From 2016 onwards, based on future capacity additions listed in PDP7A
not including coal plants listed as backup for renewables
Nuclear replaced by Coal
Renewable4 includes small hydro
Usage:
python3 plan_baseline.py summarize
python3 plan_baseline.py plot filename.[pdf|png|...]
"""
import sys
from init import pd, VERBOSE, show
from init import PLANT_TYPE, addcol_Renewable4
from data_past import CAPACITY_PAST, PRODUCTION_PAST, capacity_factor_past, capacity_2015_EVN
from data_PDP7A import (PDP7A_annex1,
capacities_PDP7A,
capacity_total_plan,
production_PDP7A,
capacity_factor_PDP7A)
from Plan import Plan
# %%
def fill_in(serie):
"""Return the investments needed to reach the capacity objectives.
Approximately because cast as integer
"""
capacity_2015 = CAPACITY_PAST.cumsum().loc[2015, serie.name]
a = (serie[2020] - capacity_2015) / 15
b = (serie[2025] - serie[2020]) / 15
c = (serie[2030] - serie[2025]) / 15
return pd.Series(name=serie.name,
data=[a, 2 * a, 3 * a, 4 * a, 5 * a,
b, 2 * b, 3 * b, 4 * b, 5 * b,
c, 2 * c, 3 * c, 4 * c, 5 * c],
index=range(2016, 2031),
dtype="int64")
# %% Capacity additions
# 2016 - 2030 capacity additions for Coal, Gas, Oil, BigHydro
additions = PDP7A_annex1.replace({"fuel": {"Nuclear": "Gas"}})
additions = additions.groupby(["year", "fuel"]).capacity_MW.sum()
additions = additions.unstack()
additions.drop("ND*", axis=1, inplace=True)
# 2016 - 2030 capacity additions for the four renewable technologies
additions["Solar"] = fill_in(capacities_PDP7A.Solar)
additions["Wind"] = fill_in(capacities_PDP7A.Wind)
additions["Biomass"] = fill_in(capacities_PDP7A.Biomass)
additions["SmallHydro"] = fill_in(capacities_PDP7A.SmallHydro)
additions["Import"] = fill_in(capacities_PDP7A.Import)
# 1974 - 2015 capacity additions and cleanup
additions = pd.concat([CAPACITY_PAST, additions])
# FIXME: PLANT_TYPE + ["PumpedStorage", "Import"] is technologies
additions = additions[PLANT_TYPE + ["PumpedStorage", "Import"]].fillna(0)
# 2031 - 2050 scenario definition
increment = {"Coal": 0, "Gas": 750, "Oil": 20, "BigHydro": 0,
"SmallHydro": 50, "Biomass": 50, "Wind": 900, "Solar": 1000,
"PumpedStorage": 50, "Import": 50, "CoalCCS": 0, "GasCCS": 0, "BioCCS": 0}
for y in range(2031, 2051):
additions.loc[y] = increment
# %% Old plant retirement program
plant_life = pd.Series({"Coal": 40, "Gas": 25, "Oil": 30,
"BigHydro": 100, "SmallHydro": 60, "Biomass": 25, "Wind": 20, "Solar": 25,
"CoalCCS": 40, "GasCCS": 25, "BioCCS": 25,
"PumpedStorage": 100, "Import": 100})
retirement = pd.DataFrame()
for tech in plant_life.index:
retirement[tech] = additions[tech].shift(plant_life[tech])
retirement.fillna(0, inplace=True)
# Fix to meet PDP7A objective more precisely
retirement.loc[2017, "BigHydro"] = 200
retirement.loc[2018, "BigHydro"] = 200
retirement.loc[2019, "BigHydro"] = 200
retirement.loc[2017, "Oil"] = 100
retirement.loc[2018, "Oil"] = 100
retirement.loc[2019, "Oil"] = 100
# Smooth the retirement program a bit, especially Gas 2025
retirement = retirement.rolling(window=2, center=False).mean()
retirement.loc[1974] = 0
# %%
# FIXME: complexity too high
# define and use function interpolating in place between two given years.
#
def extend(serie, endpoint, newname, past=capacity_factor_past, future=capacity_factor_PDP7A):
"""Extend a series by interpolating between 2020, 2025, 2030 and a 2050 endpoint."""
r = past[serie]
a = (r.loc[2013] + r.loc[2014] + r.loc[2015]) / 15
b = future.loc[2020, serie] / 5
c = future.loc[2025, serie] / 5
d = future.loc[2030, serie] / 5
s = pd.Series(name=newname,
data=[4 * a + b, 3 * a + 2 * b, 2 * a + 3 * b, a + 4 * b, 5 * b,
4 * b + c, 3 * b + 2 * c, 2 * b + 3 * c, b + 4 * c, 5 * c,
4 * c + d, 3 * c + 2 * d, 2 * c + 3 * d, c + 4 * d, 5 * d],
index=range(2016, 2031))
r = r.append(s)
d *= 5
e = endpoint
s = pd.Series(name=newname,
data=[d + (e - d) * (i + 1) / 20 for i in range(20)],
index=range(2031, 2051))
return r.append(s)
# %% Electricity production
CAPACITY_FACTOR = pd.DataFrame()
CAPACITY_FACTOR["Coal"] = extend("Coal", 0.6, "Coal")
CAPACITY_FACTOR["Gas"] = extend("Gas", 0.6, "Gas")
CAPACITY_FACTOR["Oil"] = 0.25
CAPACITY_FACTOR["BigHydro"] = extend("BigHydro", 0.4, "BigHydro")
CAPACITY_FACTOR["SmallHydro"] = extend("SmallHydro", 0.6, "SmallHydro")
CAPACITY_FACTOR["Biomass"] = extend("Renewable", 0.3, "Biomass")
CAPACITY_FACTOR["Wind"] = extend("Renewable", 0.3, "Wind")
CAPACITY_FACTOR["Solar"] = extend("Renewable", 0.23, "Solar")
CAPACITY_FACTOR["CoalCCS"] = CAPACITY_FACTOR["Coal"]
CAPACITY_FACTOR["GasCCS"] = CAPACITY_FACTOR["Gas"]
CAPACITY_FACTOR["BioCCS"] = CAPACITY_FACTOR["Biomass"]
CAPACITY_FACTOR = CAPACITY_FACTOR.where(CAPACITY_FACTOR < 1)
net_import = extend("Import", 7000, "Import", PRODUCTION_PAST, production_PDP7A)
# %% Main statement
baseline = Plan(additions, retirement, CAPACITY_FACTOR, net_import)
baseline.__doc__ = "Baseline - PDP7A extended"
if __name__ == '__main__':
if (len(sys.argv) == 2) and (sys.argv[1] == "summarize"):
baseline.summarize()
if (len(sys.argv) == 3) and (sys.argv[1] == "plot"):
baseline.plot_plan(sys.argv[2])
# %% Validation: compares to PDP7A
show("""
*****************************************************
*** Comparing our baseline with PDP7 ***
*****************************************************
""")
compared = ["Coal", "Gas", "BigHydro", "Renewable4", "Nuclear"]
tocompare = baseline.capacities.loc[[2020, 2025, 2030]]
tocompare["Gas"] = tocompare.Gas + tocompare.Oil
tocompare["Nuclear"] = 0
addcol_Renewable4(tocompare)
tocompare = tocompare[compared]
relerror = (tocompare - capacities_PDP7A) / capacities_PDP7A
relerror = relerror[compared]
show("PDP7A")
show(capacities_PDP7A[compared])
show()
show("Baseline scenario, Gas includes Oil")
show(tocompare)
show()
show("Relative error")
show(relerror)
show("Note: Gas 2030 is larger in baseline because we replace nuclear with gas")
# %% Compares PDP7A
cap_2015_implicit = capacities_PDP7A.loc[2030] - capacity_total_plan
cap_2015_implicit.dropna(inplace=True)
comparison = pd.DataFrame([capacity_2015_EVN, cap_2015_implicit],
index=["Total from EVN report", "Implicit in PDP7A decision"])
capacity_closed = pd.Series(comparison.iloc[0] - comparison.iloc[1], name="Diff ?Closed capacity?")
comparison = comparison.append(capacity_closed)
capacity_old = pd.Series(CAPACITY_PAST.cumsum().loc[1980], name="Installed before 1980")
comparison = comparison.append(capacity_old)
show("Coherence of 2015 Generation capacity numbers")
show(comparison[PLANT_TYPE])
show("""
Some coal, gas, oil and hydro capacities listed in the EVN report historical table are
not accounted for in the PDP7A current capacity total
The order of magnitude corresponds to capacities installed before 1985,
which in all probability are already closed or will be before 2030.
Gas capacity in EVN report includes the Tu Duc and Can Tho oil-fired gas turbines (264 MW)
""")
if VERBOSE:
cf = pd.concat([capacity_factor_past, capacity_factor_PDP7A])
cf = cf.where(cf < 1)
cf = cf[["Coal", "Gas", "Hydro", "Renewable"]]
ax = cf.plot(ylim=[0, 1], xlim=[1995, 2030],
title="Power generation capacity factors by fuel type")
ax.axvline(2015, color="k")
#b = PRODUCTION_PAST[PLANT_TYPE].astype("int64")
#
#show("Past - Electricity production (GWh)")
#show(b)
#show()
#
#
#relerr = ((production_baseline - b) / b).loc[1990:2015]
#show("Relative error")
#show(relerr)
# %% Fuel use
#
#MtCoal_per_GWh = fuel_use_PDP7A.Coal / production_PDP7A.Coal
#
#show(MtCoal_per_GWh)
#
#a = MtCoal_per_GWh[2020]
#b = MtCoal_per_GWh[2025]
#da = (b - a) / 5
#c = MtCoal_per_GWh[2030]
#db = (c - b) / 5
#s = pd.Series(name="Coal",
# data=np.concatenate([np.arange(a - 10 * da, b, da),
# np.arange(b, c + 21 * db, db)]),
# index=range(2010, 2051))
#
#show(s)
#
#coal_use_baseline = s * production_baseline.Coal.loc[2010:]
#
#show(fuel_use_PDP7A.Coal)
#show(coal_use_baseline)
#