Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply shift in investment variables #662

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 52 additions & 36 deletions R/reportEnergyInvestment.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#' @importFrom magclass mbind
#' @importFrom gdx readGDX

reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) {
reportEnergyInvestment <- function(gdx, regionSubsetList = NULL,
t = c(seq(2005, 2060, 5), seq(2070, 2110, 10), 2130, 2150)) {
# read sets
te <- readGDX(gdx, "te", format = "first_found")
adjte <- readGDX(gdx, name = c("teAdj", "adjte"), format = "first_found")
petyf <- readGDX(gdx, c("peFos", "petyf"), format = "first_found")
perenew <- readGDX(gdx, c("peRe", "perenew"), format = "first_found")
Expand All @@ -36,7 +36,8 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
tenoccs <- readGDX(gdx, name = c("teNoCCS", "tenoccs"), format = "first_found")
sety <- readGDX(gdx, c("entySe", "sety"), format = "first_found")

# the set liquids changed from sepet+sedie to seLiq in REMIND 1.7. Seliq, sega and seso changed to include biomass or Fossil origin after REMIND 2.0
# the set liquids changed from sepet+sedie to seLiq in REMIND 1.7. Seliq, sega
# and seso changed to include biomass or Fossil origin after REMIND 2.0
se_Liq <- intersect(c("seliqfos", "seliqbio", "seliqsyn", "seliq", "sepet", "sedie"), sety)
se_Gas <- intersect(c("segafos", "segabio", "segasyn", "sega"), sety)
se_Solids <- intersect(c("sesofos", "sesobio", "seso"), sety)
Expand All @@ -52,8 +53,10 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
pebio <- readGDX(gdx, c("peBio", "pebio"), format = "first_found")
ttot <- readGDX(gdx, name = "ttot", format = "first_found")
# read variables
v_directteinv <- readGDX(gdx, name = c("v_costInvTeDir", "vm_costInvTeDir", "v_directteinv"), field = "l", format = "first_found")
v_adjustteinv <- readGDX(gdx, name = c("v_costInvTeAdj", "vm_costInvTeAdj", "v_adjustteinv"), field = "l", format = "first_found")
v_directteinv <- readGDX(gdx, name = c("v_costInvTeDir", "vm_costInvTeDir", "v_directteinv"),
field = "l", format = "first_found")
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")
Expand All @@ -70,20 +73,31 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
inv_se <- function(ie, oe, settofilter = pe2se, adjte, v_directteinv, v_adjustteinv, te = pe2se$all_te) {
if (!is.character(settofilter)) {
if (attr(settofilter, which = "gdxdata")$name %in% c("pe2se", "se2fe", "se2se", "temapall", "en2en")) {
sub1_pe2se <- settofilter[((settofilter$all_enty %in% ie) & (settofilter$all_enty1 %in% oe) & (settofilter$all_te %in% te) & !(settofilter$all_te %in% adjte)), ]

sub2_pe2se <- settofilter[((settofilter$all_enty %in% ie) & (settofilter$all_enty1 %in% oe) & (settofilter$all_te %in% te) & (settofilter$all_te %in% adjte)), ]
sub1_pe2se <- settofilter[((settofilter$all_enty %in% ie) &
(settofilter$all_enty1 %in% oe) &
(settofilter$all_te %in% te) &
!(settofilter$all_te %in% adjte)), ]

sub2_pe2se <- settofilter[((settofilter$all_enty %in% ie) &
(settofilter$all_enty1 %in% oe) &
(settofilter$all_te %in% te) &
(settofilter$all_te %in% adjte)), ]

x1 <- dimSums(v_directteinv[, , sub1_pe2se$all_te], dim = 3) * 1000
x2 <- dimSums(v_directteinv[, , sub2_pe2se$all_te] + v_adjustteinv[, , sub2_pe2se$all_te], dim = 3) * 1000

x2 <- dimSums(v_directteinv[, , sub2_pe2se$all_te] +
v_adjustteinv[, , sub2_pe2se$all_te], dim = 3) * 1000
}
} else {
sub1_pe2se <- settofilter[((settofilter %in% te) & !(settofilter %in% adjte))]

sub2_pe2se <- settofilter[((settofilter %in% te) & (settofilter %in% adjte))]

x1 <- dimSums(v_directteinv[, , sub1_pe2se], dim = 3) * 1000

x2 <- dimSums(v_directteinv[, , sub2_pe2se] + v_adjustteinv[, , sub2_pe2se], dim = 3) * 1000
}
if (is.magpie(x1) & is.magpie(x2)) {
if (is.magpie(x1) && is.magpie(x2)) {
out <- (x1 + x2)
} else if (is.magpie(x1)) {
out <- x1
Expand Down Expand Up @@ -116,16 +130,20 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
tmp <- mbind(tmp, setNames(inv_se(ie = "peur", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Electricity|+|Nuclear (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pesol", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Electricity|+|Solar (billion US$2017/yr)"))

windonStr <- ifelse ("windon" %in% all_te, "windon", "wind")
windonStr <- ifelse("windon" %in% all_te, "windon", "wind")
tmp <- mbind(tmp, setNames(inv_se(ie = "pewin", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv, te = windonStr), "Energy Investments|Electricity|Wind|+|Onshore (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pewin", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv, te = "windoff"), "Energy Investments|Electricity|Wind|+|Offshore (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pewin", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv, te = "windoff"), "Energy Investments|Electricity|Wind|+|Offshore (billion US$2017/yr)"))

tmp <- mbind(tmp, setNames(inv_se(ie = "pewin", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Electricity|+|Wind (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pehyd", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Electricity|+|Hydro (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pegeo", oe = "seel", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Electricity|+|Geothermal (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = NULL, oe = NULL, stor, adjte, v_directteinv, v_adjustteinv, te = all_te), "Energy Investments|Electricity|+|Storage (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = NULL, oe = NULL, c("tdels", "tdelt", grid), adjte, v_directteinv, v_adjustteinv, te = all_te), "Energy Investments|Electricity|+|Grid (billion US$2017/yr)"))
# split out the amount of "normal" grid, the additional grid/charger investments due to electric vehicles, and the additional grid investments needed for better pooling of VRE. For BEVs, the assumption is to only take the share of tdelt costs that are higher than the tdels costs

# split out the amount of "normal" grid, the additional grid/charger investments due to electric vehicles,
# and the additional grid investments needed for better pooling of VRE. For BEVs, the assumption is to only
# take the share of tdelt costs that are higher than the tdels costs

tmp <- mbind(tmp, setNames(inv_se(ie = NULL, oe = NULL, c("tdelt"), adjte, v_directteinv, v_adjustteinv, te = all_te) * (costRatioTdelt2Tdels - 1) / costRatioTdelt2Tdels, "Energy Investments|Electricity|Grid|+|BEV Chargers (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = NULL, oe = NULL, c("tdels"), adjte, v_directteinv, v_adjustteinv, te = all_te)
+ inv_se(ie = NULL, oe = NULL, c("tdelt"), adjte, v_directteinv, v_adjustteinv, te = all_te) * 1 / costRatioTdelt2Tdels, "Energy Investments|Electricity|Grid|+|Normal (billion US$2017/yr)"))
Expand All @@ -143,17 +161,15 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
+ inv_se(ie = "seel", oe = "seh2", se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te)
+ inv_se(ie = "seh2", oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te), "Energy Investments|Hydrogen (billion US$2017/yr)"))


tmp <- mbind(tmp, setNames(inv_se(ie = pe2se$all_enty, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|PE (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seel", oe = "seh2", se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te), "Energy Investments|Hydrogen|se2se (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seh2", oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te), "Energy Investments|Hydrogen|se2fe (billion US$2017/yr)"))


tmp <- mbind(tmp, setNames(inv_se(ie = petyf, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|+|Fossil (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = perenew, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|+|RE (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|Bio (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seel", oe = "seh2", se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te), "Energy Investments|Hydrogen|+|Electrolysis (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seh2", oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te), "Energy Investments|Hydrogen|+|Transmission and Distribution (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = petyf, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|+|Fossil (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = perenew, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|+|RE (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, oe = "seh2", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Hydrogen|Bio (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seel", oe = "seh2", se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te), "Energy Investments|Hydrogen|+|Electrolysis (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seh2", oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te), "Energy Investments|Hydrogen|+|Transmission and Distribution (billion US$2017/yr)"))

# Liquids
tmp <- mbind(tmp, setNames((inv_se(ie = pe2se$all_enty, oe = se_Liq, pe2se, adjte, v_directteinv, v_adjustteinv)
Expand All @@ -173,30 +189,29 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
tmp <- mbind(tmp, setNames(v_directteinv[, , "dac"] + v_adjustteinv[, , "dac"], "Energy Investments|DAC (billion US$2017/yr)") * 1000)
tmp <- mbind(tmp, setNames(dimSums(v_directteinv[, , teue2rlf$all_te] + v_adjustteinv[, , teue2rlf$all_te], dim = 3), "Energy Investments|Demand (billion US$2017/yr)") * 1000)
tmp <- mbind(tmp, setNames((inv_se(ie = temapall$all_enty, oe = temapall$all_enty1, temapall[!(temapall$all_te %in% teue2rlf$all_te), ], adjte, v_directteinv, v_adjustteinv, te = all_te)
+ inv_se(ie = NULL, oe = NULL, tenotransform, adjte, v_directteinv, v_adjustteinv, te = all_te)), "Energy Investments|Supply (billion US$2017/yr)"))
+ inv_se(ie = NULL, oe = NULL, tenotransform, adjte, v_directteinv, v_adjustteinv, te = all_te)), "Energy Investments|Supply (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames((inv_se(ie = pe2se$all_enty, oe = se_Solids, pe2se, adjte, v_directteinv, v_adjustteinv)
+ inv_se(ie = se_Solids, oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te)), "Energy Investments|Solids (billion US$2017/yr)"))
+ inv_se(ie = se_Solids, oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te)), "Energy Investments|Solids (billion US$2017/yr)"))


# Gases
tmp <- mbind(tmp, setNames((inv_se(ie = pe2se$all_enty, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv)
+ inv_se(ie = se2se$all_enty, oe = se_Gas, se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te)
+ inv_se(ie = se_Gas, oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te)), "Energy Investments|Gases (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = petyf, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|+|Fossil (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seh2", oe = se_Gas, se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te), "Energy Investments|Gases|+|Hydrogen (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|+|Biomass (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, te = teccs, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|Biomass|+|w/ CC (billion US$2017/yr)"))
+ inv_se(ie = se_Gas, oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te)), "Energy Investments|Gases (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = petyf, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|+|Fossil (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "seh2", oe = se_Gas, se2se, adjte, v_directteinv, v_adjustteinv, te = se2se$all_te), "Energy Investments|Gases|+|Hydrogen (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|+|Biomass (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, te = teccs, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|Biomass|+|w/ CC (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, te = tenoccs, oe = se_Gas, pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Gases|Biomass|+|w/o CC (billion US$2017/yr)"))
# tmp <- mbind(tmp, setNames(inv_se(ie = NULL, oe = NULL, c("tdbiogas","tdfosgas","tdsyngas","tdbiogat","tdfosgat","tdsyngat"), adjte, v_directteinv, v_adjustteinv, te = all_te), "Energy Investments|Gases|Grid (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = se_Gas, oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te), "Energy Investments|Gases|+|Transmission and Distribution (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = se_Gas, oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te), "Energy Investments|Gases|+|Transmission and Distribution (billion US$2017/yr)"))

tmp <- mbind(tmp, setNames((inv_se(ie = pe2se$all_enty, oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv)
+ inv_se(ie = "sehe", oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te)), "Energy Investments|Heat (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pegeo", oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Heat Pump (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pegas", oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Gas (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pecoal", oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Coal (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = petyf, oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|Fossil (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Biomass (billion US$2017/yr)"))
+ inv_se(ie = "sehe", oe = se2fe$all_enty1, se2fe, adjte, v_directteinv, v_adjustteinv, te = se2fe$all_te)), "Energy Investments|Heat (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pegeo", oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Heat Pump (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pegas", oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Gas (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = "pecoal", oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Coal (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = petyf, oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|Fossil (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = pebio, oe = "sehe", pe2se, adjte, v_directteinv, v_adjustteinv), "Energy Investments|Heat|+|Biomass (billion US$2017/yr)"))
tmp <- mbind(tmp, setNames(inv_se(ie = NULL, oe = NULL, c("tdhes"), adjte, v_directteinv, v_adjustteinv, te = all_te), "Energy Investments|Heat|+|Grid (billion US$2017/yr)"))

tmp <- mbind(tmp, setNames((tmp[, , "Energy Investments|Supply (billion US$2017/yr)"]
Expand All @@ -206,7 +221,8 @@ reportEnergyInvestment <- function(gdx, regionSubsetList = NULL, t = c(seq(2005,
- tmp[, , "Energy Investments|Heat (billion US$2017/yr)"]
- tmp[, , "Energy Investments|Gases (billion US$2017/yr)"]
- tmp[, , "Energy Investments|Solids (billion US$2017/yr)"]
- tmp[, , "Energy Investments|CO2 Trans&Stor (billion US$2017/yr)"]), "Energy Investments|Other (billion US$2017/yr)"))
- tmp[, , "Energy Investments|CO2 Trans&Stor (billion US$2017/yr)"]),
"Energy Investments|Other (billion US$2017/yr)"))


# add global values
Expand Down
Loading
Loading