-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreportEmissions.R
212 lines (144 loc) · 7.62 KB
/
reportEmissions.R
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
reportEmissions <- function(regs) {
iCo2EmiFac <- readGDX('./blabla.gdx', "iCo2EmiFac")[regs, , ]
VConsFuel <- readGDX('./blabla.gdx', "VConsFuel", field = 'l')[regs, , ]
VInpTransfTherm <- readGDX('./blabla.gdx', "VInpTransfTherm", field = 'l')[regs, , ]
VTransfInputDHPlants <- readGDX('./blabla.gdx', "VTransfInputDHPlants", field = 'l')[regs, , ]
VConsFiEneSec <- readGDX('./blabla.gdx', "VConsFiEneSec", field = 'l')[regs, , ]
VDemFinEneTranspPerFuel <- readGDX('./blabla.gdx', "VDemFinEneTranspPerFuel", field = 'l')[regs, , ]
VProdElec <- readGDX('./blabla.gdx', "VProdElec", field = 'l')[regs, , ]
iPlantEffByType <- readGDX('./blabla.gdx', "iPlantEffByType")[regs, , ]
iCO2CaptRate <- readGDX('./blabla.gdx', "iCO2CaptRate")[regs, , ]
# Link between Model Subsectors and Fuels
sets4 <- readGDX('./blabla.gdx', "SECTTECH")
EFtoEFS <- readGDX('./blabla.gdx', "EFtoEFS")
IND <- readGDX('./blabla.gdx', "INDDOM")
IND <- as.data.frame(IND)
map_INDDOM <- sets4 %>% filter(SBS %in% IND[,1])
map_INDDOM <- filter(map_INDDOM, EF != "")
qINDDOM <- left_join(map_INDDOM, EFtoEFS, by = "EF")
qINDDOM <- select((qINDDOM), -c(EF))
qINDDOM <- unique(qINDDOM)
names(qINDDOM) <- sub("EFS", "SECTTECH", names(qINDDOM))
qINDDOM <- paste0(qINDDOM[["SBS"]], ".", qINDDOM[["SECTTECH"]])
INDDOM <- as.data.frame(qINDDOM)
PGEF <- readGDX('./blabla.gdx', "PGEF")
PGEF <- as.data.frame(PGEF)
# final consumption
sum1 <- iCo2EmiFac[,,INDDOM[, 1]] * VConsFuel[,,INDDOM[, 1]]
sum1 <- dimSums(sum1, 3, na.rm = TRUE)
# input to power generation sector
sum2 <- VInpTransfTherm[,,PGEF[,1]]*iCo2EmiFac[,,"PG"][,,PGEF[,1]]
sum2 <- dimSums(sum2, 3, na.rm = TRUE)
# input to district heating plants
sum3 <- VTransfInputDHPlants * iCo2EmiFac[,,"PG"][,,getItems(VTransfInputDHPlants,3)]
sum3 <- dimSums(sum3, 3, na.rm = TRUE)
# consumption of energy branch
sum4 <- VConsFiEneSec * iCo2EmiFac[,,"PG"][,,getItems(VConsFiEneSec,3)]
sum4 <- dimSums(sum4, 3, na.rm = TRUE)
TRANSE <- readGDX('./blabla.gdx', "TRANSE")
TRANSE <- as.data.frame(TRANSE)
map_TRANSECTOR <- sets4 %>% filter(SBS %in% TRANSE[,1])
map_TRANSECTOR <- paste0(map_TRANSECTOR[["SBS"]], ".", map_TRANSECTOR[["EF"]])
map_TRANSECTOR <- as.data.frame(map_TRANSECTOR)
sum5 <- VDemFinEneTranspPerFuel[,,map_TRANSECTOR[, 1]] * iCo2EmiFac[,,map_TRANSECTOR[, 1]]
# transport
sum5 <- dimSums(sum5, 3, na.rm = TRUE)
PGALLtoEF <- readGDX('./blabla.gdx', "PGALLtoEF")
PGALLtoEF <- as.data.frame(PGALLtoEF)
names(PGALLtoEF) <- c("PGALL", "EF")
CCS <- readGDX('./blabla.gdx', "CCS")
CCS <- as.data.frame(CCS)
CCS <- PGALLtoEF[PGALLtoEF$PGALL %in% CCS$CCS, ]
var_16 <- VProdElec[,,CCS[,1]] * 0.086 / iPlantEffByType[,,CCS[,1]] * iCo2EmiFac[,,"PG"][,,CCS[,2]] * iCO2CaptRate[,,CCS[,1]]
# CO2 captured by CCS plants in power generation
sum6 <- dimSums(var_16,dim=3, na.rm = TRUE)
SECTTECH2 <- sets4 %>% filter(SBS %in% c("BU"))
SECTTECH2 <- paste0(SECTTECH2[["SBS"]], ".", SECTTECH2[["EF"]])
SECTTECH2 <- as.data.frame(SECTTECH2)
# Bunkers
sum7 <- iCo2EmiFac[,,SECTTECH2[,1]] * VConsFuel[,,SECTTECH2[,1]]
sum7 <- dimSums(sum7,dim=3, na.rm = TRUE)
total_CO2 <- sum1 + sum2 + sum3 + sum4 + sum5 - sum6 + sum7
getItems(total_CO2, 3) <- "Emissions|CO2"
# write data in mif file
write.report(total_CO2[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Extra Emissions
# Emissions|CO2|Energy|Demand|Industry
INDSE <- readGDX('./blabla.gdx', "INDSE")
INDSE <- as.data.frame(INDSE)
map_INDSE <- sets4 %>% filter(SBS %in% INDSE[,1])
map_INDSE <- filter(map_INDSE, EF != "")
qINDSE <- left_join(map_INDSE, EFtoEFS, by = "EF")
qINDSE <- select((qINDSE), -c(EF))
qINDSE <- unique(qINDSE)
names(qINDSE) <- sub("EFS", "SECTTECH", names(qINDSE))
qINDSE <- paste0(qINDSE[["SBS"]], ".", qINDSE[["SECTTECH"]])
INDSE <- as.data.frame(qINDSE)
# final consumption
sum_INDSE <- iCo2EmiFac[,,INDSE[, 1]] * VConsFuel[,,INDSE[, 1]]
sum_INDSE <- dimSums(sum_INDSE, 3, na.rm = TRUE)
getItems(sum_INDSE, 3) <- "Emissions|CO2|Energy|Demand|Industry"
# write data in mif file
write.report(sum_INDSE[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Energy|Demand|Residential and Commercial
DOMSE <- readGDX('./blabla.gdx', "DOMSE")
DOMSE <- as.data.frame(DOMSE)
map_DOMSE <- sets4 %>% filter(SBS %in% DOMSE[,1])
map_DOMSE <- filter(map_DOMSE, EF != "")
qDOMSE <- left_join(map_DOMSE, EFtoEFS, by = "EF")
qDOMSE <- select((qDOMSE), -c(EF))
qDOMSE <- unique(qDOMSE)
names(qDOMSE) <- sub("EFS", "SECTTECH", names(qDOMSE))
qDOMSE <- paste0(qDOMSE[["SBS"]], ".", qDOMSE[["SECTTECH"]])
DOMSE <- as.data.frame(qDOMSE)
# final consumption
sum_DOMSE <- iCo2EmiFac[,,DOMSE[, 1]] * VConsFuel[,,DOMSE[, 1]]
sum_DOMSE <- dimSums(sum_DOMSE, 3, na.rm = TRUE)
getItems(sum_DOMSE, 3) <- "Emissions|CO2|Energy|Demand|Residential and Commercial"
# write data in mif file
write.report(sum_DOMSE[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Energy|Demand|Transportation
sum_TRANSE <- sum5 # transport
getItems(sum_TRANSE, 3) <- "Emissions|CO2|Energy|Demand|Transportation"
# write data in mif file
write.report(sum_TRANSE[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Energy|Demand|Bunkers
sum_Bunkers <- sum7 # Bunkers
getItems(sum_Bunkers, 3) <- "Emissions|CO2|Energy|Demand|Bunkers"
# write data in mif file
write.report(sum_Bunkers[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Energy|Demand
# Emissions|CO2|Energy|Demand|Bunkers, sum_Bunkers
# Emissions|CO2|Energy|Demand|Transportation, sum_TRANSE
# Emissions|CO2|Energy|Demand|Residential and Commercial, sum_DOMSE
# Emissions|CO2|Energy|Demand|Industry, sum_INDSE
sum_Demand <- sum_Bunkers + sum_TRANSE + sum_DOMSE + sum_INDSE
getItems(sum_Demand, 3) <- "Emissions|CO2|Energy|Demand"
# write data in mif file
write.report(sum_Demand[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Energy|Supply
# input to power generation sector, sum2
# input to district heating plants, sum3
# consumption of energy branch, sum4
# CO2 captured by CCS plants in power generation, sum6
sum_Supply <- sum2 + sum3 + sum4 - sum6
getItems(sum_Supply, 3) <- "Emissions|CO2|Energy|Supply"
# write data in mif file
write.report(sum_Supply[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Energy
# Emissions|CO2|Energy|Demand, sum_Demand
# Emissions|CO2|Energy|Supply, sum_Supply
sum_Energy <- sum_Demand + sum_Supply
getItems(sum_Energy, 3) <- "Emissions|CO2|Energy"
# write data in mif file
write.report(sum_Energy[,,],file="reporting.mif",model="OPEN-PROM",unit = "Mt CO2/yr",append=TRUE,scenario=scenario_name)
# Emissions|CO2|Cumulated
Cumulated <- as.quitte(total_CO2)
Cumulated <- Cumulated %>% group_by(region) %>% mutate(value = cumsum(value))
Cumulated <- as.data.frame(Cumulated)
Cumulated <- as.quitte(Cumulated) %>% as.magpie()
getItems(Cumulated, 3) <- "Emissions|CO2|Cumulated"
Cumulated <- Cumulated /1000
# write data in mif file
write.report(Cumulated,file="reporting.mif",model="OPEN-PROM",unit = "Gt CO2",append=TRUE,scenario=scenario_name)
}