-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_scenario_geco_2022.R
279 lines (244 loc) · 7.74 KB
/
process_scenario_geco_2022.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
logger::log_info("GECO 2022: Setting GECO 2022 config.")
geco_2022_path <- config[["geco_2022_path"]]
geco_2022_automotive_filename <- config$geco_2022_automotive_filename
geco_2022_aviation_filename <- config$geco_2022_aviation_filename
geco_2022_fossil_fuels_15c_filename <- config$geco_2022_fossil_fuels_15c_filename
geco_2022_fossil_fuels_ndc_filename <- config$geco_2022_fossil_fuels_ndc_filename
geco_2022_fossil_fuels_ref_filename <- config$geco_2022_fossil_fuels_ref_filename
geco_2022_power_15c_filename <- config$geco_2022_power_15c_filename
geco_2022_power_ndc_filename <- config$geco_2022_power_ndc_filename
geco_2022_power_ref_filename <- config$geco_2022_power_ref_filename
geco_2022_steel_filename <- config$geco_2022_steel_filename
# set filepaths ----------------------------------------------------------------
# geco 2022 specific files
geco2022_raw_path <- fs::path(scenario_preparation_inputs_path, geco_2022_path)
# GECO only provides retirement and stocks, @Antoine-Lalechere had to manually compute the
# sales on excel
# processed data, calculation are made in:
# /Users/antoinelalechere/RMI Dropbox/Antoine Lalechere/PACTA Dropbox/Portcheck_v2/00_Data/RawScenarioData/GECO2022/processed_data/where_calculation_are_made
geco_2022_automotive_filepath <- fs::path(
geco2022_raw_path,
"processed_data",
"used_in_pacta.scenario.preparation",
geco_2022_automotive_filename
)
# processed data, calculation are made in:
#/Users/antoinelalechere/RMI Dropbox/Antoine Lalechere/PACTA Dropbox/Portcheck_v2/00_Data/RawScenarioData/GECO2022/processed_data/where_calculation_are_made
geco_2022_aviation_filepath <- fs::path(
geco2022_raw_path,
"processed_data",
"used_in_pacta.scenario.preparation",
geco_2022_aviation_filename
)
# Raw data has been sent to us via email by JRC GECO in:
# /Users/antoinelalechere/RMI Dropbox/Antoine Lalechere/PACTA Dropbox/Portcheck_v2/00_Data/RawScenarioData/GECO2022/20230213_PACTA data request_GECO data template_NDC-LTS_data_reg.xlsx
# Next file is a csv formatting of sheet "Fossil Fuel Extraction"
geco_2022_fossil_fuels_15c_filepath <- fs::path(
geco2022_raw_path,
"formatted_from_raw_data",
"used",
geco_2022_fossil_fuels_15c_filename
)
geco_2022_fossil_fuels_ndc_filepath <- fs::path(
geco2022_raw_path,
"formatted_from_raw_data",
"used",
geco_2022_fossil_fuels_ndc_filename
)
geco_2022_fossil_fuels_ref_filepath <- fs::path(
geco2022_raw_path,
"formatted_from_raw_data",
"used",
geco_2022_fossil_fuels_ref_filename
)
# Raw data has been sent to us by JRC GECO in:
# /Users/antoinelalechere/RMI Dropbox/Antoine Lalechere/PACTA Dropbox/Portcheck_v2/00_Data/RawScenarioData/GECO2022/20230213_PACTA data request_GECO data template_NDC-LTS_data_reg.xlsx
# Next file is a csv formatting of sheet "Capacity"
geco_2022_power_15c_filepath <- fs::path(
geco2022_raw_path,
"formatted_from_raw_data",
"used",
geco_2022_power_15c_filename
)
geco_2022_power_ndc_filepath <- fs::path(
geco2022_raw_path,
"formatted_from_raw_data",
"used",
geco_2022_power_ndc_filename
)
geco_2022_power_ref_filepath <- fs::path(
geco2022_raw_path,
"formatted_from_raw_data",
"used",
geco_2022_power_ref_filename
)
# Raw data related to steel come from:
# /Users/antoinelalechere/RMI Dropbox/Antoine Lalechere/PACTA Dropbox/Portcheck_v2/00_Data/RawScenarioData/GECO2022/20230213_PACTA data request_GECO data template_XXX_data_reg.xlsx
# Raw data related to power generation come from:
# /Users/antoinelalechere/RMI Dropbox/Antoine Lalechere/PACTA Dropbox/Portcheck_v2/00_Data/RawScenarioData/GECO2022/GECO2022_20221221_15C.xlsx - line 26 & 110
# Calculation are made in:
# GECO2022_Steel_processed_data.xlsx
geco_2022_steel_filepath <- fs::path(
geco2022_raw_path,
"processed_data",
"used_in_pacta.scenario.preparation",
geco_2022_steel_filename
)
logger::log_info("GECO 2022: Checking that filepaths exist.")
stopifnot(fs::file_exists(geco_2022_automotive_filepath))
stopifnot(fs::file_exists(geco_2022_aviation_filepath))
stopifnot(fs::file_exists(geco_2022_fossil_fuels_15c_filepath))
stopifnot(fs::file_exists(geco_2022_fossil_fuels_ndc_filepath))
stopifnot(fs::file_exists(geco_2022_fossil_fuels_ref_filepath))
stopifnot(fs::file_exists(geco_2022_power_15c_filepath))
stopifnot(fs::file_exists(geco_2022_power_ndc_filepath))
stopifnot(fs::file_exists(geco_2022_power_ref_filepath))
stopifnot(fs::file_exists(geco_2022_steel_filepath))
# file i/o ---------------------------------------------------------------------
logger::log_info("GECO 2022: Loading data.")
geco_2022_automotive_raw <- readr::read_csv(
geco_2022_automotive_filepath,
na = "",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Vehicle = "c",
Sector = "c",
Technology = "c",
Variable = "c",
Unit = "c",
Region = "c",
.default = "d"
)
)
geco_2022_aviation_raw <- readr::read_csv(
geco_2022_aviation_filepath,
na = "",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
`Passenger/Freight` = "c",
Technology = "c",
Unit = "c",
Region = "c",
.default = "d"
)
)
geco_2022_fossil_fuels_15c_raw <- readr::read_csv(
geco_2022_fossil_fuels_15c_filepath,
na = "",
name_repair = "unique_quiet",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
Fuel = "c",
Unit = "c",
Region = "c",
.default = "d"
)
)
geco_2022_fossil_fuels_ndc_raw <- readr::read_csv(
geco_2022_fossil_fuels_ndc_filepath,
na = "",
name_repair = "unique_quiet",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
Fuel = "c",
Unit = "c",
Region = "c",
.default = "d"
)
)
geco_2022_fossil_fuels_ref_raw <- readr::read_csv(
geco_2022_fossil_fuels_ref_filepath,
na = "",
name_repair = "unique_quiet",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
Fuel = "c",
Unit = "c",
Region = "c",
.default = "d"
)
)
geco_2022_power_15c_raw <- readr::read_csv(
geco_2022_power_15c_filepath,
na = "",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
Unit = "c",
Region = "c",
Technology = "c",
.default = "d"
)
)
geco_2022_power_ndc_raw <- readr::read_csv(
geco_2022_power_ndc_filepath,
na = "",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
Unit = "c",
Region = "c",
Technology = "c",
.default = "d"
)
)
geco_2022_power_ref_raw <- readr::read_csv(
geco_2022_power_ref_filepath,
na = "",
col_types = readr::cols(
GECO = "c",
Scenario = "c",
Variable = "c",
Unit = "c",
Region = "c",
Technology = "c",
.default = "d"
)
)
geco_2022_steel_raw <- readr::read_csv(
geco_2022_steel_filepath,
na = "",
col_types = readr::cols(
Source = "c",
Sector = "c",
Scenario = "c",
Region = "c",
.default = "d"
)
)
# prepare data -----------------------------------------------------------------
geco_2022 <- pacta.scenario.data.preparation::prepare_geco_2022_scenario(
geco_2022_automotive_raw,
geco_2022_aviation_raw,
geco_2022_fossil_fuels_15c_raw,
geco_2022_fossil_fuels_ndc_raw,
geco_2022_fossil_fuels_ref_raw,
geco_2022_power_15c_raw,
geco_2022_power_ndc_raw,
geco_2022_power_ref_raw,
geco_2022_steel_raw
)
# check output data ------------------------------------------------------------
if (pacta.data.validation::validate_intermediate_scenario_output(geco_2022)) {
logger::log_info("GECO 2022: GECO 2022 data is valid.")
output_path <- fs::path(scenario_preparation_outputs_path, "geco_2022.csv")
readr::write_csv(
x = geco_2022,
file = output_path
)
logger::log_info("GECO 2022: GECO 2022 data saved to {output_path}.")
} else {
logger::log_error("GECO 2022: GECO 2022 data is not valid.")
stop()
}