-
Notifications
You must be signed in to change notification settings - Fork 0
/
1a_create_CT_CRF_classification.R
201 lines (157 loc) · 6.26 KB
/
1a_create_CT_CRF_classification.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
#'
#'
#'
#' @author Simon Schulte
#' Date: 2022-06-21 12:16:12
#'
#' Content:
#'
############################################################################## #
##### load packages ############################################################
############################################################################## #
library(data.table)
library(tidyverse)
library(units)
library(ggforce)
#library(my.utils)
library(data.tree)
library(logr)
############################################################################## #
##### general settings #################################################################
############################################################################## #
# source utils
source(file.path('src', 'functions.R'))
# read config and setup log script
config <- setup_config_and_log()
path2output <- config$path2output
############################################################################## #
##### settings #################################################################
############################################################################## #
path2CT <- config$path2CT_CRF_EXIOBASE
############################################################################## #
##### load data #############################################################
############################################################################## #
# which classifications exist in emissions data?
# classes_from_CT <- rio::import(path2CT) %>%
# as.data.table %>%
# .$CRF_class %>%
# na.omit %>%
# unique %>%
# data.table(original = .)
classes_from_CT <- readRDS(file.path(path2output, 'prepare_CT_UNFCCC.RData')) %>%
.$CRF_class %>%
na.omit %>%
unique %>%
data.table(original = .)
classes_from_CT[, id := gsub(' ', '_', tolower(original))]
# how are these classifications named in NIR uncertainty tables? ===============
matching_classes <- vector('list', length(classes_from_CT$id)) %>%
setNames(classes_from_CT$id)
length(matching_classes)
matching_classes$solid_fuels <- c(
'black_coal', 'brown_coal', 'bituminous_coal', 'coal', 'solid_fossil_fuels',
'solid_fuel', 'solids', "solid_f.", 'solid'
)
matching_classes$gaseous_fuels <- c(
'natural_gas', 'gaseous_fossil_fuels', 'gaseous', 'gaseous_fuel',
"gaseous_f.", 'gas', 'cng'
)
matching_classes$liquid_fuels <- c(
'liquid_fossil_fuels', 'liquid_f.', 'liquid', 'liquid_fuel',
'liquids', 'all_liquid_fuels'
)
matching_classes$other_liquid_fuels <- c(
'other_liquid_fuels_(please_specify)',
"(stationary)_oil" , "fuel_oil", "petroleum_coke",
'lubricants', 'oil'
)
matching_classes$other_fossil_fuels <- c(
'other_fossil_fuel', "other_f.", "other_fosssil_fuels",
"other_fossil_fuels_(please_specify)",
"other_fuels_(please_specify)", "other_fuels_(waste)",
"other_fossil" , "other_fuels", "other_(waste)" ,
'waste_incineration', 'others', 'msw', 'waste'
)
#matching_classes$aviation_gasoline <- c()
matching_classes$jet_kerosene <- c('kerosene')
matching_classes$diesel_oil <- c('diesel', 'derv')
#matching_classes$`gas/diesel_oil` <- c()
matching_classes$gasoline <- c(
'motor_gasoline', "gasoline/_lpg" #'gas',
)
matching_classes$`liquefied_petroleum_gases_(lpg)` <- c(
'lpg', "gasoline/_lpg"
)
matching_classes$residual_fuel_oil <- c(
'residual_oil'
)
matching_classes$rabbit <- c(
'rabbit', 'rabbits'
)
matching_classes$growing_cattle <- c(
'young_cattle', "non-dairy_young_cattle_(younger_than_1_year)",
"non-dairy_young_cattle_(younger_than_1_year)",
"non-dairy_young_cattle_1-2_years"
)
matching_classes$cattle <- c(
"bulls_(olther_than_2_years)",
'non-dairy_heifers_(older_than_2_years)',
"bulls_(older_than_2_years)"
)
matching_classes$reindeer <- c(
'raindeer'
)
matching_classes$`fur-bearing_animals` <- c(
'fur_animals'
)
matching_classes$swine <- c(
'sw_ine', 'swaine'
)
matching_classes$other <- c(
'other_livestock', 'other_animal'
)
matching_classes$biomass <- c(
'wood'
)
# unsure: fuels, gas, fuel oil
unlist(matching_classes)
matching_classes$indirect_emissions <- c(
'indirect'
)
# create one look up table from list ===========================================
ct_classes <- data.table('CRF_class' = names(matching_classes),
'other_names' = '',
'main_class' = names(matching_classes))
for (i in 1:length(matching_classes)) {
ct_classes[i]$other_names <- paste(matching_classes[[i]], collapse = ', ')
}
ct_classes[CRF_class %in% c('liquid_fuels', 'aviation_gasoline',
'jet_kerosene', 'diesel_oil', 'gasoline',
'gas/diesel_oil',
'liquefied_petroleum_gases_(lpg)',
'other_liquid_fuels', 'residual_fuel_oil'),
main_class := 'liquid_fuels']
ct_classes[CRF_class %in% c('cattle', 'dairy_cattle', 'growing_cattle',
'mature_dairy_cattle', 'non-dairy_cattle',
'other_cattle', 'other_mature_cattle'),
main_class := 'cattle']
#view_excel(ct_classes)
# create hierarchy ========================================
ct_classes[CRF_class == 'total_for_category', pathString := 'total_for_category']
ct_classes[CRF_class == main_class & CRF_class != 'total_for_category',
pathString := paste('total_for_category',
CRF_class,
sep = '|')]
ct_classes[CRF_class != main_class, pathString := paste('total_for_category',
main_class,
CRF_class,
sep = '|')]
# ct_classes[CRF_class== 'mature_dairy_cattle',
# pathString := 'total_for_category|cattle|dairy_cattle|mature_dairy_cattle']
# save CT tables/list ===========================================================
# saveRDS(matching_classes, file.path(path2output, paste0(filename, '_list.RData')))
# saveRDS(ct_classes, file.path(path2output, paste0(filename, '_table.RData')))
save_results(matching_classes, suffix = '_list' )
save_results(ct_classes, suffix = '_table')
log_close()
# THE END ---------------------------------------------------------------------