Skip to content

Commit

Permalink
sort production factors in heat map of calibration script
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed May 13, 2024
1 parent cc0ddda commit 788a741
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions scripts/output/single/notebook_templates/cesCalibrationReport.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ if (!file.exists(file.path(params$outputdir, params$cal))) {
## Line Plots

```{r load data}
gdx <- file.path(params$outputdir, params$gdx)
ces <- read.table(file.path(params$outputdir, params$cal), header = TRUE, sep = ",", quote = "\"") %>%
as.data.frame()
Expand Down Expand Up @@ -96,7 +95,7 @@ df <- left_join(target_period_items, ces, by = c("pf", "t")) %>%
) %>%
group_by(t, regi, variable, pf) %>%
filter(abs((value[iteration == "target"] - value[iteration == last_iteration]) /
value[iteration == "target"]) > threshold) %>%
value[iteration == "target"]) > threshold) %>%
ungroup() %>%
filter(.data$value > eps) %>%
select("regi", "pf", "t") %>%
Expand Down Expand Up @@ -277,8 +276,8 @@ for (s in levels(ces$scenario)) {
```{r heat maps}
ces <- read_csv(file = file.path(params$outputdir, params$cal), show_col_types = FALSE, comment = "#") %>%
mutate(iteration = gsub(".E+00", "",
gsub(".E+01", "0", iteration, fixed = TRUE),
fixed = TRUE
gsub(".E+01", "0", iteration, fixed = TRUE),
fixed = TRUE
))
# remove duplicated data (due to a bug in REMIND)
Expand All @@ -299,6 +298,22 @@ target_pf <- ces %>%
periods <- unique(pmax(2005, pmin(2100, ces$t)))
pf_order <- read_lines(file = file.path(params$outputdir, params$cal), n_max = 1)
if (grepl("^# pf order:", pf_order)) {
pf_order <- pf_order %>%
sub("^# pf order: ", "", .) %>%
strsplit(", ") %>%
unlist()
} else {
pf_order <- d %>%
pull("pf") %>%
unique()
}
ces <- ces %>%
order.levels(pf = pf_order)
if (is.null(params$lastiteration)) {
last_iteration <- ces %>%
distinct(iteration) %>%
Expand Down Expand Up @@ -336,7 +351,7 @@ for (r in sort(unique(ces$regi))) {
levels = c("0", "< 5 %", "5-15 %", "> 15 %")
)
)
p <- ggplot(data = df) +
geom_rect(mapping = aes(
xmin = 0, xmax = 1, ymin = 0, ymax = 1,
Expand Down Expand Up @@ -373,9 +388,9 @@ for (r in sort(unique(ces$regi))) {
panel.spacing = unit(0, "npc"),
strip.text.y.left = element_text(angle = 0)
)
plot(p)
df <- ces %>%
filter(
iteration %in% c("origin", "target"),
Expand All @@ -388,7 +403,7 @@ for (r in sort(unique(ces$regi))) {
x = t - last_iteration / 2 + 1 / 2,
xend = t + last_iteration / 2 - 1 / 2
)
p <- ggplot() +
geom_segment(
data = df,
Expand Down Expand Up @@ -425,9 +440,9 @@ for (r in sort(unique(ces$regi))) {
labs(x = NULL, y = NULL, subtitle = paste(r, "quantity evolution")) +
theme_minimal() +
theme(axis.text = element_text(size = rel(0.5)))
plot(p)
df_seg <- ces %>%
filter(
"origin" == iteration,
Expand All @@ -440,7 +455,7 @@ for (r in sort(unique(ces$regi))) {
x = t - last_iteration / 2 + 1 / 2,
xend = t + last_iteration / 2 - 1 / 2
)
df_line <- ces %>%
filter(
iteration %in% 1:10,
Expand All @@ -452,7 +467,7 @@ for (r in sort(unique(ces$regi))) {
mutate(
x = t + as.integer(iteration) - (last_iteration + 1) / 2
)
p <- ggplot() +
geom_segment(
data = df_seg,
Expand All @@ -478,8 +493,7 @@ for (r in sort(unique(ces$regi))) {
labs(x = NULL, y = NULL, subtitle = paste(r, "price evolution")) +
theme_minimal() +
theme(axis.text = element_text(size = rel(0.5)))
plot(p)
}
```

0 comments on commit 788a741

Please sign in to comment.