-
Notifications
You must be signed in to change notification settings - Fork 5
/
plex_post_process.R
59 lines (43 loc) · 1.48 KB
/
plex_post_process.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
# --------------------
# Post process with R
# Author: Jack Simpson
# --------------------
rm(list = ls())
# libraries
library(tidyverse)
library(data.table)
library(furrr)
# use multicore
plan(multiprocess)
# define directories
str_base_directory <- 'results'
str_time_period <- 'Interval'
str_search <- file.path(str_base_directory, 'model_1', str_time_period)
str_regex <- 'ST Region'
list_csv <- list.files(path = str_search, pattern = str_regex)
dt_id2name <- read_csv(file.path(str_base_directory, 'model_1', 'id2name.csv'))
model_name <- dt_id2name %>%
filter(class == 'Model')
model_name <- model_name$name[1]
dt <- tibble(csvs = list_csv) %>%
mutate(filenames = file.path(str_search, csvs),
model_name = model_name) %>%
separate(model_name, c('blank','esoo_label','scenario','horizon',
'poe','refyear','model_type','outage',
'test_label'), sep='_') %>%
mutate(csvs = gsub('\\.csv','', csvs)) %>%
separate(csvs, c('class', 'metric'), sep='\\.') %>%
separate(class, c('phase', 'class'), sep=' ') %>%
mutate(id = parse_number(class),
class = gsub('\\(.*', '', class)) %>%
left_join(dt_id2name) %>%
group_by(phase, class, metric, filenames, poe, refyear, name) %>%
nest %>%
mutate(data2 = future_map(filenames, fread, .progress = TRUE)) %>%
select(-data) %>%
unnest() %>%
ungroup() %>%
select(-filenames) %>%
spread(metric, VALUE)
dt_one <- dt$data2[[1]]
str_filename <- dt$filenames[1]