Skip to content

Commit

Permalink
improve plotting script
Browse files Browse the repository at this point in the history
  • Loading branch information
cchrisgong committed Sep 2, 2022
1 parent d15151b commit fc101d2
Show file tree
Hide file tree
Showing 9 changed files with 1,330 additions and 345 deletions.
276 changes: 192 additions & 84 deletions scripts/output/single/DIETER/DIETERValidationPlots.R

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions scripts/output/single/DIETER/plotCapAndCF.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (length(dieter.files) != 0) {

remind.peak.demand <- file.path(outputdir, remind.files[i]) %>%
read.gdx("p32_peakDemand", factor = FALSE) %>%
filter(ttot %in% model.periods) %>%
filter(ttot %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
select(period=ttot,value) %>%
mutate(value = value * 1e3) %>%
Expand All @@ -31,7 +31,7 @@ out.remind.capacity <- NULL

remind.capacity <- file.path(outputdir, remind.files[i]) %>%
read.gdx("vm_cap", factors = FALSE, squeeze = FALSE) %>%
filter(tall %in% model.periods) %>%
filter(tall %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
filter(rlf == "1") %>%
filter(all_te %in% names(remind.tech.mapping.narrow)) %>%
Expand Down Expand Up @@ -70,7 +70,7 @@ if (length(dieter.files) != 0) {
dieter.cap.data <- file.path(outputdir, dieter.files[i]) %>%
read.gdx("p32_report4RM", factor = FALSE, squeeze = FALSE) %>%
select(period = X..1, tech = X..3, variable=X..4, value) %>%
filter(period %in% model.periods) %>%
filter(period %in% model.periods.from2020) %>%
filter(tech %in% names(dieter.tech.mapping)) %>%
filter(!tech %in% names(dieter.storage.mapping)) %>%
filter(variable %in% c("capacity")) %>%
Expand All @@ -81,7 +81,7 @@ if (length(dieter.files) != 0) {
dieter.sto.cap.data <- file.path(outputdir, dieter.files[i]) %>%
read.gdx("p32_report4RM", factor = FALSE, squeeze = FALSE) %>%
select(period = X..1, tech = X..3, variable=X..4, value) %>%
filter(period %in% model.periods) %>%
filter(period %in% model.periods.from2020) %>%
filter(tech %in% names(dieter.storage.mapping)) %>%
filter(variable %in% c("sto_P_capacity")) %>%
revalue.levels(tech = dieter.storage.mapping) %>%
Expand Down Expand Up @@ -237,7 +237,7 @@ swlatex(sw, "\\subsection{Capacities last iteration - double bar plot}")


plot.remind.capacity <- out.remind.capacity %>%
filter(period %in% model.periods.till2100) %>%
filter(period %in% model.periods.from2020.till2100) %>%
filter(iteration == max(out.remind.capacity$iteration)) %>%
select(period,tech,value) %>%
filter(!tech %in% dieter.storage.mapping)%>%
Expand All @@ -248,7 +248,7 @@ swlatex(sw, "\\subsection{Capacities last iteration - double bar plot}")
mutate(period = as.numeric(period))%>%
filter(iteration == max(out.remind.capacity$iteration)) %>%
select(period,tech,value) %>%
filter(period %in% model.periods.till2100) %>%
filter(period %in% model.periods.from2020.till2100) %>%
filter(tech %in% dieter.storage.mapping)

plot.dieter.capacity.h2stor2 <- plot.dieter.capacity.stor %>%
Expand All @@ -263,15 +263,15 @@ swlatex(sw, "\\subsection{Capacities last iteration - double bar plot}")


plot.remind.capacity.wDIETERstorage <- plot.remind.capacity.wDIETERstorage %>%
mutate(tech = factor(tech, levels=rev(unique(c(dieter.tech.mapping,"Hydrogen Turbine","Electrolyzers for long-term storage"))))) %>%
mutate(tech = factor(tech, levels=rev(unique(c("Hydrogen Turbine", dieter.tech.mapping,"Electrolyzers for long-term storage"))))) %>%
mutate(model="REMIND")

plot.remind.capacity.wDIETERstorage2 <- plot.remind.capacity.wDIETERstorage %>%
mutate(period = as.numeric(as.character(period)) - 1)

plot.dieter.capacity <- out.dieter.capacity %>%
mutate(period = as.numeric(as.character(period))) %>%
filter(period %in% model.periods.till2100) %>%
filter(period %in% model.periods.from2020.till2100) %>%
filter(iteration == max(out.dieter.capacity$iteration)) %>%
select(-iteration) %>%
full_join(plot.dieter.capacity.h2stor2)%>%
Expand Down Expand Up @@ -351,7 +351,7 @@ if (save_png == 1){
if (length(dieter.files) != 0) {
swlatex(sw, paste0("\\section{Capacity factors}"))

for(year_toplot in model.periods){
for(year_toplot in model.periods.from2020){
plot.remind.capfac <- out.remind.capfac %>%
filter(period == year_toplot)

Expand Down
25 changes: 21 additions & 4 deletions scripts/output/single/DIETER/plotConvergence.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ diff.price <- out.RMprice %>%
filter(period %in% model.periods) %>%
filter(!value == 0) %>%
select(period,iteration,rmprice=value) %>%
left_join(out.DTprice) %>%
left_join(out.DTprice_wscar) %>%
filter(period %in% model.periods.till2100) %>%
select(period,iteration,rmprice, value) %>%
mutate(value = rmprice - value) %>%
Expand All @@ -223,20 +223,37 @@ if (save_png == 1){

swlatex(sw, paste0("\\subsection{Electricity price difference over iterations (with rolling mean REMIND price over 3 periods)}"))

# price in REMIND compared to no_scar price in DIETER
diff.price.rollmean <- out.RMprice %>%
filter(period %in% model.periods) %>%
filter(!value == 0) %>%
select(period,iteration,rmprice=value) %>%
dplyr::group_by(iteration) %>%
mutate( rmprice = frollmean(rmprice, 3, align = "left", fill = 0)) %>%
dplyr::ungroup(iteration) %>%
left_join(out.DTprice) %>%
left_join(out.DTprice_wscar) %>%
filter(period %in% model.periods.till2100) %>%
select(period,iteration,rmprice, value) %>%
mutate(value = rmprice - value) %>%
select(-rmprice)%>%
select(-rmprice) %>%
filter(iteration > start_i-1)

# # price in REMIND plus cap shad price compared to full price in DIETER (improve later: also need to add capacity shadow price for standing capacities in dieter)
#
# diff.price.rollmean <- out.RMprice_wSP %>%
# filter(period %in% model.periods) %>%
# filter(!value == 0) %>%
# select(period,iteration,rmprice=value) %>%
# # dplyr::group_by(iteration) %>%
# # mutate( rmprice = frollmean(rmprice, 3, align = "left", fill = 0)) %>%
# # dplyr::ungroup(iteration) %>%
# left_join(out.DTprice_wscar) %>%
# filter(period %in% model.periods.till2100) %>%
# select(period,iteration,rmprice, value) %>%
# mutate(value = rmprice - value) %>%
# select(-rmprice) %>%
# filter(iteration > start_i-1)

p <- ggplot() +
geom_line(data = diff.price.rollmean, aes(x = iteration, y = value,), size = 1.2, alpha = 0.5) +
theme(axis.text=element_text(size=20), axis.title=element_text(size= 20,face="bold")) +
Expand Down Expand Up @@ -357,7 +374,7 @@ if (save_png == 1){
}

##################################################################################################
for (tech_plot in c("OCGT", "Wind Onshore", "Solar")){
for (tech_plot in c("OCGT", "Wind onshore", "Solar")){

swlatex(sw, paste0("\\subsection{Markup and Market value for ", tech_plot, " over iterations}"))
# tech_plot = "CCGT"
Expand Down
25 changes: 12 additions & 13 deletions scripts/output/single/DIETER/plotGeneration.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for (i in 1:length(remind.files)) {
# usable energy for VRE (excluding curtailment)
vmUsableSeTe <- file.path(outputdir, remind.files[i]) %>%
read.gdx("vm_usableSeTe", factors = FALSE, squeeze = FALSE) %>%
filter(ttot %in% model.periods) %>%
filter(ttot %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
filter(entySe == "seel") %>%
filter(all_te %in% names(remind.vre.mapping)) %>%
Expand All @@ -26,7 +26,7 @@ for (i in 1:length(remind.files)) {
# for non-VRE
vmprodSe <- file.path(outputdir, remind.files[i]) %>%
read.gdx("vm_prodSe", factors = FALSE, squeeze = FALSE) %>%
filter(tall %in% model.periods) %>%
filter(tall %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
filter(all_enty.1 == "seel") %>%
filter(all_te %in% names(remind.nonvre.mapping.whyd)) %>%
Expand All @@ -43,7 +43,7 @@ for (i in 1:length(remind.files)) {

generation.withCurt<- file.path(outputdir, remind.files[i]) %>%
read.gdx("vm_prodSe", factors = FALSE, squeeze = FALSE) %>%
filter(tall %in% model.periods) %>%
filter(tall %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
filter(all_te %in% names(remind.tech.mapping)) %>%
filter(all_enty.1 == "seel") %>%
Expand All @@ -68,7 +68,7 @@ for (i in 2:length(remind.files)) {
read.gdx("p32_seh2elh2Dem",
factors = FALSE,
squeeze = FALSE) %>%
filter(ttot %in% model.periods) %>%
filter(ttot %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
mutate(value = value * sm_TWa_2_MWh / 1e6) %>%
select(period = ttot, h2dem = value)
Expand All @@ -77,7 +77,7 @@ for (i in 2:length(remind.files)) {
read.gdx("p32_usableSeDisp",
factors = FALSE,
squeeze = FALSE) %>%
filter(ttot %in% model.periods) %>%
filter(ttot %in% model.periods.from2020) %>%
filter(all_regi == reg) %>%
mutate(value = value * sm_TWa_2_MWh / 1e6) %>%
mutate(tech="seel") %>%
Expand All @@ -104,19 +104,19 @@ remind.consumption <- remind.consumption %>%
mutate(tech = fct_relevel(tech, table_ordered_name_dem))

generation.withCurt.disp <- remind.generation.withCurt %>%
filter(!tech %in% c("Solar", "Wind Onshore", "Wind Offshore")) %>%
filter(!tech %in% c("Solar", "Wind onshore", "Wind offshore")) %>%
dplyr::group_by(period, iteration) %>%
dplyr::summarise( disp = sum(value) , .groups = 'keep' ) %>%
dplyr::ungroup(period, iteration)

generation.withCurt.wind <- remind.generation.withCurt %>%
filter(tech %in% c("Wind Onshore")) %>%
filter(tech %in% c("Wind onshore")) %>%
left_join(generation.withCurt.disp) %>%
mutate(value = value + disp) %>%
select(iteration,period,tech,value)

generation.withCurt.vre <- remind.generation.withCurt %>%
filter(tech %in% c("Solar","Wind Offshore")) %>%
filter(tech %in% c("Solar","Wind offshore")) %>%
select(iteration,period,tech,value)%>%
full_join(generation.withCurt.wind)

Expand Down Expand Up @@ -168,19 +168,19 @@ dieter.gen.wCurt.sum <- out.dieter %>%
dplyr::ungroup(period, iteration)

dieter.gen.wCurt.disp <- dieter.gen.wCurt %>%
filter(!tech %in% c("Solar", "Wind Onshore", "Wind Offshore")) %>%
filter(!tech %in% c("Solar", "Wind onshore", "Wind offshore")) %>%
dplyr::group_by(period, iteration) %>%
dplyr::summarise( disp = sum(value) , .groups = 'keep' ) %>%
dplyr::ungroup(period, iteration)

dieter.gen.wCurt.wind <- dieter.gen.wCurt %>%
filter(tech %in% c("Wind Onshore")) %>%
filter(tech %in% c("Wind onshore")) %>%
left_join(dieter.gen.wCurt.disp) %>%
mutate(value = value +disp) %>%
select(iteration,period,tech,value)

dieter.gen.wCurt.vre <- dieter.gen.wCurt %>%
filter(tech %in% c("Wind Offshore","Solar")) %>%
filter(tech %in% c("Wind offshore","Solar")) %>%
select(iteration,period,tech,value)%>%
full_join(dieter.gen.wCurt.wind)

Expand All @@ -191,7 +191,7 @@ dieter.gen.wCurt <- dieter.gen.wCurt.vre

swlatex(sw, paste0("\\section{Generation}"))

for (year_toplot in model.periods) {
for (year_toplot in model.periods.from2020) {

plot.remind.generation <- out.remind.generation %>%
filter(period == year_toplot)
Expand Down Expand Up @@ -484,7 +484,6 @@ if (h2switch == "on"){
alpha = 0.5
)


p.genwConsump2 <- p.genwConsump2 + geom_area(
data = plot.remind.consumption%>% filter(period %in% model.periods.till2100)%>% mutate(value = -value),
aes(x = period, y = value, fill = tech),
Expand Down
Loading

0 comments on commit fc101d2

Please sign in to comment.