Skip to content

Commit

Permalink
Merge pull request #509 from JakobBD/pbs
Browse files Browse the repository at this point in the history
Process-based steel implementation
  • Loading branch information
JakobBD authored Jan 22, 2024
2 parents ddcedbb + bcec2c6 commit 3f4ffde
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '222974595'
ValidationKey: '223107200'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
6 changes: 4 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'remind2: The REMIND R package (2nd generation)'
version: 1.129.5
date-released: '2024-01-19'
version: 1.130.0
date-released: '2024-01-22'
abstract: Contains the REMIND-specific routines for data and model output manipulation.
authors:
- family-names: Rodrigues
Expand All @@ -17,6 +17,8 @@ authors:
given-names: Jan Philipp
- family-names: Dirnaichner
given-names: Alois
- family-names: Duerrwaechter
given-names: Jakob
- family-names: Führlich
given-names: Pascal
- family-names: Giannousakis
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Type: Package
Package: remind2
Title: The REMIND R package (2nd generation)
Version: 1.129.5
Date: 2024-01-19
Version: 1.130.0
Date: 2024-01-22
Authors@R: c(
person("Renato", "Rodrigues", , "[email protected]", role = c("aut", "cre")),
person("Lavinia", "Baumstark", role = "aut"),
person("Falk", "Benke", role = "aut"),
person("Jan Philipp", "Dietrich", role = "aut"),
person("Alois", "Dirnaichner", role = "aut"),
person("Jakob", "Duerrwaechter", role = "aut"),
person("Pascal", "Führlich", role = "aut"),
person("Anastasis", "Giannousakis", role = "aut"),
person("Robin", "Hasse", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions R/convGDX2MIF.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ convGDX2MIF <- function(gdx, gdx_ref = NULL, file = NULL, scenario = "default",

# make the reporting
output <- NULL

message("running reportMacroEconomy...")
output <- mbind(output,reportMacroEconomy(gdx,regionSubsetList,t)[,t,])
message("running reportTrade...")
Expand Down
66 changes: 36 additions & 30 deletions R/reportCapitalStock.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#' Read in GDX and calculate capital stocks, used in convGDX2MIF.R for the reporting
#'
#'
#' Read in capital stock information from GDX file, information used in convGDX2MIF.R
#' for the reporting
#'
#'
#'
#'
#' @param gdx a GDX object as created by readGDX, or the path to a gdx
#' @param regionSubsetList a list containing regions to create report variables region
#' aggregations. If NULL (default value) only the global region aggregation "GLO" will
#' be created.
#' @param t temporal resolution of the reporting, default:
#' t=c(seq(2005,2060,5),seq(2070,2110,10),2130,2150)
#'
#'
#' @return MAgPIE object - contains the capital stock variables
#' @author Lavinia Baumstark; Michaja Pehl
#' @seealso \code{\link{convGDX2MIF}}
#' @examples
#'
#'
#' \dontrun{reportCapitalStock(gdx)}
#'
#'
#' @export
#' @importFrom gdx readGDX
#' @importFrom magclass getYears mbind setNames dimSums
Expand All @@ -28,53 +28,54 @@ reportCapitalStock <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),se
tran_mod = module2realisation[module2realisation$modules == "transport", 2]

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")
teall2rlf <- readGDX(gdx,name=c("te2rlf","teall2rlf"),format="first_found")
teue2rlf <- readGDX(gdx,name=c("teue2rlf", "tees2rlf"),format="first_found")
te <- readGDX(gdx,name=c("te"),format="first_found")
te <- readGDX(gdx,name=c("te"),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")
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')
# 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,]
v_investcost <- v_investcost[,y,]

tmp <- NULL

# ---- report transport capital stocks ----
if (tran_mod == "complex"){
LDV35 <- readGDX(gdx,name=c("LDV35"),format="first_found")
tmp <- mbind(tmp,setNames(dimSums( (vm_cap * v_investcost)[teue2rlf]
tmp <- mbind(tmp,setNames(dimSums( (vm_cap * v_investcost)[teue2rlf]
,dim=c(3.1,3.2)) * 1000, "Est Capital Stock|ESM|Transp vehic (billion US$2005)"))
tmp <- mbind(tmp,setNames(dimSums( (vm_cap * v_investcost)[teall2rlf][,,LDV35]
tmp <- mbind(tmp,setNames(dimSums( (vm_cap * v_investcost)[teall2rlf][,,LDV35]
,dim=c(3.1,3.2)) * 1000, "Est Capital Stock|ESM|Pet/EV LDV (billion US$2005)"))

tmp <- mbind(tmp,
tmp <- mbind(tmp,
setNames(
dimSums(mbind(vm_cap * v_investcost),
dim = 3) * 1000,
dimSums(mbind(vm_cap * v_investcost),
dim = 3) * 1000,
"Estimated Capital Stock|ESM (billion US$2005)"
)
)

# prepare variables
vm_cap <- vm_cap[teall2rlf]
vm_deltaCap <- vm_deltaCap[teall2rlf]

# build reporting
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,LDV35] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est LDV Stock (million vehicles)"))
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,"apCarElT"] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est EV LDV Stock (million vehicles)"))
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,"apCarH2T"] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est H2 LDV Stock (million vehicles)"))
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,"apCarPeT"] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est ICE LDV Stock (million vehicles)"))

tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,LDV35] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est LDV Sales (million vehicles)"))
tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,"apCarElT"] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est EV LDV Sales (million vehicles)"))
tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,"apCarH2T"] * pm_conv_cap_2_MioLDV,dim=c(3.1,3.2)),"Est H2 LDV Sales (million vehicles)"))
Expand All @@ -84,45 +85,50 @@ reportCapitalStock <- function(gdx,regionSubsetList=NULL,t=c(seq(2005,2060,5),se
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,"apCarDiT"] ,dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Stock|apCarDiT (NA)"))
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,"apcarDiEffT"] ,dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Stock|apcarDiEffT (NA)"))
tmp <- mbind(tmp,setNames(dimSums(vm_cap[,,"apcarDiEffH2T"] ,dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Stock|apcarDiEffH2T (NA)"))

tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,c("apCarDiT","apcarDiEffT","apcarDiEffH2T")],dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Sales|uedit (NA)"))
tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,"apCarDiT"] ,dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Sales|apCarDiT (NA)"))
tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,"apcarDiEffT"] ,dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Sales|apcarDiEffT (NA)"))
tmp <- mbind(tmp,setNames(dimSums(vm_deltaCap[,,"apcarDiEffH2T"] ,dim=c(3.1,3.2)), "Services and Products|Transport|non-LDV|Sales|apcarDiEffH2T (NA)"))


## add global values
tmp <- mbind(tmp,dimSums(tmp,dim=1))
}

# ---- report industry energy efficiency capital stocks ----
if (!is.null(ppfKap_Ind) & 0 < length(ppfKap_Ind)) {
mixer <- tribble(
~pf, ~name,
'kap_cement', 'Cement',
'kap_chemicals', 'Chemicals',
'kap_steel_primary', 'Primary Steel',
'kap_steel_secondary', 'Secondary Steel',
'kap_otherInd', 'other')


if (!steel_process_based) {
mixer <- bind_rows(mixer, tribble(
~pf, ~name,
'kap_steel_primary', 'Primary Steel',
'kap_steel_secondary', 'Secondary Steel'))
}

if (0 != length(setdiff(ppfKap_Ind, mixer$pf))) {
warning(paste('Unknown ppfKap_industry_dyn37 entity.',
'Adjust remind2::reportCapitalStock()'))
}

if (0 != length(setdiff(mixer$pf, ppfKap_Ind))) {
warning(paste('Missing ppfKap_industry_dyn37 entity.',
'Adjust remind2::reportCapitalStock()'))
}
}

eek_Ind <- setNames(vm_cesIO[,y,ppfKap_Ind],
paste0('Capital|Energy Efficiency|Industry|',
paste0('Capital|Energy Efficiency|Industry|',
mixer[mixer$pf %in% ppfKap_Ind,][['name']],
' (billion US$2005)'))
# add industry EEK and global totals
tmp <- mbind(tmp, mbind(eek_Ind, dimSums(eek_Ind, dim = 1)))
}

# ---- add region aggregates ----
if (!is.null(regionSubsetList))
tmp <- mbind(tmp, calc_regionSubset_sums(tmp, regionSubsetList))
Expand Down
10 changes: 7 additions & 3 deletions R/reportEmi.R
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ if (!is.null(vm_plasticsCarbon)) {
`getSets<-`(fulldim = FALSE, value = getSets(out)),

# process emissions for cement subsector
readGDX(gdx, 'vm_macBaseInd', field = 'l', restore_zeros = FALSE) %>%
readGDX(gdx, c('vm_emiIndBase', 'vm_macBaseInd'), field = 'l', restore_zeros = FALSE) %>%
`[`(,,'co2cement_process.cement') %>%
`*`(as.numeric(GtC_2_MtCO2)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)) %>%
Expand Down Expand Up @@ -953,8 +953,12 @@ if (!is.null(vm_plasticsCarbon)) {
as.magpie(spatial = 2, temporal = 1, datacol = ncol(.)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)),

# process emissions
readGDX(gdx, 'vm_macBaseInd', field = 'l', restore_zeros = FALSE) %>%
out)

# process emissions
emiIndBase <- readGDX(gdx, c('vm_emiIndBase', 'vm_macBaseInd'), field = 'l', restore_zeros = FALSE)
out <- mbind(
emiIndBase %>%
`[`(,,'co2cement_process.cement') %>%
`*`(as.numeric(GtC_2_MtCO2)) %>%
`getSets<-`(fulldim = FALSE, value = getSets(out)) %>%
Expand Down
Loading

0 comments on commit 3f4ffde

Please sign in to comment.