Skip to content

Commit

Permalink
handle differing years in modifyInvestmentVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Oct 21, 2024
1 parent 5c91508 commit 3b87243
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/convGDX2MIF_LCOE.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ convGDX2MIF_LCOE <- function(gdx, gdx_ref, file = NULL, scenario = "default",
t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) {
# make the reporting
output <- NULL
output <- mbind(output, reportLCOE(gdx = gdx, gdx_ref = gdx_ref)[, t, ],)
output <- mbind(output, reportLCOE(gdx = gdx, gdx_ref = gdx_ref)[, t, ])

# write the LCOE.mif or give back the magpie object output
if (!is.null(file)) {
Expand Down
5 changes: 2 additions & 3 deletions R/modifyInvestmentVariables.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ modifyInvestmentVariables <- function(x, ref = NULL, startYear = NULL) {
x <- (x + tmp) / 2

if (!is.null(ref)) {
fixedYears <- getYears(x)[getYears(x, as.integer = TRUE) < startYear]

joinedYears <- intersect(getYears(x, as.integer = TRUE), getYears(ref, as.integer = TRUE))
fixedYears <- joinedYears[joinedYears < startYear]
if (length(fixedYears) == 0) {
return(x)
}

ref <- modifyInvestmentVariables(ref)
joinedNames <- intersect(getNames(x), getNames(ref))
joinedRegions <- intersect(getItems(ref, dim = 1), getItems(x, dim = 1))
Expand Down
10 changes: 6 additions & 4 deletions R/reportCapacity.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ reportCapacity <- function(gdx, regionSubsetList = NULL,

# data preparation
ttot <- as.numeric(as.vector(ttot))
vm_cap <- vm_cap[teall2rlf]
vm_cap <- vm_cap[, ttot, ]
vm_cap <- vm_cap[teall2rlf]
vm_cap <- vm_cap[, ttot, ]

vm_deltaCap <- vm_deltaCap[teall2rlf]
vm_deltaCap <- vm_deltaCap[, ttot, ]

if (!is.null(gdx_ref)) {
cm_startyear <- as.integer(readGDX(gdx, name = "cm_startyear", format = "simplest"))
vm_deltaCapRef <- readGDX(gdx_ref, name = c("vm_deltaCap"), field = "l", format = "first_found") * 1000
vm_deltaCap <- modifyInvestmentVariables(vm_deltaCap, vm_deltaCapRef, gdx_ref)
vm_deltaCapRef <- vm_deltaCapRef[teall2rlf]
vm_deltaCapRef <- vm_deltaCapRef[, ttot, ]
vm_deltaCap <- modifyInvestmentVariables(vm_deltaCap, vm_deltaCapRef, cm_startyear)
} else {
vm_deltaCap <- modifyInvestmentVariables(vm_deltaCap)
}
Expand Down Expand Up @@ -168,7 +171,6 @@ reportCapacity <- function(gdx, regionSubsetList = NULL,
if ("dac" %in% magclass::getNames(vm_cap, dim = 1)) {
tmp <- mbind(tmp, setNames(dimSums(vm_cap[, , c("dac")], dim = 3) * sm_c_2_co2, "Cap|Carbon Management|DAC (Mt CO2/yr)"))
}

# Newly built capacities electricity (Should all go into tmp2, so that this can be used for calculating cumulated values in tmp5 below)
tmp2 <- NULL
tmp2 <- mbind(tmp2, setNames(dimSums(vm_deltaCap[, , c("ngcc", "ngt", "gaschp", "ngccc")], dim = 3), "New Cap|Electricity|Gas (GW/yr)"))
Expand Down
4 changes: 2 additions & 2 deletions R/reportEnergyInvestment.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL,
v_adjustteinv_ref <- readGDX(gdx_ref, name = c("v_costInvTeAdj", "vm_costInvTeAdj", "v_adjustteinv"),
field = "l", format = "first_found")
cm_startyear <- as.integer(readGDX(gdx, name = "cm_startyear", format = "simplest"))
v_directteinv <- modifyInvestmentVariables(v_directteinv[, ttot, ], v_directteinv_ref, cm_startyear)
v_adjustteinv <- modifyInvestmentVariables(v_adjustteinv[, ttot, ], v_adjustteinv_ref, cm_startyear)
v_directteinv <- modifyInvestmentVariables(v_directteinv[, ttot, ], v_directteinv_ref[, ttot, ], cm_startyear)
v_adjustteinv <- modifyInvestmentVariables(v_adjustteinv[, ttot, ], v_adjustteinv_ref[, ttot, ], cm_startyear)
} else {
v_directteinv <- modifyInvestmentVariables(v_directteinv[, ttot, ])
v_adjustteinv <- modifyInvestmentVariables(v_adjustteinv[, ttot, ])
Expand Down
6 changes: 5 additions & 1 deletion man/modifyInvestmentVariables.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b87243

Please sign in to comment.