Skip to content

Commit

Permalink
remove subtype ES from calcFEdemand
Browse files Browse the repository at this point in the history
  • Loading branch information
fbenke-pik committed Jan 5, 2024
1 parent 4a31751 commit b1dc5a1
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 187 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export(readUSGS)
export(readindustry_subsectors_specific)
export(readvanRuijven2016)
export(readworldsteel)
export(toolAggregateTimeSteps)
export(toolBiomassSupplyAggregate)
export(toolCubicFunctionAggregate)
export(toolCubicFunctionDisaggregate)
Expand Down
38 changes: 16 additions & 22 deletions R/calcFEdemand.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Returns the Edge data at the Remind level
#'
#' @param subtype Final energy (FE) or Energy service (ES) or Useful/Final
#' @param subtype Final energy (FE) or Useful/Final
#' Energy items from EDGEv3 corresponding to REMIND FE items (UE_for_Eff,
#' FE_for_Eff)
#' @param use_ODYM_RECC per-capita pathways for `SDP_xx` scenarios? (Defaults
Expand All @@ -29,7 +29,7 @@
#' @author Michaja Pehl, Robin Hasse, Falk Benke
calcFEdemand <- function(subtype, use_ODYM_RECC = FALSE) {

if (!subtype %in% c("FE", "ES", "FE_for_Eff", "UE_for_Eff")) {
if (!subtype %in% c("FE", "FE_for_Eff", "UE_for_Eff")) {
stop(paste0("Unsupported subtype: ", subtype ))
}

Expand All @@ -38,9 +38,9 @@ calcFEdemand <- function(subtype, use_ODYM_RECC = FALSE) {
getNames(mag, dim = "scenario")
}

addDim <- function(x, addnm, dim, dimCode = 3.2) {
do.call("mbind", lapply(addnm, function(item) {
add_dimension(x, dim = dimCode, add = dim, nm = item)
addDimensions <- function(x, dimVals, dimName, dimCode = 3.2) {
do.call("mbind", lapply(dimVals, function(item) {
add_dimension(x, dim = dimCode, add = dimName, nm = item)
}))
}

Expand Down Expand Up @@ -479,16 +479,9 @@ calcFEdemand <- function(subtype, use_ODYM_RECC = FALSE) {
}
}

} else if (subtype == "ES"){
Unit2Million = 1e-6

services <- readSource("EDGE",subtype="ES_buildings")
getSets(services) <- gsub("data", "item", getSets(services))
data <- services*Unit2Million
unit_out = "million square meters times degree [1e6.m2.C]"
description_out = "demand pathways for energy service in buildings"
}

# SAME FOR ALL ----

mapping = toolGetMapping(type = "sectoral", name = "structuremappingIO_outputs.csv", where = "mappingfolder")

Expand All @@ -503,9 +496,6 @@ calcFEdemand <- function(subtype, use_ODYM_RECC = FALSE) {
mutate(REMINDitems_out = "feelb")
)


#----- PROCESS DATA ------------------

regions <- getRegions(data)
years <- getYears(data)
scenarios <- getScens(data)
Expand Down Expand Up @@ -567,6 +557,8 @@ calcFEdemand <- function(subtype, use_ODYM_RECC = FALSE) {
getNames(reminditems) <- gsub("^SSP","gdp_SSP",getNames(reminditems))
getNames(reminditems) <- gsub("SDP","gdp_SDP",getNames(reminditems))

# FE only ----

if ('FE' == subtype) {

# ---- _modify SSP1/SSP2 data of CHN/IND further ----
Expand Down Expand Up @@ -1881,19 +1873,21 @@ calcFEdemand <- function(subtype, use_ODYM_RECC = FALSE) {
reminditems <- mbind(
mselect(reminditems, scenario = nonDuplScenarios),
mselect(reminditems, scenario = duplScenarios, item = nonIndustryItems),
addDim(mselect(reminditems, scenario = "gdp_SSP2EU", item = industryItems,
collapseNames = TRUE),
c(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
paste0("gdp_SSP2EU_CAMP_", c("weak", "strong"))),
"scenario", 3.1)
addDimensions(x = mselect(reminditems, scenario = "gdp_SSP2EU", item = industryItems,
collapseNames = TRUE),
dimVals = c(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
paste0("gdp_SSP2EU_CAMP_", c("weak", "strong"))),
dimName = "scenario",
dimCode = 3.1)
)
}

# SAME FOR ALL ----

structure_data <- switch(subtype,
FE = "^gdp_(SSP[1-5].*|SDP.*)\\.(fe|ue)",
FE_for_Eff = "^gdp_(SSP[1-5]|SDP).*\\.fe.*(b|s)$",
UE_for_Eff = "^gdp_(SSP[1-5]|SDP).*\\.fe.*(b|s)$",
ES = "^gdp_(SSP[1-5]|SDP).*\\.esswb$",
"^gdp_(SSP[1-5].*|SDP.*)\\.fe..s\\.ue.*b\\.te_ue.*b$")

return(list(x=reminditems,weight=NULL,
Expand Down
8 changes: 5 additions & 3 deletions R/calcFeDemandBuildings.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ calcFeDemandBuildings <- function(subtype) {
# change item names back from UE to FE
if (subtype == "UE") {
getItems(remind, "item") <- gsub("^ue", "fe", getItems(remind, "item"))
description <- "useful energy demand in buildings"
} else {
description <- "demand pathways for final energy in buildings and industry in the original file"
}

description <- switch(subtype,
FE = "demand pathways for final energy in buildings and industry in the original file",
UE = "useful energy demand in buildings"
)

outputStructure <- switch(subtype,
FE = "^gdp_(SSP[1-5]|SDP).*\\..*\\.fe.*b$",
UE = "^gdp_(SSP[1-5]|SDP).*\\..*\\.fe.*b$"
Expand Down
Loading

0 comments on commit b1dc5a1

Please sign in to comment.