Skip to content

Commit

Permalink
modify investment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Oct 7, 2024
1 parent cc809ab commit 40e7b36
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions R/modifyInvestmentVariables.R
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 2 additions & 3 deletions R/plotLCOE.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) %>%
Expand Down
1 change: 1 addition & 0 deletions R/reportCapacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
15 changes: 8 additions & 7 deletions R/reportCapitalStock.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions R/reportEnergyInvestment.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ 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")

# read parameters for additional calculations:
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) {
Expand Down
16 changes: 13 additions & 3 deletions R/reportLCOE.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 40e7b36

Please sign in to comment.