-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_scenario_weo_2023.R
126 lines (101 loc) · 3.24 KB
/
process_scenario_weo_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
logger::log_info("WEO 2023: Setting WEO 2023 config.")
weo_2023_raw_path <- config[["weo_2023_raw_path"]]
weo_2023_ext_data_regions_raw_filename <- config[["weo_2023_ext_data_regions_raw_filename"]]
weo_2023_ext_data_world_raw_filename <- config[["weo_2023_ext_data_world_raw_filename"]]
weo_2023_fig_chptr_3_raw_filename <- config[["weo_2023_fig_chptr_3_raw_filename"]]
iea_global_ev_raw_path <- config[["iea_global_ev_raw_path"]]
iea_global_ev_raw_filename <- config[["iea_global_ev_raw_filename"]]
mpp_ats_raw_path <- config[["mpp_ats_raw_path"]]
mpp_ats_raw_filename <- config[["mpp_ats_raw_filename"]]
logger::log_info("WEO 2023: Setting WEO 2023 paths.")
weo_2023_raw_full_path <-
file.path(
scenario_preparation_inputs_path,
weo_2023_raw_path
)
weo_2023_ext_data_regions_raw_full_filepath <-
file.path(
weo_2023_raw_full_path,
weo_2023_ext_data_regions_raw_filename
)
weo_2023_ext_data_world_raw_full_filepath <-
file.path(
weo_2023_raw_full_path,
weo_2023_ext_data_world_raw_filename
)
weo_2023_fig_chptr_3_raw_full_filepath <-
file.path(
weo_2023_raw_full_path,
weo_2023_fig_chptr_3_raw_filename
)
iea_global_ev_raw_full_path <-
file.path(
scenario_preparation_inputs_path,
iea_global_ev_raw_path
)
iea_global_ev_raw_full_filepath <-
file.path(
iea_global_ev_raw_full_path,
iea_global_ev_raw_filename
)
mpp_ats_raw_full_path <-
file.path(
scenario_preparation_inputs_path,
mpp_ats_raw_path
)
mpp_ats_raw_full_filepath <-
file.path(
mpp_ats_raw_full_path,
mpp_ats_raw_filename
)
logger::log_info("WEO 2023: Checking that WEO 2023 filepaths exist.")
stopifnot(fs::file_exists(weo_2023_ext_data_regions_raw_full_filepath))
stopifnot(fs::file_exists(weo_2023_ext_data_world_raw_full_filepath))
stopifnot(fs::file_exists(weo_2023_fig_chptr_3_raw_full_filepath))
stopifnot(fs::file_exists(iea_global_ev_raw_full_filepath))
stopifnot(fs::file_exists(mpp_ats_raw_full_filepath))
logger::log_info("WEO 2023: Loading WEO 2023 raw data.")
weo_2023_ext_data_regions_raw <-
readr::read_csv(
file = weo_2023_ext_data_regions_raw_full_filepath,
show_col_types = FALSE
)
weo_2023_ext_data_world_raw <-
readr::read_csv(
file = weo_2023_ext_data_world_raw_full_filepath,
show_col_types = FALSE
)
weo_2023_fig_chptr_3_raw <-
tidyxl::xlsx_cells(
path = weo_2023_fig_chptr_3_raw_full_filepath
)
iea_global_ev_raw <-
readr::read_csv(
file = iea_global_ev_raw_full_filepath,
show_col_types = FALSE
)
mpp_ats_raw <-
tidyxl::xlsx_cells(
path = mpp_ats_raw_full_filepath
)
logger::log_info("WEO 2023: Processing WEO 2023 data.")
weo_2023 <-
pacta.scenario.data.preparation::prepare_weo_2023_scenario(
weo_2023_ext_data_regions_raw,
weo_2023_ext_data_world_raw,
weo_2023_fig_chptr_3_raw,
iea_global_ev_raw,
mpp_ats_raw
)
if (pacta.data.validation::validate_intermediate_scenario_output(weo_2023)) {
logger::log_info("WEO 2023: WEO 2023 data is valid.")
output_path <- fs::path(scenario_preparation_outputs_path, "weo_2023.csv")
readr::write_csv(
x = weo_2023,
file = output_path
)
logger::log_info("WEO 2023: WEO 2023 data saved to {output_path}.")
} else {
logger::log_error("WEO 2023 data is not valid.")
stop()
}