From a574dc7ece1331e7683371f45d93ffd784a16269 Mon Sep 17 00:00:00 2001 From: Johannes Koch Date: Mon, 11 Nov 2024 15:12:05 +0100 Subject: [PATCH] Change ADB scenarios Harmonize past with future instead of the otherway around. (ADB projections now appear as-is in the scenarios.) --- R/calcDriver.R | 1 + R/readADB.R | 4 ++++ R/toolGetScenarioDefinition.R | 2 +- R/toolHarmonizeGDP.R | 10 +++++----- R/toolHarmonizePop.R | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/R/calcDriver.R b/R/calcDriver.R index 4513a6c..2d888c5 100644 --- a/R/calcDriver.R +++ b/R/calcDriver.R @@ -179,6 +179,7 @@ calcHarmonizedData <- function(driver, scenario) { "pastAndGrowth" = toolHarmonizePast(past, future, method = "growth"), "pastAndTransition" = toolHarmonizePast(past, future, method = "transition", yEnd = 2100), "PopSSPs" = toolHarmonizeWithPEAPandFuture(past, future), + "PopADBs" = toolHarmonizePopulationADBs(past, future), "PopISIMIP" = toolHarmonizePast(past, future, method = "transition", yEnd = 2030), "GDPpcSSPs" = toolHarmonizeGDPpcSSPs(past, future, yEnd = 2100), "GDPpcSDPs" = toolBuildGDPpcSDPs(), diff --git a/R/readADB.R b/R/readADB.R index afdbef9..de9e8be 100644 --- a/R/readADB.R +++ b/R/readADB.R @@ -36,6 +36,10 @@ readADB <- function() { #' @param x MAgPIE object returned from readADB #' @param subtype A string, either "all", "gdppc", "pop" convertADB <- function(x, subtype = "all") { + if (!subtype %in% c("all", "gdppc", "pop")) { + stop("Bad input for readADB. Invalid 'subtype' argument. Available subtypes are 'all', 'gdppc', and 'pop'.") + } + # Filter for subtype in the convert Function to use common read cache if (subtype == "gdppc") { x <- mselect(x, diff --git a/R/toolGetScenarioDefinition.R b/R/toolGetScenarioDefinition.R index 63dccf4..c1f2b75 100644 --- a/R/toolGetScenarioDefinition.R +++ b/R/toolGetScenarioDefinition.R @@ -53,7 +53,7 @@ toolGetScenarioDefinition <- function(driver = NULL, scen = NULL, aslist = FALSE "Population", "SSP2EU", "WDI-UN_PopDiv-MI", "SSP2EU-UN_PopDiv", "PopSSPs", "Population", "SDPs", "WDI-UN_PopDiv-MI", "SDPs-UN_PopDiv", "PopSSPs", "Population", "ISIMIP", "UN_PopDiv-MI", "SSPs-UN_PopDiv", "PopISIMIP", - "Population", "ADBs", "WDI-UN_PopDiv-MI", "ADBs-SSP2-UN_PopDiv", "PopSSPs", + "Population", "ADBs", "WDI-UN_PopDiv-MI", "ADBs-SSP2-UN_PopDiv", "PopADBs", # Labour Scenarios "Labour", "SSPs", "WDI-UN_PopDiv", "SSPs-UN_PopDiv", "pastAndLevel", "Labour", "SSP2", "WDI-UN_PopDiv", "SSP2-UN_PopDiv", "pastAndLevel", diff --git a/R/toolHarmonizeGDP.R b/R/toolHarmonizeGDP.R index 2ac19bc..135bb26 100644 --- a/R/toolHarmonizeGDP.R +++ b/R/toolHarmonizeGDP.R @@ -131,13 +131,13 @@ toolDivideGDPbyPop <- function(scenario) { toolHarmonizeGDPpcADBs <- function(past, future) { ssp2Data <- calcOutput("GDPpc", scenario = "SSP2", extension2150 = "none", average2020 = FALSE, aggregate = FALSE) - # For ADBs: transition IND from past to future by 2030 - dataIND <- toolHarmonizePast(past, future, method = "transition", yEnd = 2030) - - combined <- purrr::map(getNames(dataIND$x), function(x) { + # For both ADB scenarios, overwrite SSP2 IND data with ADB IND data + combined <- purrr::map(getNames(future$x), function(x) { y <- setNames(ssp2Data, x) y["IND", , ] <- 0 - y["IND", getYears(dataIND$x), ] <- dataIND$x["IND", , x] + # Transition IND from past to future. Here keep future as is, and use growth rates from past. + dataIND <- toolHarmonizeFuture(past$x["IND", , ], future$x["IND", , x], method = "growth") + y["IND", getYears(dataIND), ] <- dataIND y }) %>% mbind() diff --git a/R/toolHarmonizePop.R b/R/toolHarmonizePop.R index 1d8d11b..68a1a53 100644 --- a/R/toolHarmonizePop.R +++ b/R/toolHarmonizePop.R @@ -22,6 +22,26 @@ toolHarmonizeWithPEAPandFuture <- function(past, future) { and growth rates from {future$description} thereafter.")) } +toolHarmonizePopulationADBs <- function(past, future) { + ssp2Data <- calcOutput("Population", scenario = "SSP2", extension2150 = "none", aggregate = FALSE) + + # For both ADB scenarios, overwrite SSP2 IND data with ADB IND data + combined <- purrr::map(getNames(future$x), function(x) { + y <- setNames(ssp2Data, x) + y["IND", , ] <- 0 + # Transition IND from past to future. Here keep future as is, and use growth rates from past. + dataIND <- toolHarmonizeFuture(past$x["IND", , ], future$x["IND", , x], method = "growth") + y["IND", getYears(dataIND), ] <- dataIND + y + }) %>% + mbind() + + list(x = combined, + description = glue("equal to SSP2 in all countries except for IND. \\ + For IND use {past$description} until {max(getYears(past$x, as.integer = TRUE))}, \\ + and converge to {future$description} by 2030.")) +} + toolHarmonizeLabourADBs <- function() { pop2 <- calcOutput("Population", scenario = "SSP2", naming = "scenario", extension2150 = "none", aggregate = FALSE) lab2 <- calcOutput("Labour", scenario = "SSP2", naming = "scenario", extension2150 = "none", aggregate = FALSE)