Skip to content

Commit

Permalink
Merge pull request #100 from johanneskoch94/main
Browse files Browse the repository at this point in the history
Adjust ADB scenarios and fix pm_shPPPMER.cs4r
  • Loading branch information
johanneskoch94 authored Nov 13, 2024
2 parents a045211 + 21ef4dc commit 6454aa5
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '8053668'
ValidationKey: '8076120'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: 'mrdrivers: Create GDP and Population Scenarios'
version: 4.0.2
date-released: '2024-11-07'
version: 4.0.3
date-released: '2024-11-13'
abstract: Create GDP and population scenarios This package constructs the GDP and
population scenarios used as drivers in both the REMIND and MAgPIE models.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mrdrivers
Type: Package
Title: Create GDP and Population Scenarios
Version: 4.0.2
Version: 4.0.3
Authors@R: c(person(given = "Johannes",
family = "Koch",
email = "[email protected]",
Expand Down Expand Up @@ -44,6 +44,6 @@ Suggests:
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Date: 2024-11-07
Date: 2024-11-13
Config/testthat/edition: 3
VignetteBuilder: knitr
1 change: 1 addition & 0 deletions R/calcDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 3 additions & 0 deletions R/calcRatioPPP2MER.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ calcRatioPPP2MER <- function(when = 2017) {
data <- readSource("WDI", "PA.NUS.PPPC.RF")[, when, ]
# Replace 0s with 1s. This was done previously. Other solutions here should be taken into consideration.
data[data == 0] <- 1
# Set names and years to NULL, for GAMS interface to work.
getNames(data) <- NULL
getYears(data) <- NULL

weight <- calcOutput("GDPPast", aggregate = FALSE, years = when)

Expand Down
4 changes: 4 additions & 0 deletions R/readADB.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/toolGetScenarioDefinition.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions R/toolHarmonizeGDP.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 20 additions & 0 deletions R/toolHarmonizePop.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Create GDP and Population Scenarios

R package **mrdrivers**, version **4.0.2**
R package **mrdrivers**, version **4.0.3**

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

Expand Down Expand Up @@ -100,7 +100,7 @@ In case of questions / problems please contact Johannes Koch <jokoch@pik-potsdam

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

Koch J, Soergel B, Leip D, Benke F, Dietrich J (2024). _mrdrivers: Create GDP and Population Scenarios_. R package version 4.0.2, <https://pik-piam.github.io/mrdrivershttps://github.com/pik-piam/mrdrivers>.
Koch J, Soergel B, Leip D, Benke F, Dietrich J (2024). _mrdrivers: Create GDP and Population Scenarios_. R package version 4.0.3, <https://pik-piam.github.io/mrdrivershttps://github.com/pik-piam/mrdrivers>.

A BibTeX entry for LaTeX users is

Expand All @@ -109,7 +109,7 @@ A BibTeX entry for LaTeX users is
title = {mrdrivers: Create GDP and Population Scenarios},
author = {Johannes Koch and Bjoern Soergel and Deborra Leip and Falk Benke and Jan Philipp Dietrich},
year = {2024},
note = {R package version 4.0.2},
note = {R package version 4.0.3},
url = {https://pik-piam.github.io/mrdrivers},
url = {https://github.com/pik-piam/mrdrivers},
}
Expand Down

0 comments on commit 6454aa5

Please sign in to comment.