-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.py
More file actions
153 lines (114 loc) · 4.16 KB
/
init.py
File metadata and controls
153 lines (114 loc) · 4.16 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
# encoding: utf-8
# CCS in Vietnam scenarios
#
# Model framework common to all files: time domain, technology domain, units
#
# (c) Minh Ha-Duong, 2017
# minh.haduong@gmail.com
# Creative Commons Attribution-ShareAlike 4.0 International
# Modified by Alice Duval, 2018
#Energy converter used is: www.iea.org/statistics/resources/unitconverter/
#
"""Common functions, units.
To clarify column names.
1/ Some include Imports in electricity "Production". We don't.
Imports are part of "Domestic Supply". We use these column names:
Supply = Production + Import
2/ We define Import as net of Exports
3/ Another ambiguity is whether SmallHydro is included in "Hydro" or "Renewable"
Here we do the former and use these column names:
Hydro = BigHydro + SmallHydro
BigHydro = LargeHydro + InterHydro
Renewable = Wind + Solar + Biomass
Renewable4 = Renewable + Small hydro
4/ We do NOT include PumpedStorage in Hydro capacities or (double accounting) production
5/ In VN capacity stats, generation from fuel oil and from diesel is not clearly accounted for.
6/ Adding up fossil fuel generation capacities with renewable capacities is meaningless
because the capacity factors are not comparable, neither are the investment costs
"""
from functools import lru_cache
# import time
import pandas as pd
import numpy as np
#This is overkill. Would be better to find the exact offending line and reenable warnings
#Disable the spurious message:
# FutureWarning: The pandas.core.datetools module is deprecated
#https://stackoverflow.com/questions/14463277/how-to-disable-python-warnings
#https://github.com/statsmodels/statsmodels/issues/3814
#Should be fixed in statsmodels version 0.9
#
np.warnings.filterwarnings("ignore")
pd.set_option('display.max_rows', 100)
pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 1000)
VERBOSE = False
show = print if VERBOSE else lambda *a, **k: None
# %% Rows
START_YEAR = 2016
END_YEAR = 2050
YEARS = range(START_YEAR, END_YEAR + 1)
N_YEARS = len(YEARS)
@lru_cache(maxsize=32)
def discountor(discount_rate):
"""Return a vector V such that the scalar product A.V is the present value of series A."""
return pd.Series(data=np.logspace(0, N_YEARS - 1, N_YEARS, base=1 / (1 + discount_rate)),
index=YEARS)
def present_value(series, discount_rate):
"""Intertemporal total present value. Applies to a series or a dataframe's columns."""
return series.mul(discountor(discount_rate), axis=0).sum()
def discount(value, year, discount_rate):
"""Return the present value of a future cash flow."""
return value * discountor(discount_rate).loc[year]
# %% Columns
# Nuclear is presently out of the power planning discussion in Vietnam
# CCS also, but that's the point of our study.
PLANT_TYPE = ["Coal", "Gas", "Oil",
"BigHydro", "SmallHydro", "Biomass", "Wind", "Solar",
"CoalCCS", "GasCCS", "BioCCS"]
SOURCES = PLANT_TYPE + ["Import"]
technologies = SOURCES + ["PumpedStorage"]
def addcol_Renewable(container):
"""Define Renewable excluding hydro. The container can be a dict, Series, DataFrame."""
container["Renewable"] = container["Biomass"] + container["Wind"] + container["Solar"]
def addcol_Renewable4(container):
"""Define Renewable4 including hydro. The container can be a dict, Series, DataFrame."""
container["Renewable4"] = (container["Biomass"] + container["Wind"] + container["Solar"]
+ container["SmallHydro"])
# %% Units
W = 1
kW = 1000
MW = 10**6
GW = 10**9
kWh = 1000
MWh = 10**6
GWh = 10**9
TWh = 10**12
Btu = 1
MBtu = 10**6
TBtu = 10**12
Mkal = 3969
TOE = 39.7 * 10**6
USD = 1
MUSD = 10**6
GUSD = 10**9
g = 10**(-3)
kg = 1
t = 1000
kt = 10**6
Mt = 10**9
Gt = 10**12
MM3 = 10**6
#%% Calorific power
CALORIFIC_POWER = {}
CALORIFIC_POWER["Coal_local"] = 5500 * Mkal / t
CALORIFIC_POWER["Coal_international"] = 6700 * Mkal / t
CALORIFIC_POWER["Gas_local"] = 35700
#
# def timefunc(f):
# def f_timer(*args, **kwargs):
# start = time.time()
# result = f(*args, **kwargs)
# end = time.time()
# print(f.__name__, 'took', end - start, 'time')
# return result
# return f_timer