-
Notifications
You must be signed in to change notification settings - Fork 40
/
reportEmi.R
2864 lines (2342 loc) · 157 KB
/
reportEmi.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
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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#' Read in GDX and calculate emissions, used in convGDX2MIF.R for the
#' reporting
#'
#'
#'
#' @param gdx a GDX as created by readGDX, or the file name of a gdx
#' @param output a magpie object containing all needed variables generated by other report*.R functions
#' @param regionSubsetList a list containing regions to create report variables region
#' aggregations. If NULL (default value) only the global region aggregation "GLO" will
#' be created.
#' @param t temporal resolution of the reporting, default:
#' t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)
#'
#' @author Felix Schreyer, Simón Moreno Leiva
#' @examples
#' \dontrun{
#' reportEmi(gdx)
#' }
#' @export
#'
#' @importFrom gdx readGDX
#' @importFrom dplyr %>% filter full_join group_by inner_join left_join mutate rename select summarise
#' @importFrom magclass mselect dimSums mselect<- collapseDim getItems getRegions getYears
#' @importFrom madrat toolAggregate
#' @importFrom tibble as_tibble
reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) {
# emissions calculation requires information from other reporting functions
if (is.null(output)) {
message("reportEmi executes reportFE")
output <- mbind(output, reportFE(gdx, regionSubsetList, t))
}
# intialize varibles used in dplyr operations
all_enty2 <- all_te <- all_enty <- all_enty1 <- emi_sectors <- all_emiMkt <- all_in <- emiAll <- NULL
# Read Data from GDX ----
####### get realisations #########
module2realisation <- readGDX(gdx, "module2realisation")
rownames(module2realisation) <- module2realisation$modules
# unit conversion parameters needed
sm_TWa_2_MWh <- readGDX(gdx, "sm_TWa_2_MWh") # conversion of TWa (native REMIND energy units) to MWh
pm_conv_TWa_EJ <- readGDX(gdx, "pm_conv_TWa_EJ") # conversion of TWa (native REMIND energy units) to EJ
sm_c_2_co2 <- readGDX(gdx, "sm_c_2_co2")
GtC_2_MtCO2 <- sm_c_2_co2 * 1000 # conversion of GtC to MtCO2
sm_tgn_2_pgc <- readGDX(gdx, "sm_tgn_2_pgc") # conversion of GtN of N2 to GtC Co2eq
sm_tgch4_2_pgc <- readGDX(gdx, "sm_tgch4_2_pgc") # conversion of MtCH4 to GtC Co2eq
MtN2_to_ktN2O <- 44 / 28 * 1000 # conversion from MtN to ktN2O
# other parameters required
pm_ts <- readGDX(gdx, "pm_ts") # years per time step of model
# switches relevant for emissions reporting
cm_multigasscen <- readGDX(gdx, "cm_multigasscen")
# sets required
emiTe <- readGDX(gdx, "emiTe") # emission gases
emi2te <- readGDX(gdx, "emi2te") # conversions to emissions
pe2se <- readGDX(gdx, "pe2se") # pe2se conversions
se2fe <- readGDX(gdx, "se2fe") # se2fe conversions
emiMacSector2emiMac <- readGDX(gdx, "emiMacSector2emiMac") # MAC sector to emissions gas
peFos <- readGDX(gdx, "peFos") # fossil PE carriers
emiInd37_fuel <- readGDX(gdx, "emiInd37_fuel") # energy-related industry CCS categories (excl. co2 cement CCS)
emiMac2sector <- readGDX(gdx, "emiMac2sector") # mapping of MAC sectors to emissions sectors and gases
macSector2emiMkt <- readGDX(gdx, "macSector2emiMkt") # mapping of MAC sectors to emissions markets
fe2ppfEn <- readGDX(gdx, "fe2ppfEn") # mapping of FE to bottom-level CES tree nodes
entyFe2Sector <- readGDX(gdx, "entyFe2Sector") %>%
rename(all_enty1 = all_enty) # mapping of combination of FE to sectors which are actually used
sector2emiMkt <- readGDX(gdx, "sector2emiMkt") # mapping from sectors to markets
secInd37_2_emiInd37 <- readGDX(gdx, "secInd37_2_emiInd37") # mapping from industry subsectors to industry CCS sectors
entyFe2sector2emiMkt_NonEn <- readGDX(gdx, "entyFe2sector2emiMkt_NonEn", react = "silent") # combinations of FE type, sector, market for which non-energy use exists
# technology sets
teCCS <- readGDX(gdx, "teCCS")
teBio <- readGDX(gdx, "teBio")
teFosCCS <- readGDX(gdx, "teFosCCS")
# additional sets needed
# SE carriers for solids, liquids, gases
if ("seliqsyn" %in% se2fe$all_enty) {
se_liq <- c("seliqfos", "seliqbio", "seliqsyn")
se_gas <- c("segafos", "segabio", "segasyn")
} else {
se_liq <- c("seliqfos", "seliqbio")
se_gas <- c("segafos", "segabio")
}
se_sol <- c("sesofos", "sesobio")
# SE carriers by origin
if (is.null(entySEfos <- readGDX(gdx, 'entySEfos', react = 'silent')))
entySEfos <- c('sesofos', 'seliqfos', 'segafos')
if (is.null(entySEbio <- readGDX(gdx, 'entySEbio', react = 'silent')))
entySEbio <- c('sesobio', 'seliqbio', 'segabio')
if ( is.null(entySEsyn <- readGDX(gdx, 'entySEsyn', react = 'silent'))
|| (length(entySEbio) == length(entySEsyn) && all(entySEbio == entySEsyn)))
entySEsyn <- c('seliqsyn', 'segasyn')
### emissions variables from REMIND (see definitions in core/equations.gms)
# total GHG emissions
vm_co2eq <- readGDX(gdx, "vm_co2eq", field = "l", restore_zeros = F)[, t, ]
# total emissions by gas
vm_emiAllMkt <- readGDX(gdx, "vm_emiAllMkt", field = "l", restore_zeros = F)[, t, ]
# total energy emissions from pe2se and se2fe conversions
vm_emiTeDetailMkt <- readGDX(gdx, c("vm_emiTeDetailMkt","v_emiTeDetailMkt"), field = "l", restore_zeros = F)
# total energy emissions in REMIND
vm_emiTeMkt <- readGDX(gdx, c("vm_emiTeMkt","v_emiTeMkt"), field = "l", restore_zeros = F, format="first_found")[, t, ]
# emissions from MAC curves (non-energy emissions)
vm_emiMacSector <- readGDX(gdx, "vm_emiMacSector", field = "l", restore_zeros = F)[, t, ]
# exogenous emissions (SO2, BC, OC)
pm_emiExog <- readGDX(gdx, "pm_emiExog", field = "l", restore_zeros = F)
# F-Gases
vm_emiFgas <- readGDX(gdx, "vm_emiFgas", field = "l", restore_zeros = F)[, t, ]
# Emissions from MACs (currently: all emissions outside of energy CO2 emissions)
vm_emiMacSector <- readGDX(gdx, "vm_emiMacSector", field = "l", restore_zeros = F)
# energy extraction energy-related CO2 emissions
v_emiEnFuelEx <- readGDX(gdx, "v_emiEnFuelEx", field = "l", restore_zeros = F)
# set to zero if not available
if (is.null(v_emiEnFuelEx)) {
v_emiEnFuelEx <- vm_emiMacSector[, , "co2"] * 0
}
### for emissions of energy system technologies
# emission factors of technologies
pm_emifac <- readGDX(gdx, "pm_emifac", restore_zeros = F)[, t, ]
# emissions factors of non-energy use
pm_emifacNonEnergy <- readGDX(gdx, "pm_emifacNonEnergy", restore_zeros = F, react = "silent")[,t,]
# primary energy demand (pe2se emissions factors applied to)
vm_demPE <- readGDX(gdx, "vm_demPE", field = "l", restore_zeros = F)[, t, ]
# final energy demand (se2fe emissions factors applied to)
vm_demFeSector <- readGDX(gdx, "vm_demFeSector", field = "l", restore_zeros = F)[, t, ]
# set NA values to 0,
vm_demFeSector[is.na(vm_demFeSector)] <- 0
# FE demand per industry subsector
o37_demFeIndSub <- readGDX(gdx, "o37_demFeIndSub", restore_zeros = F, react = "silent")[, t, ]
if (!is.null(o37_demFeIndSub)) {
o37_demFeIndSub[is.na(o37_demFeIndSub)] <- 0
}
# CO2 captured per industry subsector
# note: this has to be read in with restore_zeros=T because sometimes it contains only non-zero values for "ETS" emiMkt
# and magclass will wrongly interpret this as a region
pm_IndstCO2Captured <- readGDX(gdx, "pm_IndstCO2Captured", restore_zeros = T,
react = 'silent')[,t,]
# if all zero, set to NULL
if (length(pm_IndstCO2Captured) == 0) {
pm_IndstCO2Captured <- NULL
}
# subset parameter to decrease size as restore_zeros=F was not possible
if (!is.null(pm_IndstCO2Captured)) {
pm_IndstCO2Captured <- pm_IndstCO2Captured[se2fe[,c(1,2)]]
}
# FE non-energy use
vm_demFENonEnergySector <- readGDX(gdx, "vm_demFENonEnergySector", field = "l", react = "silent")[,t,]
if (length(vm_demFENonEnergySector) == 0) {
vm_demFENonEnergySector <- NULL
}
# secondary energy production
vm_prodSe <- readGDX(gdx, "vm_prodSe", field = "l", restore_zeros = F)
# parameter to calculate coupled production
pm_prodCouple <- readGDX(gdx, "pm_prodCouple", field = "l", restore_zeros = F)
### Carbon management variables
# total captured CO2
vm_co2capture <- readGDX(gdx, "vm_co2capture", field = "l", restore_zeros = F)[, t, ]
vm_emiCdrTeDetail <- readGDX(gdx, c("vm_emiCdrTeDetail","v33_emi"), field = "l", restore_zeros = F, react = "silent")[, t, ]
if (is.null(vm_emiCdrTeDetail)) { # compatibility with the CDR module before the portfolio was added
# captured CO2 by DAC
v33_emiDAC <- readGDX(gdx, "v33_emiDAC", field = "l", restore_zeros = F, react = "silent")[, t, ]
if (is.null(v33_emiDAC)) {
v33_emiDAC <- new.magpie(getItems(vm_co2capture, "all_regi"), getItems(vm_co2capture, "ttot"), fill = 0)
}
# captured CO2 by Enhanced Weathering
v33_emiEW <- readGDX(gdx, "v33_emiEW", field = "l", restore_zeros = F, react = "silent")[, t, ]
if (is.null(v33_emiEW)) {
v33_emiEW <- new.magpie(getItems(vm_co2capture, "all_regi"), getItems(vm_co2capture, "ttot"), fill = 0)
}
# variable used in the rest of the reporting
vm_emiCdrTeDetail <- mbind(v33_emiDAC, v33_emiEW)
vm_emiCdrTeDetail <- setNames(vm_emiCdrTeDetail, c("dac", "weathering"))
}
# stored CO2
vm_co2CCS <- readGDX(gdx, "vm_co2CCS", field = "l", restore_zeros = F)[, t, ]
# CO2 captured by industry sectors
vm_emiIndCCS <- readGDX(gdx, "vm_emiIndCCS", field = "l", restore_zeros = T)[, t, ]
getSets(vm_emiIndCCS)[3] <- "secInd37" # relabel subsector dimension to match with other parameters
# CO2 released by CCU
vm_co2CCUshort <- readGDX(gdx, "vm_co2CCUshort", field = "l", restore_zeros = F)[, t, ]
# variable to release captured CO2 when no CCU capacities are standing anymore vent captured CO2
v_co2capturevalve <- readGDX(gdx, "v_co2capturevalve", field = "l", restore_zeros = F)[, t, ]
# CO2 captured per industry subsector
# NOTE: The parameter pm_IndstCO2Captured was calculated without taking into
# account the different emission factors of energy carriers, so we recalculate
# it here. Might load it again when we are reasonably sure we won't process
# any gdxes with the faulty parameter any more.
vm_emiIndCCS_tibble <- vm_emiIndCCS[,,emiInd37_fuel] %>%
as_tibble() %>%
select(t = 'ttot', regi = 'all_regi', emiInd37 = 'secInd37',
vm_emiIndCCS = 'value') %>%
left_join(secInd37_2_emiInd37, 'emiInd37') %>%
select(-'emiInd37')
o37_demFeIndSub_tibble <- o37_demFeIndSub %>%
as_tibble() %>%
select(t = 'ttot', regi = 'all_regi', sety = 'all_enty',
fety = 'all_enty1', 'secInd37', 'emiMkt' = 'all_emiMkt',
o37_demFEindsub = 'value')
pm_emifac_tibble <- pm_emifac %>%
mselect(mutate(se2fe, all_enty2 = 'co2')) %>%
as_tibble() %>%
select(t = 'tall', regi = 'all_regi', fety = 'all_enty1',
pm_emifac = 'value') %>%
# extend fossil emission factors to biomass and synfuels
left_join(
se2fe %>%
distinct(sety = .data$all_enty, fety = .data$all_enty1),
by = 'fety',
relationship = 'many-to-many'
)
subsector_total_emissions <- inner_join(
o37_demFeIndSub_tibble,
pm_emifac_tibble,
c('t', 'regi', 'sety', 'fety')
) %>%
group_by(.data$t, .data$regi, .data$secInd37) %>%
summarise(
subsector_total_emissions = sum(.data$o37_demFEindsub * .data$pm_emifac),
.groups = 'drop')
subsector_emissions <- inner_join(
o37_demFeIndSub_tibble,
pm_emifac_tibble,
c('t', 'regi', 'sety', 'fety')
) %>%
group_by(.data$t, .data$regi, .data$secInd37, .data$sety, .data$fety,
.data$emiMkt) %>%
summarise(
subsector_emissions = sum(.data$o37_demFEindsub * .data$pm_emifac),
.groups = 'drop')
pm_IndstCO2Captured <- subsector_emissions %>%
full_join(
inner_join(
vm_emiIndCCS_tibble,
subsector_total_emissions,
c('t', 'regi', 'secInd37')
) %>%
mutate(subsector_capture_share = .data$vm_emiIndCCS
/ .data$subsector_total_emissions) %>%
select(-'vm_emiIndCCS', -'subsector_total_emissions'),
c('t', 'regi', 'secInd37')
) %>%
mutate(
value = .data$subsector_emissions * .data$subsector_capture_share) %>%
select(-'subsector_emissions', -'subsector_capture_share') %>%
select(ttot = 't', all_regi = 'regi', all_enty = 'sety', all_enty1 = 'fety',
'secInd37', all_emiMkt = 'emiMkt', 'value') %>%
as.magpie(spatial = 2, temporal = 1, data = ncol(.)) %>%
ifelse(is.finite(.), ., 0) # replace NaN by 0
rm(vm_emiIndCCS_tibble, subsector_total_emissions, pm_emifac_tibble)
# utility functions ----
# Convert a mixer table into a list that can be passed to mselect() to
# select specified dimensions from a magpie object
.mixer_to_selector <- function(mixer) {
selector <- list()
for (i in seq_len(nrow(mixer))) {
selector <- c(
selector,
list(mixer[i,] %>%
as.list() %>%
# exclude list entries that are NULL
Filter(function(x) { !is.null(x[[1]]) }, x = .) %>%
# coerce character vector elements one level up
lapply(unlist))
)
}
return(selector)
}
# Preliminary Calculations----
# get combinations of SE,FE,sector,emiMkt that exist in vm_demFeSector
FE.map <- se2fe %>%
left_join(entyFe2Sector, by = "all_enty1", relationship = "many-to-many") %>%
left_join(sector2emiMkt, by = "emi_sectors", relationship = "many-to-many") %>%
select( -all_te) %>%
mutate( name = paste(all_enty,all_enty1,emi_sectors,all_emiMkt, sep = "."))
# calculate FE without non-energy use
if (!is.null(vm_demFENonEnergySector)) {
vm_demFENonEnergySector <- mselect(vm_demFENonEnergySector[, , FE.map$name],
all_enty1 = entyFe2sector2emiMkt_NonEn$all_enty,
emi_sectors = entyFe2sector2emiMkt_NonEn$emi_sectors,
all_emiMkt = entyFe2sector2emiMkt_NonEn$all_emiMkt)
# calculate FE without non-energy use
vm_demFeSector_woNonEn <- vm_demFeSector
vm_demFeSector_woNonEn[,,getNames(vm_demFENonEnergySector )] <- vm_demFeSector[,,getNames(vm_demFENonEnergySector )]-vm_demFENonEnergySector
}
# Read-in plastic-related variables
vm_plasticsCarbon <- readGDX(gdx, "vm_plasticsCarbon", field = "l", restore_zeros = T, react = "silent")[,t,]
if (length(vm_plasticsCarbon) == 0) {
vm_plasticsCarbon <- NULL
}
if (!is.null(vm_plasticsCarbon)){
vm_feedstockEmiUnknownFate <- readGDX(gdx, "vm_feedstockEmiUnknownFate", field = "l", restore_zeros = T, react = "silent")[,t,]
vm_incinerationEmi <- readGDX(gdx, "vm_incinerationEmi", field = "l", restore_zeros = T, react = "silent")[,t,]
vm_nonIncineratedPlastics <- readGDX(gdx, "vm_nonIncineratedPlastics", field = "l", restore_zeros = T, react = "silent")[,t,]
}
# create new variable for carbon embbeded in non-incinerated plastics:
# plastics that do not get incinerated and come from biogenic sources
# or synfuels (regardless of syfuel origin)
if (!is.null(vm_plasticsCarbon)) {
# get combinations of SE,FE,sector,emiMkt that exist in vm_nonIncineratedPlastics
FE.feed.map <- se2fe %>%
left_join(entyFe2Sector, by = "all_enty1", relationship = "many-to-many") %>%
left_join(sector2emiMkt, by = "emi_sectors", relationship = "many-to-many") %>%
right_join(entyFe2sector2emiMkt_NonEn %>%
rename(all_enty1 = all_enty)) %>%
select( -all_te) %>%
mutate( name = paste(all_enty,all_enty1,all_emiMkt, sep = "."))
plastic_CDR <- mselect(vm_nonIncineratedPlastics[,,FE.feed.map$name],
all_enty = unique(entySEbio, entySEsyn))
} else {
plastic_CDR <- collapseDim(vm_co2eq)*0
}
# Calculate Variables ----
## 1. Total GHG Emissions ----
out <- NULL
out <- mbind(out,
# total GHG in Mt CO2eq/yr (CO2, CH4, N2O, F-Gases)
setNames(dimSums(vm_emiAllMkt[, , "co2"], dim = 3) * GtC_2_MtCO2 +
dimSums(vm_emiAllMkt[, , "ch4"], dim = 3) * sm_tgch4_2_pgc * GtC_2_MtCO2 +
dimSums(vm_emiAllMkt[, , "n2o"], dim = 3) * sm_tgn_2_pgc * GtC_2_MtCO2 +
vm_emiFgas[, , "emiFgasTotal"],
"Emi|GHG (Mt CO2eq/yr)"),
# total CO2 emissions
setNames(dimSums(vm_emiAllMkt[, , "co2"], dim = 3) * GtC_2_MtCO2,
"Emi|GHG|+|CO2 (Mt CO2eq/yr)"),
# total CH4 emissions in CO2eq (convert from MtCH4 to MtCO2eq)
setNames(dimSums(vm_emiAllMkt[, , "ch4"], dim = 3) * sm_tgch4_2_pgc * GtC_2_MtCO2,
"Emi|GHG|+|CH4 (Mt CO2eq/yr)"),
# total N2O emissions in CO2eq (convert from MtN to MtCO2eq)
setNames(dimSums(vm_emiAllMkt[, , "n2o"], dim = 3) * sm_tgn_2_pgc * GtC_2_MtCO2,
"Emi|GHG|+|N2O (Mt CO2eq/yr)"),
# F-Gases (Mt CO2eq)
setNames(vm_emiFgas[, , "emiFgasTotal"],
"Emi|GHG|+|F-Gases (Mt CO2eq/yr)")
)
## 2. CO2 Emissions ----
### 2.1 Energy CO2 Emissions ----
# (splitting q_emiTeMkt into supply-side and demand-side)
# pe2se,extraction,CCU -> supply-side
# se2fe,industryCCS -> demand-side
# compute share of stored carbon from total captured carbon
p_share_CCS <- dimSums(vm_co2CCS, dim = 3, na.rm = T) / dimSums(vm_co2capture, dim = 3)
p_share_CCS[is.infinite(p_share_CCS)] <- 0
p_share_CCS[is.na(p_share_CCS)] <- 0
sel_vm_emiTeDetailMkt_cco2 <- if(getSets(vm_emiTeDetailMkt)[[6]] == "emiAll"){
mselect(vm_emiTeDetailMkt, emiAll = "cco2")
} else {
mselect(vm_emiTeDetailMkt, all_enty2 = "cco2")
}
# supply and demand emissions of conversion technologies
if (names(emi2te)[4] == "emiAll") {
emi2te.pe2se.co2 <- emi2te %>%
filter(emiAll == "co2") %>%
filter(all_te %in% pe2se$all_te)
} else {
emi2te.pe2se.co2 <- emi2te %>%
filter(all_enty2 == "co2") %>%
filter(all_te %in% pe2se$all_te)
}
sel_pm_emifac_pe2se <- if(getSets(pm_emifac)[[6]] == "emiAll"){
mselect(pm_emifac, all_te = pe2se$all_te, emiAll = "co2")
} else {
mselect(pm_emifac, all_te = pe2se$all_te, all_enty2 = "co2")
}
sel_pm_emifac_se2fe <- if(getSets(pm_emifac)[[6]] == "emiAll"){
mselect(pm_emifac, all_te = se2fe$all_te, emiAll = "co2")
} else {
mselect(pm_emifac, all_te = se2fe$all_te, all_enty2 = "co2")
}
# co2 emissions factor of pe2se technologies
pm_emifac.co2.pe <- dimSums(sel_pm_emifac_pe2se, dim = c(3.4))
# co2 emissions factor of fe carriers
pm_emifac.co2.fe <- dimSums(sel_pm_emifac_se2fe, dim = c(3.3,3.4))
# only retain combinations of vm_demFeSector subdimensions which are in entyFe2Sector and sector2emiMkt
emi.map.fe <- data.frame(all_enty = getItems(pm_emifac.co2.fe, dim = "all_enty", full = T),
all_enty1 = getItems(pm_emifac.co2.fe, dim = "all_enty1", full = T)) %>%
left_join(entyFe2Sector, by = "all_enty1", relationship = "many-to-many") %>%
left_join(sector2emiMkt, by = "emi_sectors", relationship = "many-to-many") %>%
mutate(name = paste(all_enty, all_enty1, emi_sectors, all_emiMkt, sep = "."))
# calculate captured CO2 per pe2se technology
sel_pm_emifac_pe2seCCO2 <- if(getSets(pm_emifac)[[6]] == "emiAll"){
mselect(pm_emifac, all_te = pe2se$all_te, emiAll = "cco2")
} else {
mselect(pm_emifac, all_te = pe2se$all_te, all_enty2 = "cco2")
}
pm_emifac.cco2.pe <- dimSums(sel_pm_emifac_pe2seCCO2, dim = c(3.4))
CCO2Pe2Se <- pm_emifac.cco2.pe * vm_demPE[,,getNames(pm_emifac.cco2.pe)]
# calculate emissions from pe2se conversions and fe carriers
# emissions from pe2se conversions (supply-side emissions)
EmiPe2Se <- pm_emifac.co2.pe * vm_demPE[, , getNames(pm_emifac.co2.pe)]
# increase supply-side emissions by captured carbon which is not stored (goes into CCU)
# as synfuel carbon should be accounted on the side of the CO2-Provider
EmiPe2Se[,,getNames(CCO2Pe2Se, dim=3)] <- EmiPe2Se[,,getNames(CCO2Pe2Se, dim=3)] + CCO2Pe2Se * (1 - p_share_CCS)
# emissions from fe carriers (demand-side emissions)
# if FE non-energy use available, subtract it before calculating emissions
if (!is.null(vm_demFENonEnergySector)) {
EmiFeCarrier <- pm_emifac.co2.fe * vm_demFeSector_woNonEn[, , emi.map.fe$name]
} else {
EmiFeCarrier <- pm_emifac.co2.fe * vm_demFeSector[, , emi.map.fe$name]
}
# calculate total energy supply and demand co2 emissions
out <- mbind(out,
# supply-side energy CO2 emissions
# pe2se emissions
setNames((dimSums(EmiPe2Se, dim = 3)
# add extraction energy-related CO2 emissions
+ dimSums(v_emiEnFuelEx[, , "co2"], dim = 3))
* GtC_2_MtCO2,
"Emi|CO2|Energy|+|Supply (Mt CO2/yr)"),
# demand-side energy CO2 emissions
# fe emissions
setNames((dimSums(EmiFeCarrier, dim = 3)
# subtract industry CCS
- dimSums(vm_emiIndCCS[, , emiInd37_fuel], dim = 3)*p_share_CCS
# subtract synthetic and biogenic carbon contained in industrial feedstocks
- dimSums(plastic_CDR, dim=3)
)*GtC_2_MtCO2,
"Emi|CO2|Energy|+|Demand (Mt CO2/yr)")
)
# CO2 emissions from the end-of-life of carbon-bearing products
if (!is.null(vm_plasticsCarbon)) {
out <- mbind(out,
setNames(dimSums(vm_feedstockEmiUnknownFate, dim=3)* GtC_2_MtCO2,
"Emi|CO2|Energy|Waste|+|Feedstocks unknown fate (Mt CO2/yr)"),
setNames(dimSums(vm_incinerationEmi, dim=3)* GtC_2_MtCO2,
"Emi|CO2|Energy|Waste|+|Plastics Incineration (Mt CO2/yr)")
)
out <- mbind(out,
setNames(out[, , "Emi|CO2|Energy|Waste|+|Feedstocks unknown fate (Mt CO2/yr)"]
+ out[, , "Emi|CO2|Energy|Waste|+|Plastics Incineration (Mt CO2/yr)"],
"Emi|CO2|Energy|+|Waste (Mt CO2/yr)")
)
}
#### 2.1.2 Energy Supply ----
#### calculations required for coupled production
# calculate shares of first output and second output for technologies with coupled production
# filter for positive coupled production parameters of pe2se technologies and only get coupled production and not own consumption
pm_prodCouple.prod <- pm_prodCouple[, , intersect(getNames(pm_prodCouple, dim = 3), pe2se$all_te)]
pm_prodCouple.prod[pm_prodCouple.prod <= 0] <- 0
# production of second output
vm_prodSe_coupleProd <- pm_prodCouple.prod * vm_prodSe[, , getNames(pm_prodCouple.prod, dim = 3)]
# calculate weights of emissions distribution for coupled production
# weights follow shares of coupled product/total output
p_weights_cp <- vm_prodSe_coupleProd / (vm_prodSe[, , getNames(pm_prodCouple.prod, dim = 3)] + vm_prodSe_coupleProd)
# for power generating technologies technologies with heat as a coupled product, rescale with halfed heat emissions
# this splits electricity and heat emissions in a chp plant roughly as if both products were produced by 2 seperate plants (Finnish Method)
# where the heat plant has about double the efficiency of the power plant
mselect(p_weights_cp, all_enty1 = "seel", all_enty2 = "sehe") <- 0.5 * mselect(vm_prodSe_coupleProd, all_enty1 = "seel", all_enty2 = "sehe") / (mselect(vm_prodSe[, , getNames(pm_prodCouple.prod, dim = 3)], all_enty1 = "seel") + 0.5 * mselect(vm_prodSe_coupleProd, all_enty1 = "seel", all_enty2 = "sehe"))
# pe2se emissions technologies with coupled production
emi.te.cp <- intersect(paste(getItems(p_weights_cp, dim = "all_enty", full = T),
getItems(p_weights_cp, dim = "all_enty1", full = T),
getItems(p_weights_cp, dim = "all_te", full = T), sep = "."),
getItems(EmiPe2Se, dim = 3))
# pe2se emissions technologies without coupled production
emi.te.nocp <- setdiff(getNames(EmiPe2Se), emi.te.cp)
# only retain coupled production factors for technologies which have emissions
p_weights_cp <- p_weights_cp[, , emi.te.cp]
p_weights_cp[is.na(p_weights_cp)] <- 0
# # TODO: refactor this to a more elegant way at some point
# # assign 1 to those elements not in p_weight_cp
#
# df.emi.te.cp <- data.frame(all_enty=getItems(EmiPe2Se, dim="all_enty", full = T),
# all_enty1=getItems(EmiPe2Se, dim="all_enty1", full = T),
# all_te=getItems(EmiPe2Se, dim="all_te", full = T))
#
# p_weights_test <- p_weights_cp[df.emi.te.cp]
# p_weights_test[is.na(p_weights_test)] <- 1
#
# test <- p_weights_test*EmiPe2Se
out <- mbind(out,
# electricity emissions (w/ coupled production)
# electricity emissions from pe2se technologies which have no coupled product
setNames((dimSums(mselect(EmiPe2Se[, , emi.te.nocp], all_enty1 = "seel"), dim = 3)
# emissions from coupled production technologies where electricty is first product
+ dimSums(mselect((1 - p_weights_cp) * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty1 = "seel"), dim = 3)
# emissions from coupled production technologies where electricty is coupled/second product
+ dimSums(mselect(p_weights_cp * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty2 = "seel"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|+|Electricity w/ couple prod (Mt CO2/yr)"),
# heat emissions (w/ coupled production)
# heat emissions from pe2se technologies which have no coupled product
setNames((dimSums(mselect(EmiPe2Se[, , emi.te.nocp], all_enty1 = "sehe"), dim = 3)
# emissions from coupled production technologies where heat is first product
+ dimSums(mselect((1 - p_weights_cp) * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty1 = "sehe"), dim = 3)
# emissions from coupled production technologies where heat is coupled/second product
+ dimSums(mselect(p_weights_cp * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty2 = "sehe"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|+|Heat w/ couple prod (Mt CO2/yr)"),
# hydrogen emissions (w/ coupled production)
# hydrogen emissions from pe2se technologies which have no coupled product
setNames((dimSums(mselect(EmiPe2Se[, , emi.te.nocp], all_enty1 = "seh2"), dim = 3)
# emissions from coupled production technologies where hydrogen is first product
+ dimSums(mselect((1 - p_weights_cp) * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty1 = "seh2"), dim = 3)
# emissions from coupled production technologies where hydrogen is coupled/second product
+ dimSums(mselect(p_weights_cp * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty2 = "seh2"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|+|Hydrogen w/ couple prod (Mt CO2/yr)"),
# supply-side solids emissions (w/ coupled production)
# solids emissions from pe2se technologies which have no coupled product
setNames((dimSums(mselect(EmiPe2Se[, , emi.te.nocp], all_enty1 = se_sol), dim = 3)
# emissions from coupled production technologies where solids are first product
+ dimSums(mselect((1 - p_weights_cp) * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty1 = se_sol), dim = 3)
# emissions from coupled production technologies where solids are coupled/second product
+ dimSums(mselect(p_weights_cp * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty2 = se_sol), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|+|Solids w/ couple prod (Mt CO2/yr)"),
# supply-side liquids emissions (w/ coupled production)
# liquids emissions from pe2se technologies which have no coupled product
setNames((dimSums(mselect(EmiPe2Se[, , emi.te.nocp], all_enty1 = se_liq), dim = 3)
# emissions from coupled production technologies where liquids are first product
+ dimSums(mselect((1 - p_weights_cp) * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty1 = se_liq), dim = 3)
# emissions from coupled production technologies where liquids are coupled/second product
+ dimSums(mselect(p_weights_cp * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty2 = se_liq), dim = 3)
# add energy-related extraction CO2 emissions (small!), has to be added somewhere such that it adds up with above levels
+ dimSums(v_emiEnFuelEx[, , "co2"], dim = 3)
) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|+|Liquids w/ couple prod (Mt CO2/yr)"),
# supply-side gases emissions (w/ coupled production)
# gases emissions from pe2se technologies which have no coupled product
setNames((dimSums(mselect(EmiPe2Se[, , emi.te.nocp], all_enty1 = se_gas), dim = 3)
# emissions from coupled production technologies where gases are first product
+ dimSums(mselect((1 - p_weights_cp) * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty1 = se_gas), dim = 3)
# emissions from coupled production technologies where gases are coupled/second product
+ dimSums(mselect(p_weights_cp * EmiPe2Se[, , getNames(p_weights_cp, dim = 3)], all_enty2 = se_gas), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|+|Gases w/ couple prod (Mt CO2/yr)")
)
# energy-related CO2 emissions from extraction processes
out <- mbind(out,
setNames(dimSums(v_emiEnFuelEx[, , "co2"], dim = 3) * GtC_2_MtCO2,
"Emi|CO2|Energy|Supply|Extraction (Mt CO2/yr)")
)
# split into electric and non-electric energy supply emissions
out <- mbind(out,
# total gross non-eletric energy supply emissions
setNames(out[, , "Emi|CO2|Energy|+|Supply (Mt CO2/yr)"]
- out[, , "Emi|CO2|Energy|Supply|+|Electricity w/ couple prod (Mt CO2/yr)"],
"Emi|CO2|Energy|Supply|Non-electric (Mt CO2/yr)"))
#### 2.1.3 Energy Demand ----
# split into sectors
out <- mbind(out,
# buildings emissions
setNames(dimSums(EmiFeCarrier[, , "build"], dim = 3) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|+|Buildings (Mt CO2/yr)"),
# industry emissions: fe carrier emissions - industry CCS
# (carbon captured by industry used for CCU is still accounted as industry emissions
# as only account negative emissions for the CO2 provider if carbon gets stored)
setNames((dimSums(EmiFeCarrier[, , "indst"], dim = 3)
- dimSums(vm_emiIndCCS[, , emiInd37_fuel]* p_share_CCS, dim = 3)
# substract synthetic and biogenic carbon contained in industrial feedstocks
- dimSums(plastic_CDR, dim=3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|+|Industry (Mt CO2/yr)"),
# transport emissions: fe carrier emissions
setNames(dimSums(EmiFeCarrier[, , "trans"], dim = 3) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|+|Transport (Mt CO2/yr)"),
# cdr energy requirement emissions: fe carrier emissions
setNames(dimSums(EmiFeCarrier[, , "CDR"], dim = 3) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|+|CDR (Mt CO2/yr)")
)
# split of demand-side emissions into FE carriers and industry-specific reporting
# reporting if FE per industry subsector o37_demFeIndSub exists
if (!is.null(o37_demFeIndSub)) {
### calculate FE per industry subsector w/o Non-energy Use
o37_demFeIndSub_woNonEn <- o37_demFeIndSub
sefe.chem.feedstock <- intersect(getNames(collapseDim(o37_demFeIndSub_woNonEn[,,"chemicals.ETS"])), getNames(collapseDim(vm_demFENonEnergySector[,,"indst"])))
o37_demFeIndSub_woNonEn[,,"chemicals"][,,sefe.chem.feedstock] <- o37_demFeIndSub_woNonEn[,,"chemicals"][,,sefe.chem.feedstock] - collapseDim(vm_demFENonEnergySector[,,"indst"][,,sefe.chem.feedstock])
# relabel industry energy CC from CCS sectors to industry sectors
vm_emiIndCCS_Mapped <- toolAggregate(
vm_emiIndCCS[, , emiInd37_fuel],
rel = secInd37_2_emiInd37 %>% filter(.data$emiInd37 %in% emiInd37_fuel),
from = "emiInd37", to = "secInd37", dim = 3)
# calculate captured CO2 per subsector and FE carrier by multiplying subsectoral share of fesos, fehos, fegas in total FE from fesos, fehos and fegas with the captured CO2 by subsector
vm_emiIndCCS_Sub <- vm_emiIndCCS_Mapped * dimSums(mselect(o37_demFeIndSub_woNonEn, all_enty1 = c("fesos", "fehos", "fegas")), dim = c(3.1, 3.4)) / dimSums(mselect(o37_demFeIndSub_woNonEn, all_enty1 = c("fesos", "fehos", "fegas")), dim = c(3.1, 3.2, 3.4))
vm_emiIndCCS_Sub[is.na(vm_emiIndCCS_Sub)] <- 0
getSets(vm_emiIndCCS_Sub)[c(3, 4)] <- c("secInd37", "all_enty1")
# calculate captured CO2 per subsector and FE carrier
vm_emiIndCCS_Sub <- dimSums(pm_IndstCO2Captured,
dim = c('all_enty', 'all_emiMkt'))
# calculate industry emissions by subsector (before industry CO2 Capture)
sel_pm_emifac_co2 <- if(getSets(pm_emifac)[[6]] == "emiAll"){
mselect(pm_emifac, all_enty1 = getNames(o37_demFeIndSub_woNonEn, dim = 2), emiAll = "co2")
} else {
mselect(pm_emifac, all_enty1 = getNames(o37_demFeIndSub_woNonEn, dim = 2), all_enty2 = "co2")
}
pm_emifac.fe.indst <- dimSums(sel_pm_emifac_co2, dim = c(3.3, 3.4))
EmiIndSubSec <- pm_emifac.fe.indst * o37_demFeIndSub_woNonEn[, , getNames(pm_emifac.fe.indst)]
# calculate demand-side Solids, Liquids and gases emissions (after industry CO2 Capture)
if (!is.null(vm_plasticsCarbon)){
out <- mbind(out,
# solids emissions: direct solids emissions of all sectors - industry CCS of solids
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = "fesos"), dim = 3)
- dimSums(mselect(vm_emiIndCCS_Sub, all_enty1 = "fesos")*p_share_CCS, dim = 3)
# substract synthetic and biogenic carbon contained in non-incinerated plastics
- dimSums(mselect(vm_nonIncineratedPlastics, all_enty=c("sesobio","sesosyn"), all_enty1 = "fesos"), dim=3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|++|Solids (Mt CO2/yr)"),
# liquids emissions: direct liquids emissions of all sectors - industry CCS of liquids
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = c("fehos", "fepet", "fedie")), dim = 3)
- dimSums(mselect(vm_emiIndCCS_Sub, all_enty1 = "fehos")*p_share_CCS, dim = 3)
# substract synthetic and biogenic carbon contained in non-incinerated plastics
- dimSums(mselect(vm_nonIncineratedPlastics, all_enty=c("seliqbio","seliqsyn"), all_enty1 = "fehos"), dim=3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|++|Liquids (Mt CO2/yr)"),
# gases emissions: direct gases emissions of all sectors - industry CCS of gases
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = c("fegas", "fegat")), dim = 3)
- dimSums(mselect(vm_emiIndCCS_Sub, all_enty1 = "fegas")*p_share_CCS, dim = 3)
# substract synthetic and biogenic carbon contained in non-incinerated plastics
- dimSums(mselect(vm_nonIncineratedPlastics, all_enty=c("segabio","segasyn"), all_enty1 = "fegas"), dim=3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|++|Gases (Mt CO2/yr)")
)
} else {
out <- mbind(out,
# solids emissions: direct solids emissions of all sectors - industry CCS of solids
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = "fesos"), dim = 3)
- dimSums(mselect(vm_emiIndCCS_Sub, all_enty1 = "fesos")*p_share_CCS, dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|++|Solids (Mt CO2/yr)"),
# liquids emissions: direct liquids emissions of all sectors - industry CCS of liquids
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = c("fehos", "fepet", "fedie")), dim = 3)
- dimSums(mselect(vm_emiIndCCS_Sub, all_enty1 = "fehos")*p_share_CCS, dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|++|Liquids (Mt CO2/yr)"),
# gases emissions: direct gases emissions of all sectors - industry CCS of gases
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = c("fegas", "fegat")), dim = 3)
- dimSums(mselect(vm_emiIndCCS_Sub, all_enty1 = "fegas")*p_share_CCS, dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|++|Gases (Mt CO2/yr)")
)
}
# sectoral demand-side emissions across energy carriers
out <- mbind(out,
# buildings
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = "fesos", emi_sectors = "build"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|Buildings|+|Solids (Mt CO2/yr)"),
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = "fehos", emi_sectors = "build"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|Buildings|+|Liquids (Mt CO2/yr)"),
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = "fegas", emi_sectors = "build"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|Buildings|+|Gases (Mt CO2/yr)"),
# transport
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = c("fedie", "fepet"), emi_sectors = "trans"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|Transport|+|Liquids (Mt CO2/yr)"),
setNames((dimSums(mselect(EmiFeCarrier, all_enty1 = c("fegat"), emi_sectors = "trans"), dim = 3)) * GtC_2_MtCO2,
"Emi|CO2|Energy|Demand|Transport|+|Gases (Mt CO2/yr)")
)
##### industry ----
variable_prefix <- 'Emi|CO2|Energy|Demand|Industry|'
variable_postfix <- ' (Mt CO2/yr)'
mixer <- tribble(
~variable, ~secInd37, ~all_enty, ~all_enty1,
'+|Solids', NULL, NULL, 'fesos',
'+|Liquids', NULL, NULL, 'fehos',
'+|Gases', NULL, NULL, 'fegas',
'Solids|+|Fossil', NULL, 'sesofos', 'fesos',
'Solids|+|Biomass', NULL, 'sesobio', 'fesos',
'Liquids|+|Fossil', NULL, 'seliqfos', 'fehos',
'Liquids|+|Biomass', NULL, 'seliqbio', 'fehos',
'Liquids|+|Synfuel', NULL, 'seliqsyn', 'fehos',
'Gases|+|Fossil', NULL, 'segafos', 'fegas',
'Gases|+|Biomass', NULL, 'segabio', 'fegas',
'Gases|+|Synfuel', NULL, 'segasyn', 'fegas',
'++|Cement', 'cement', NULL, NULL,
'Cement|+|Solids', 'cement', NULL, 'fesos',
'Cement|Solids|+|Fossil', 'cement', 'sesofos', 'fesos',
'Cement|Solids|+|Biomass', 'cement', 'sesobio', 'fesos',
'Cement|+|Liquids', 'cement', NULL, 'fehos',
'Cement|Liquids|+|Fossil', 'cement', 'seliqfos', 'fehos',
'Cement|Liquids|+|Biomass', 'cement', 'seliqbio', 'fehos',
'Cement|Liquids|+|Synfuel', 'cement', 'seliqsyn', 'fehos',
'Cement|+|Gases', 'cement', NULL, 'fegas',
'Cement|Gases|+|Fossil', 'cement', 'segafos', 'fegas',
'Cement|Gases|+|Biomass', 'cement', 'segabio', 'fegas',
'Cement|Gases|+|Synfuel', 'cement', 'segasyn', 'fegas',
'++|Chemicals', 'chemicals', NULL, NULL,
'Chemicals|+|Solids', 'chemicals', NULL, 'fesos',
'Chemicals|Solids|+|Fossil', 'chemicals', 'sesofos', 'fesos',
'Chemicals|Solids|+|Biomass', 'chemicals', 'sesobio', 'fesos',
'Chemicals|+|Liquids', 'chemicals', NULL, 'fehos',
'Chemicals|Liquids|+|Fossil', 'chemicals', 'seliqfos', 'fehos',
'Chemicals|Liquids|+|Biomass', 'chemicals', 'seliqbio', 'fehos',
'Chemicals|Liquids|+|Synfuel', 'chemicals', 'seliqsyn', 'fehos',
'Chemicals|+|Gases', 'chemicals', NULL, 'fegas',
'Chemicals|Gases|+|Fossil', 'chemicals', 'segafos', 'fegas',
'Chemicals|Gases|+|Biomass', 'chemicals', 'segabio', 'fegas',
'Chemicals|Gases|+|Synfuel', 'chemicals', 'segasyn', 'fegas',
'++|Steel', 'steel', NULL, NULL,
'Steel|+|Solids', 'steel', NULL, 'fesos',
'Steel|Solids|+|Fossil', 'steel', 'sesofos', 'fesos',
'Steel|Solids|+|Biomass', 'steel', 'sesobio', 'fesos',
'Steel|+|Liquids', 'steel', NULL, 'fehos',
'Steel|Liquids|+|Fossil', 'steel', 'seliqfos', 'fehos',
'Steel|Liquids|+|Biomass', 'steel', 'seliqbio', 'fehos',
'Steel|Liquids|+|Synfuel', 'steel', 'seliqsyn', 'fehos',
'Steel|+|Gases', 'steel', NULL, 'fegas',
'Steel|Gases|+|Fossil', 'steel', 'segafos', 'fegas',
'Steel|Gases|+|Biomass', 'steel', 'segabio', 'fegas',
'Steel|Gases|+|Synfuel', 'steel', 'segasyn', 'fegas',
'++|Other Industry', 'otherInd', NULL, NULL,
'Other Industry|+|Solids', 'otherInd', NULL, 'fesos',
'Other Industry|Solids|+|Fossil', 'otherInd', 'sesofos', 'fesos',
'Other Industry|+|Liquids', 'otherInd', NULL, 'fehos',
'Other Industry|Liquids|+|Fossil', 'otherInd', 'seliqfos', 'fehos',
'Other Industry|+|Gases', 'otherInd', NULL, 'fegas',
'Other Industry|Gases|+|Fossil', 'otherInd', 'segafos', 'fegas'
) %>%
mutate(
variable = paste0(variable_prefix, .data$variable, variable_postfix))
# if feedstocks are represented in REMIND
if (!is.null(vm_plasticsCarbon)){
plastic_CDR_SubSec <- add_dimension(plastic_CDR, dim = 3.1, add = 'secInd37', nm = 'chemicals')
out <- mbind(
out,
lapply(.mixer_to_selector(mixer), function(x) {
setNames(
# extract relevant portions from EmiIndSubSec and vm_emiIndCCS_Sub,
# call mselect(), but without the 'variable' column
( dimSums(mselect(EmiIndSubSec, x[setdiff(names(x), 'variable')]),
dim = 3)
- dimSums(
( mselect(pm_IndstCO2Captured, x[setdiff(names(x), 'variable')])
* p_share_CCS
),
dim = 3)
# subtract carbon contained in plastics that are not incinerated
- dimSums(
( mselect(plastic_CDR_SubSec, x[setdiff(names(x), 'variable')])
),
dim = 3)
) * GtC_2_MtCO2,
x[['variable']])
}) %>%
mbind())
# Baseline emission before CCS, corresponds to energy carbon content
out <- mbind(
# energy emissions
subsector_emissions %>%
mutate(
secInd37 = case_when(
'cement' == .data$secInd37 ~ 'Cement',
'chemicals' == .data$secInd37 ~ 'Chemicals',
'steel' == .data$secInd37 ~ 'Steel',
'otherInd' == .data$secInd37 ~ 'Other Industry',
TRUE ~ NA_character_),
fety = case_when(
'fesos' == .data$fety ~ 'Solids',
'fehos' == .data$fety ~ 'Liquids',
'fegas' == .data$fety ~ 'Gases',
TRUE ~ NA_character_),
origin = case_when(
grepl('fos$', .data$sety) ~ 'Fossil',
grepl('bio$', .data$sety) ~ 'Biomass',
grepl('syn$', .data$sety) ~ 'Hydrogen',
TRUE ~ NA_character_)) %>%
assert(not_na, everything()) %>%
group_by(.data$t, .data$regi, .data$secInd37, .data$fety,
.data$origin) %>%
summarise(value = sum(.data$subsector_emissions)
* as.numeric(GtC_2_MtCO2),
.groups = 'drop') %>%
mutate(d3 = paste0('Emi|CO2|pre-CCS|Energy|Demand|Industry|',
.data$secInd37, '|', .data$fety, '|', .data$origin,
' (Mt CO2/yr)')) %>%
select('t', 'regi', 'd3', 'value') %>%
as.magpie(spatial = 2, temporal = 1, datacol = ncol(.)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)),
# process emissions for cement subsector
readGDX(gdx, 'vm_macBaseInd', field = 'l', restore_zeros = FALSE) %>%
`[`(,,'co2cement_process.cement') %>%
`*`(as.numeric(GtC_2_MtCO2)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)) %>%
`getNames<-`(
value = 'Emi|CO2|pre-CCS|Industrial Processes|Cement (Mt CO2/yr)'),
out)
}
else {
out <- mbind(
out,
lapply(.mixer_to_selector(mixer), function(x) {
setNames(
# extract relevant portions from EmiIndSubSec and vm_emiIndCCS_Sub,
# call mselect(), but without the 'variable' column
( dimSums(mselect(EmiIndSubSec, x[setdiff(names(x), 'variable')]),
dim = 3)
- dimSums(
( mselect(pm_IndstCO2Captured, x[setdiff(names(x), 'variable')])
* p_share_CCS
),
dim = 3)
) * GtC_2_MtCO2,
x[['variable']])
}) %>%
mbind()
)
# Baseline emission before CCS, corresponds to energy carbon content
out <- mbind(
# energy emissions
subsector_emissions %>%
mutate(
secInd37 = case_when(
'cement' == .data$secInd37 ~ 'Cement',
'chemicals' == .data$secInd37 ~ 'Chemicals',
'steel' == .data$secInd37 ~ 'Steel',
'otherInd' == .data$secInd37 ~ 'Other Industry',
TRUE ~ NA_character_),
fety = case_when(
'fesos' == .data$fety ~ 'Solids',
'fehos' == .data$fety ~ 'Liquids',
'fegas' == .data$fety ~ 'Gases',
TRUE ~ NA_character_),
origin = case_when(
grepl('fos$', .data$sety) ~ 'Fossil',
grepl('bio$', .data$sety) ~ 'Biomass',
grepl('syn$', .data$sety) ~ 'Hydrogen',
TRUE ~ NA_character_)) %>%
assert(not_na, everything()) %>%
group_by(.data$t, .data$regi, .data$secInd37, .data$fety,
.data$origin) %>%
summarise(value = sum(.data$subsector_emissions)
* as.numeric(GtC_2_MtCO2),
.groups = 'drop') %>%
mutate(d3 = paste0('Emi|CO2|pre-CCS|Energy|Demand|Industry|',
.data$secInd37, '|', .data$fety, '|', .data$origin,
' (Mt CO2/yr)')) %>%
select('t', 'regi', 'd3', 'value') %>%
as.magpie(spatial = 2, temporal = 1, datacol = ncol(.)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)),
# process emissions
readGDX(gdx, 'vm_macBaseInd', field = 'l', restore_zeros = FALSE) %>%
`[`(,,'co2cement_process.cement') %>%
`*`(as.numeric(GtC_2_MtCO2)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)) %>%
`getNames<-`(
value = 'Emi|CO2|pre-CCS|Industrial Processes|Cement (Mt CO2/yr)'),
out)
}
} else {
# if o37_demFeIndSub not existing in GDX, calculate reporting parameter here, note: works for industry fixed_shares only
if (module2realisation["industry", 2] == "fixed_shares") {
# fixed share of FE demand of industry subsector
p37_shIndFE <- readGDX(gdx, "p37_shIndFE", restore_zeros = F)
# mapping of industry subsectors to industry CCS sectors
# map from pffen to entyFE
p37_shIndFE <- toolAggregate(p37_shIndFE, rel = fe2ppfEn %>% filter(all_in %in% getNames(p37_shIndFE, dim = 1)),
from = "all_in", to = "all_enty", dim = 3.1)
getSets(p37_shIndFE)[c(3)] <- c("all_enty1")
# calculate FE industry demand per subsector
vm_demFeIndSub <- mselect(vm_demFeSector, emi_sectors = "indst", all_enty1 = filter(entyFe2Sector, emi_sectors == "indst")$all_enty1) * p37_shIndFE
# set NAs in vm_demFeIndSub to zero
vm_demFeIndSub[is.na(vm_demFeIndSub)] <- 0
# relabel industry energy CC from CCS sectors to industry sectors
emiInd37 <- NULL
vm_emiIndCCS_Mapped <- toolAggregate(vm_emiIndCCS[, , emiInd37_fuel], rel = secInd37_2_emiInd37 %>% filter(emiInd37 %in% emiInd37_fuel),
from = "emiInd37", to = "secInd37", dim = 3)
# calculate captured CO2 per subsector and FE carrier by multiplying subsectoral share of fesos, fehos, fegas in total FE from fesos, fehos and fegas with the captured CO2 by subsector
vm_emiIndCCS_Sub <- vm_emiIndCCS_Mapped * dimSums(mselect(vm_demFeIndSub, all_enty1 = c("fesos", "fehos", "fegas")), dim = c(3.1, 3.3, 3.4)) / dimSums(mselect(vm_demFeIndSub, all_enty1 = c("fesos", "fehos", "fegas")), dim = c(3.1, 3.2, 3.3, 3.4))