From 40e7b36118c0696b2c64b725f74920603eb9d305 Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Mon, 7 Oct 2024 15:12:49 +0200 Subject: [PATCH] modify investment variables --- NAMESPACE | 3 --- R/modifyInvestmentVariables.R | 19 +++++++++++++++++++ R/plotLCOE.R | 5 ++--- R/reportCapacity.R | 1 + R/reportCapitalStock.R | 15 ++++++++------- R/reportEnergyInvestment.R | 10 +++++++--- R/reportLCOE.R | 16 +++++++++++++--- 7 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 R/modifyInvestmentVariables.R diff --git a/NAMESPACE b/NAMESPACE index 8dcf8a57..81929c83 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -136,7 +136,6 @@ importFrom(ggplot2,ggtitle) importFrom(ggplot2,labs) importFrom(ggplot2,scale_color_manual) importFrom(ggplot2,scale_fill_brewer) -importFrom(ggplot2,scale_fill_discrete) importFrom(ggplot2,scale_fill_manual) importFrom(ggplot2,scale_linetype_identity) importFrom(ggplot2,scale_x_continuous) @@ -148,7 +147,6 @@ importFrom(ggplot2,theme) importFrom(ggplot2,theme_bw) importFrom(ggplot2,theme_minimal) importFrom(ggplot2,unit) -importFrom(ggplot2,xlab) importFrom(gms,getLine) importFrom(gms,readDefaultConfig) importFrom(lucode2,getScenNames) @@ -222,7 +220,6 @@ importFrom(quitte,overwrite) importFrom(quitte,read.gdx) importFrom(quitte,read.quitte) importFrom(quitte,revalue.levels) -importFrom(quitte,sum_total) importFrom(readr,read_csv) importFrom(readr,write_rds) importFrom(remulator,calc_supplycurve) diff --git a/R/modifyInvestmentVariables.R b/R/modifyInvestmentVariables.R new file mode 100644 index 00000000..aa2a1df7 --- /dev/null +++ b/R/modifyInvestmentVariables.R @@ -0,0 +1,19 @@ +#' Modify Investment Variables +#' +#' a helper to adapt investment variables in reporting after changes in https://github.com/remindmodel/remind/pull/1238 +#' +#' calculates the value of each timestep for a given maglcass object +#' as the average of this timestep and the next timestep (last timestep remains unchanged) +#' +#' +#' @author Falk Benke +modifyInvestmentVariables <- function(x) { + # obtain 't+1' + idx <- c(tail(getYears(x, as.integer = TRUE), -1), tail(getYears(x, as.integer = TRUE), 1)) + # retrieve values for 't+1' and assign to 't' + tmp <- x[, idx, ] + getItems(tmp, dim = 2) <- getItems(x, dim = 2) + # calculate average of 't' and 't'+1 + out <- (x + tmp) / 2 + return(out) +} diff --git a/R/plotLCOE.R b/R/plotLCOE.R index e7e5b1c5..80890b1d 100644 --- a/R/plotLCOE.R +++ b/R/plotLCOE.R @@ -34,7 +34,6 @@ plotLCOE <- function(LCOEfile, gdx, y = c(2015, 2020, 2030, 2040, 2050, 2060), variable <- NULL value <- NULL type <- NULL - vm_deltaCap <- NULL LCOE <- NULL all_te <- NULL output <- NULL @@ -117,8 +116,8 @@ plotLCOE <- function(LCOEfile, gdx, y = c(2015, 2020, 2030, 2040, 2050, 2060), ### end plot settings # read in capacity additions from .mif, for second y axes of plot - vm_deltaCap <- readGDX(gdx, "vm_deltaCap", field = "l", restore_zeros = FALSE) - + vm_deltaCap <- readGDX(gdx, "vm_deltaCap", field = "l", restore_zeros = FALSE) %>% + modifyInvestmentVariables() # calculate 15-year moving average capacity additions df.dC <- as.quitte(dimSums(vm_deltaCap, dim = 3.2) * 1e3) %>% diff --git a/R/reportCapacity.R b/R/reportCapacity.R index b2c159c1..c1519561 100644 --- a/R/reportCapacity.R +++ b/R/reportCapacity.R @@ -50,6 +50,7 @@ reportCapacity <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5 vm_cap <- vm_cap[, ttot, ] vm_deltaCap <- vm_deltaCap[teall2rlf] vm_deltaCap <- vm_deltaCap[, ttot, ] + vm_deltaCap <- modifyInvestmentVariables(vm_deltaCap) v_earlyreti <- v_earlyreti[, ttot, ] t2005 <- ttot[ttot > 2004] diff --git a/R/reportCapitalStock.R b/R/reportCapitalStock.R index 53ffa1ba..b7d9cccc 100644 --- a/R/reportCapitalStock.R +++ b/R/reportCapitalStock.R @@ -31,21 +31,22 @@ reportCapitalStock <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 206 pm_conv_cap_2_MioLDV <- 650 # The world has ~715million cars in 2005 (IEA TECO2) # read sets - teall2rlf <- readGDX(gdx, name = c("te2rlf", "teall2rlf"), format = "first_found") - teue2rlf <- readGDX(gdx, name = c("teue2rlf", "tees2rlf"), format = "first_found") + teall2rlf <- readGDX(gdx, name = c("te2rlf", "teall2rlf"), format = "first_found") + teue2rlf <- readGDX(gdx, name = c("teue2rlf", "tees2rlf"), format = "first_found") # read variables - vm_cap <- readGDX(gdx, name = c("vm_cap"), field = "l", format = "first_found") - vm_deltaCap <- readGDX(gdx, name = c("vm_deltaCap"), field = "l", format = "first_found") + vm_cap <- readGDX(gdx, name = c("vm_cap"), field = "l", format = "first_found") + vm_deltaCap <- readGDX(gdx, name = c("vm_deltaCap"), field = "l", format = "first_found") + vm_deltaCap <- modifyInvestmentVariables(vm_deltaCap) v_investcost <- readGDX(gdx, name = c("vm_costTeCapital", "v_costTeCapital", "v_investcost"), field = "l", format = "first_found") - vm_cesIO <- readGDX(gdx, name = "vm_cesIO", field = "l") + vm_cesIO <- readGDX(gdx, name = "vm_cesIO", field = "l") # read parameters ppfKap_Ind <- readGDX(gdx, name = "ppfkap_industry_dyn37", react = "silent") steel_process_based <- "steel" %in% readGDX(gdx, "secInd37Prc", react = "silent") # calculate maximal temporal resolution y <- Reduce(intersect, list(getYears(vm_cap), getYears(v_investcost))) - vm_cap <- vm_cap[, y, ] - vm_deltaCap <- vm_deltaCap[, y, ] + vm_cap <- vm_cap[, y, ] + vm_deltaCap <- vm_deltaCap[, y, ] v_investcost <- v_investcost[, y, ] tmp <- NULL diff --git a/R/reportEnergyInvestment.R b/R/reportEnergyInvestment.R index 5cff9225..840d4f91 100644 --- a/R/reportEnergyInvestment.R +++ b/R/reportEnergyInvestment.R @@ -52,9 +52,13 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, grid <- readGDX(gdx, name = c("teGrid", "grid"), format = "first_found") pebio <- readGDX(gdx, c("peBio", "pebio"), format = "first_found") ttot <- readGDX(gdx, name = "ttot", format = "first_found") + # read variables + + # investment cost per technology v_directteinv <- readGDX(gdx, name = c("v_costInvTeDir", "vm_costInvTeDir", "v_directteinv"), field = "l", format = "first_found") + # adjustment cost per technology v_adjustteinv <- readGDX(gdx, name = c("v_costInvTeAdj", "vm_costInvTeAdj", "v_adjustteinv"), field = "l", format = "first_found") @@ -62,12 +66,12 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, pm_data <- readGDX(gdx, c("pm_data"), format = "first_found") # data preparation + ttot <- as.numeric(as.vector(readGDX(gdx, "ttot", format = "first_found"))) - v_directteinv <- v_directteinv[, ttot, ] - v_adjustteinv <- v_adjustteinv[, ttot, ] + v_directteinv <- modifyInvestmentVariables(v_directteinv[, ttot, ]) + v_adjustteinv <- modifyInvestmentVariables(v_adjustteinv[, ttot, ]) costRatioTdelt2Tdels <- pm_data[, , "inco0.tdelt"] / pm_data[, , "inco0.tdels"] - ####### internal function for reporting ########### ## "ie" stands for input energy, "oe" for output energy inv_se <- function(ie, oe, settofilter = pe2se, adjte, v_directteinv, v_adjustteinv, te = pe2se$all_te) { diff --git a/R/reportLCOE.R b/R/reportLCOE.R index d1d2d1ea..71bbb680 100644 --- a/R/reportLCOE.R +++ b/R/reportLCOE.R @@ -138,9 +138,19 @@ reportLCOE <- function(gdx, output.type = "both") { pm_SEPrice <- readGDX(gdx, "pm_SEPrice", restore_zeros = FALSE) ## variables - vm_costInvTeDir <- readGDX(gdx, name = c("vm_costInvTeDir", "v_costInvTeDir", "v_directteinv"), field = "l", format = "first_found")[, ttot, ] ## Total direct Investment Cost in Timestep - vm_costInvTeAdj <- readGDX(gdx, name = c("vm_costInvTeAdj", "v_costInvTeAdj"), field = "l", format = "first_found")[, ttot, ] ## total adjustment cost in period - vm_deltaCap <- readGDX(gdx, name = c("vm_deltaCap"), field = "l", format = "first_found")[, ttot, ] + + ## Total direct Investment Cost in Timestep + vm_costInvTeDir <- readGDX(gdx, name = c("vm_costInvTeDir", "v_costInvTeDir", "v_directteinv"), field = "l", format = "first_found")[, ttot, ] + vm_costInvTeDir <- modifyInvestmentVariables(vm_costInvTeDir) + + ## total adjustment cost in period + vm_costInvTeAdj <- readGDX(gdx, name = c("vm_costInvTeAdj", "v_costInvTeAdj"), field = "l", format = "first_found")[, ttot, ] + vm_costInvTeAdj <- modifyInvestmentVariables(vm_costInvTeAdj) + + # capacity additions per year + vm_deltaCap <- readGDX(gdx, name = c("vm_deltaCap"), field = "l", format = "first_found")[, ttot, ] + vm_deltaCap <- modifyInvestmentVariables(vm_deltaCap) + vm_demPe <- readGDX(gdx, name = c("vm_demPe", "v_pedem"), field = "l", restore_zeros = FALSE, format = "first_found") v_investcost <- readGDX(gdx, name = c("vm_costTeCapital", "v_costTeCapital", "v_investcost"), field = "l", format = "first_found")[, ttot, ] vm_cap <- readGDX(gdx, name = c("vm_cap"), field = "l", format = "first_found")