-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_scenario_geco_2023.R
220 lines (181 loc) · 5.18 KB
/
process_scenario_geco_2023.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
logger::log_info("GECO 2023: Setting GECO 2023 config.")
geco_2023_raw_path <- config[["geco_2023_raw_path"]]
geco_2023_15c_raw_filename <- config[["geco_2023_15c_raw_filename"]]
geco_2023_ndc_raw_filename <- config[["geco_2023_ndc_raw_filename"]]
geco_2023_ref_raw_filename <- config[["geco_2023_ref_raw_filename"]]
geco_2023_supplement_path <- config[["geco_2023_supplement_path"]]
geco_2023_supplement_15c_raw_filename <- config[["geco_2023_supplement_15c_raw_filename"]]
geco_2023_supplement_ndc_raw_filename <- config[["geco_2023_supplement_ndc_raw_filename"]]
geco_2023_supplement_ref_raw_filename <- config[["geco_2023_supplement_ref_raw_filename"]]
logger::log_info("GECO 2023: Setting GECO 2023 paths.")
geco_2023_raw_full_path <-
file.path(
scenario_preparation_inputs_path,
geco_2023_raw_path
)
geco_2023_15c_raw_filepath <-
file.path(
geco_2023_raw_full_path,
geco_2023_15c_raw_filename
)
geco_2023_ndc_raw_filepath <-
file.path(
geco_2023_raw_full_path,
geco_2023_ndc_raw_filename
)
geco_2023_ref_raw_filepath <-
file.path(
geco_2023_raw_full_path,
geco_2023_ref_raw_filename
)
geco_2023_supplement_full_path <-
file.path(
scenario_preparation_inputs_path,
geco_2023_supplement_path
)
geco_2023_supplement_15c_raw_filepath <-
file.path(
geco_2023_supplement_full_path,
geco_2023_supplement_15c_raw_filename
)
geco_2023_supplement_ndc_raw_filepath <-
file.path(
geco_2023_supplement_full_path,
geco_2023_supplement_ndc_raw_filename
)
geco_2023_supplement_ref_raw_filepath <-
file.path(
geco_2023_supplement_full_path,
geco_2023_supplement_ref_raw_filename
)
logger::log_info("GECO 2023: Checking that GECO 2023 filepaths exist.")
stopifnot(fs::file_exists(geco_2023_15c_raw_filepath))
stopifnot(fs::file_exists(geco_2023_ndc_raw_filepath))
stopifnot(fs::file_exists(geco_2023_ref_raw_filepath))
stopifnot(fs::file_exists(geco_2023_supplement_15c_raw_filepath))
stopifnot(fs::file_exists(geco_2023_supplement_ndc_raw_filepath))
stopifnot(fs::file_exists(geco_2023_supplement_ref_raw_filepath))
logger::log_info("GECO 2023: Loading GECO 2023 raw data.")
geco_2023_aviation_15c_raw <-
readxl::read_xlsx(
path = geco_2023_15c_raw_filepath,
na = "",
sheet = "Aviation"
)
geco_2023_aviation_ndc_raw <-
readxl::read_xlsx(
path = geco_2023_ndc_raw_filepath,
na = "",
sheet = "Aviation"
)
geco_2023_aviation_ref_raw <-
readxl::read_xlsx(
path = geco_2023_ref_raw_filepath,
na = "",
sheet = "Aviation"
)
geco_2023_fossil_fuels_15c_raw <-
readxl::read_xlsx(
path = geco_2023_15c_raw_filepath,
na = "",
sheet = "Fossil Fuel Extraction"
)
geco_2023_fossil_fuels_ndc_raw <-
readxl::read_xlsx(
path = geco_2023_ndc_raw_filepath,
na = "",
sheet = "Fossil Fuel Extraction"
)
geco_2023_fossil_fuels_ref_raw <-
readxl::read_xlsx(
path = geco_2023_ref_raw_filepath,
na = "",
sheet = "Fossil Fuel Extraction"
)
geco_2023_power_cap_15c_raw <-
readxl::read_xlsx(
path = geco_2023_15c_raw_filepath,
na = "",
sheet = "Capacity"
)
geco_2023_power_cap_ndc_raw <-
readxl::read_xlsx(
path = geco_2023_ndc_raw_filepath,
na = "",
sheet = "Capacity"
)
geco_2023_power_cap_ref_raw <-
readxl::read_xlsx(
path = geco_2023_ref_raw_filepath,
na = "",
sheet = "Capacity"
)
geco_2023_steel_15c_raw <-
readxl::read_xlsx(
path = geco_2023_15c_raw_filepath,
na = "",
sheet = "Steel"
)
geco_2023_steel_ndc_raw <-
readxl::read_xlsx(
path = geco_2023_ndc_raw_filepath,
na = "",
sheet = "Steel"
)
geco_2023_steel_ref_raw <-
readxl::read_xlsx(
path = geco_2023_ref_raw_filepath,
na = "",
sheet = "Steel"
)
geco_2023_supplement_15c_raw <-
readxl::read_xlsx(
path = geco_2023_supplement_15c_raw_filepath,
na = "",
sheet = "World",
range = "A3:J109"
)
geco_2023_supplement_ndc_raw <-
readxl::read_xlsx(
path = geco_2023_supplement_ndc_raw_filepath,
na = "",
sheet = "World",
range = "A3:J109"
)
geco_2023_supplement_ref_raw <-
readxl::read_xlsx(
path = geco_2023_supplement_ref_raw_filepath,
na = "",
sheet = "World",
range = "A3:J109"
)
logger::log_info("GECO 2023: Processing GECO 2023 data.")
geco_2023 <- pacta.scenario.data.preparation::prepare_geco_2023_scenario(
geco_2023_aviation_15c_raw,
geco_2023_aviation_ndc_raw,
geco_2023_aviation_ref_raw,
geco_2023_fossil_fuels_15c_raw,
geco_2023_fossil_fuels_ndc_raw,
geco_2023_fossil_fuels_ref_raw,
geco_2023_power_cap_15c_raw,
geco_2023_power_cap_ndc_raw,
geco_2023_power_cap_ref_raw,
geco_2023_steel_15c_raw,
geco_2023_steel_ndc_raw,
geco_2023_steel_ref_raw,
geco_2023_supplement_15c_raw,
geco_2023_supplement_ndc_raw,
geco_2023_supplement_ref_raw
)
if (pacta.data.validation::validate_intermediate_scenario_output(geco_2023)) {
logger::log_info("GECO 2023: GECO 2023 data is valid.")
output_path <- fs::path(scenario_preparation_outputs_path, "geco_2023.csv")
readr::write_csv(
x = geco_2023,
file = output_path
)
logger::log_info("GECO 2023: GECO 2023 data saved to {output_path}.")
} else {
logger::log_error("GECO 2023 data is not valid.")
stop()
}