Skip to content

Commit

Permalink
Add demand scenarios for CAMPAIGners
Browse files Browse the repository at this point in the history
  • Loading branch information
robinhasse committed Aug 9, 2023
1 parent e3f32f5 commit e0bc2e6
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '32750648'
ValidationKey: '32891040'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 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: 'mrremind: MadRat REMIND Input Data Package'
version: 0.167.3
date-released: '2023-08-07'
version: 0.168.0
date-released: '2023-08-09'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.167.3
Date: 2023-08-07
Version: 0.168.0
Date: 2023-08-09
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
5 changes: 4 additions & 1 deletion R/calcEDGETrData.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ calcEDGETrData <- function() {
'SSP2EU', 'NAV_ele', 'default',
'SSP2EU', 'NAV_all', 'SSP2EU_lowdem',
'SSP2EU', 'NAV_lce', 'SSP2EU_lowdem',
'SSP2EU', 'PhOP', 'default'
'SSP2EU', 'PhOP', 'default',
# DEM_Scenario has to changed once EDGE-T has new scenarios
'SSP2EU', 'CAMP_weak', 'SSP2EU_lowdem',
'SSP2EU', 'CAMP_strong', 'SSP2EU_lowdem'
)
)

Expand Down
15 changes: 8 additions & 7 deletions R/calcFEdemand.R
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ calcFEdemand <- function(subtype = "FE", use_ODYM_RECC = FALSE) {

# remove missing Navigate scenarios
if (subtype %in% c("FE_buildings", "UE_buildings")) {
reminditems <- reminditems[, , grep("SSP2EU_NAV_.{3}\\.rcp", getItems(reminditems, 3), value = TRUE), invert = TRUE]
reminditems <- reminditems[, , grep("SSP2EU_(NAV|CAMP)_[a-z]*\\.rcp", getItems(reminditems, 3), value = TRUE), invert = TRUE]
}

#Change the scenario names for consistency with REMIND sets
Expand Down Expand Up @@ -1982,18 +1982,19 @@ calcFEdemand <- function(subtype = "FE", use_ODYM_RECC = FALSE) {
description_out <- "useful energy demand in buildings"
}
if (subtype == "FE") {
# duplicate SSP2EU scenarios of industry for Navigate scenarios
# duplicate SSP2EU scenarios of industry for Navigate and Campaigners scenarios
industryItems <- grep("(.*i$)|chemicals|steel|otherInd|cement",
getItems(reminditems, 3.2), value = TRUE)
nonIndustryItems <- setdiff(getItems(reminditems, 3.2), industryItems)
navigateScenarios <- grep("SSP2EU_NAV_", getItems(reminditems, 3.1), value = TRUE)
nonNavigateScenarios <- setdiff(getItems(reminditems, 3.1), navigateScenarios)
duplScenarios <- grep("SSP2EU_(NAV|CAMP)_", getItems(reminditems, 3.1), value = TRUE)
nonDuplScenarios <- setdiff(getItems(reminditems, 3.1), duplScenarios)
reminditems <- mbind(
mselect(reminditems, scenario = nonNavigateScenarios),
mselect(reminditems, scenario = navigateScenarios, item = nonIndustryItems),
mselect(reminditems, scenario = nonDuplScenarios),
mselect(reminditems, scenario = duplScenarios, item = nonIndustryItems),
addDim(mselect(reminditems, scenario = "gdp_SSP2EU", item = industryItems,
collapseNames = TRUE),
paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
c(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
paste0("gdp_SSP2EU_CAMP_", c("weak", "strong"))),
"scenario", 3.1)
)
}
Expand Down
67 changes: 31 additions & 36 deletions R/convertEDGE.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@ convertEDGE <- function(x, subtype = "FE_stationary") {
addSSPnames <- function(x) {
do.call("mbind", lapply(c(paste0("SSP", c(1:5, "2EU", "2_lowEn")),
paste0("SDP", c("", "_EI", "_RC", "_MC")),
paste0("SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all"))),
paste0("SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
paste0("SSP2EU_CAMP_", c("weak", "strong"))),
function(s) setNames(x, paste(s, getNames(x), sep = "."))
))
}

duplScens <- function(x, scens = NULL) {
if (is.null(scens)) {
scens <- list(
gdp_SSP2EU = paste0("gdp_SSP2EU_",
c("NAV_act", "NAV_ele", "NAV_tec", "NAV_lce", "NAV_all",
"CAMP_weak", "CAMP_strong")),
gdp_SSP2 = "gdp_SSP2_lowEn"
)
}
mbind(x, do.call(mbind, lapply(names(scens), function(from) {
do.call(mbind, lapply(scens[[from]], function(to) {
setItems(x[, , from], 3, to)
}))
})))
}

renameExtraWeights <- function(magObj, magWeight, mapping) {
do.call("mbind", lapply(mapping[["EDGEitems"]], function(itemIN) {
if (itemIN %in% getNames(magObj, dim = "item")) {
Expand Down Expand Up @@ -51,7 +68,7 @@ convertEDGE <- function(x, subtype = "FE_stationary") {
rem_years_hist <- seq(1990,2150,5)
keep_years <- getYears(x)

struct_mapping_path = toolGetMapping(type = "sectoral", name = "structuremappingIO_outputs.csv",
struct_mapping_path = toolGetMapping(type = "sectoral", name = "structuremappingIO_outputs.csv",
returnPathOnly = TRUE, where = "mappingfolder")
struct_mapping = read.csv2(struct_mapping_path, na.strings = "")

Expand All @@ -70,15 +87,15 @@ convertEDGE <- function(x, subtype = "FE_stationary") {
# Load the regional mapping which depends upon the model used
if (subtype == "FE_stationary"){

mappingfile <- toolGetMapping(type = "regional", name = "regionmappingREMIND.csv",
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingREMIND.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mapping <- read.csv2(mappingfile)
region_col = which(names(mapping) == "RegionCode")
iso_col = which(names(mapping) == "CountryCode")

}else if (subtype %in% c("FE_buildings")){

mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mapping <- read.csv2(mappingfile)
region_col = which(names(mapping) == "RegionCodeEUR_ETP")
Expand All @@ -89,15 +106,8 @@ convertEDGE <- function(x, subtype = "FE_stationary") {
#--- Load the Weights
#--- First load the GDP data. Set average2020 to False to get yearly data as far as possible.
wg <- calcOutput("GDP", average2020 = FALSE, aggregate = FALSE)
# duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate scenarios
wg <- mbind(
wg,
do.call("mbind", lapply(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
function(navScen) {
setItems(wg[,, "gdp_SSP2EU"], 3, navScen)
})),
setItems(wg[,, "gdp_SSP2"], 3, "gdp_SSP2_lowEn")
)
# duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate and Campaigners scenarios
wg <- duplScens(wg)
getNames(wg) <- gsub("gdp_", "", getNames(wg))


Expand Down Expand Up @@ -258,7 +268,7 @@ convertEDGE <- function(x, subtype = "FE_stationary") {

} else if(subtype %in% c("Capital")){

mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mapping <- read.csv2(mappingfile)
region_col = which(names(mapping) == "RegionCodeEUR_ETP")
Expand Down Expand Up @@ -299,7 +309,7 @@ convertEDGE <- function(x, subtype = "FE_stationary") {

} else if(subtype %in% c("CapitalUnit")){

mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mapping <- read.csv2(mappingfile)
region_col = which(names(mapping) == "RegionCodeEUR_ETP")
Expand All @@ -313,7 +323,7 @@ convertEDGE <- function(x, subtype = "FE_stationary") {

} else if(subtype %in% c("ES_buildings")){

mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mapping <- read.csv2(mappingfile)
region_col = which(names(mapping) == "RegionCodeEUR_ETP")
Expand All @@ -322,23 +332,15 @@ convertEDGE <- function(x, subtype = "FE_stationary") {
select_years = intersect(getYears(x,as.integer = T),rem_years_hist)
wg <- calcOutput("GDP", years = select_years, aggregate = FALSE)

# duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate scenarios
wg <- mbind(
wg,
do.call("mbind", lapply(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
function(navScen) {
setItems(wg[,, "gdp_SSP2EU"], 3, navScen)
})),
setItems(wg[,, "gdp_SSP2"], 3, "gdp_SSP2_lowEn")
)

# duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate and Campaigners scenarios
wg <- duplScens(wg)
getNames(wg) = gsub("gdp_","", getNames(wg))

x = toolAggregate(x[,select_years,],mappingfile, weight = wg[,,getNames(x,dim=1)], from = region_col, to = iso_col )
result = x

} else if (subtype == "Floorspace") {
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingEDGE.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mapping <- read.csv2(mappingfile)
region_col = which(names(mapping) == "RegionCodeEUR_ETP")
Expand All @@ -348,15 +350,8 @@ convertEDGE <- function(x, subtype = "FE_stationary") {
wp <- calcOutput("Population", years = rem_years_hist, aggregate = FALSE)
getSets(wp) <- gsub("variable", "scenario", getSets(wp))
getItems(wp, "scenario") <- gsub("pop_", "gdp_", getItems(wp, "scenario"))
# duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate scenarios
wp <- mbind(
wp,
do.call("mbind", lapply(paste0("gdp_SSP2EU_NAV_", c("act", "tec", "ele", "lce", "all")),
function(navScen) {
setItems(wp[,, "gdp_SSP2EU"], 3, navScen)
})),
setItems(wp[,, "gdp_SSP2"], 3, "gdp_SSP2_lowEn")
)
# duplicate SSP2 for SSP2_lowEn an SSP2EU for Navigate and Campaigners scenarios
wp <- duplScens(wp)

x <- toolAggregate(x[, rem_years_hist, ], mappingfile, weight = wp,
from = region_col, to = iso_col )
Expand Down
4 changes: 3 additions & 1 deletion R/readEDGE.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ readEDGE <- function(subtype = c("FE_stationary", "FE_buildings", "Capital", "Ca
ver <- "1.12"
scenarios <- list(
SSPs = paste0("SSP", 1:5),
SSP2s = paste0("SSP2", c("EU", "_lowEn", paste0("EU_NAV_", c("act", "tec", "ele", "lce", "all")))),
SSP2s = paste0("SSP2", c("EU", "_lowEn",
paste0("EU_NAV_", c("act", "tec", "ele", "lce", "all")),
paste0("EU_CAMP_", c("weak", "strong")))),
SDPs = paste0("SDP", c("", "_EI", "_MC", "_RC")))

addDim <- function(x, addnm, dim, dimCode = 3.2) {
Expand Down
7 changes: 6 additions & 1 deletion R/readEDGETransport.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ readEDGETransport <- function(subtype = "logit_exponent") {
dt[.("gdp_SSP2EU_lowdem", "gdp_SSP2EU", "NAV_all"), nomatch=NULL][
, DEM_scenario := "gdp_SSP2EU_NAV_all"],
dt[.("gdp_SSP2EU_lowdem", "gdp_SSP2EU", "NAV_lce"), nomatch=NULL][
, DEM_scenario := "gdp_SSP2EU_NAV_lce"]
, DEM_scenario := "gdp_SSP2EU_NAV_lce"],
# should get redundant once EDGE-T hace additional scenarios
dt[.("gdp_SSP2EU_lowdem", "gdp_SSP2EU", "CAMP_weak"), nomatch=NULL][
, DEM_scenario := "gdp_SSP2EU_CAMP_weak"],
dt[.("gdp_SSP2EU_lowdem", "gdp_SSP2EU", "CAMP_strong"), nomatch=NULL][
, DEM_scenario := "gdp_SSP2EU_CAMP_strong"]
)
setkeyv(dt, "DEM_scenario")
dt[.("gdp_SSP2EU_lowdem"), DEM_scenario := "gdp_SSP2_lowEn"]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRat REMIND Input Data Package

R package **mrremind**, version **0.167.3**
R package **mrremind**, version **0.168.0**

[![CRAN status](https://www.r-pkg.org/badges/version/mrremind)](https://cran.r-project.org/package=mrremind) [![R build status](https://github.com/pik-piam/mrremind/workflows/check/badge.svg)](https://github.com/pik-piam/mrremind/actions) [![codecov](https://codecov.io/gh/pik-piam/mrremind/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrremind) [![r-universe](https://pik-piam.r-universe.dev/badges/mrremind)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Lavinia Baumstark <lavinia@pik-po

To cite package **mrremind** in publications use:

Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R (2023). _mrremind: MadRat REMIND Input Data Package_. R package version 0.167.3, <https://github.com/pik-piam/mrremind>.
Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R (2023). _mrremind: MadRat REMIND Input Data Package_. R package version 0.168.0, <https://github.com/pik-piam/mrremind>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrremind: MadRat REMIND Input Data Package},
author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux},
year = {2023},
note = {R package version 0.167.3},
note = {R package version 0.168.0},
url = {https://github.com/pik-piam/mrremind},
}
```

0 comments on commit e0bc2e6

Please sign in to comment.