Skip to content

Commit

Permalink
Merge pull request #49 from johanneskoch94/master
Browse files Browse the repository at this point in the history
Drop SSP2EU and pop_ prefixes
  • Loading branch information
johanneskoch94 authored Feb 7, 2025
2 parents 2f1473a + 15fd1b3 commit 27ba42d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '30770038'
ValidationKey: '30831500'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
[ -f requirements.txt ] && python -m pip install --upgrade pip wheel || true
[ -f requirements.txt ] && pip install -r requirements.txt || true
- name: Run pre-commit checks
shell: bash
run: |
python -m pip install pre-commit
python -m pip freeze --local
pre-commit run --show-diff-on-failure --color=always --all-files
- name: Verify validation key
shell: Rscript {0}
run: lucode2:::validkey(stopIfInvalid = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ repos:
- id: readme-rmd-rendered
- id: use-tidy-description
ci:
autoupdate_schedule: quarterly
autoupdate_schedule: weekly
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: 'mrmagpie: madrat based MAgPIE Input Data Library'
version: 1.53.1
date-released: '2025-01-10'
version: 1.53.2
date-released: '2025-02-06'
abstract: Provides functions for MAgPIE country and cellular input data generation.
authors:
- family-names: Karstens
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: mrmagpie
Title: madrat based MAgPIE Input Data Library
Version: 1.53.1
Date: 2025-01-10
Version: 1.53.2
Date: 2025-02-06
Authors@R: c(
person("Kristine", "Karstens", , "[email protected]", role = c("aut", "cre")),
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"),
Expand Down
27 changes: 8 additions & 19 deletions R/calcGridPop.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ calcGridPop <- function(source = "ISIMIP", subtype = "all", # nolint

if (subtype == "past") {
# Add scenario dimension and fill with same value
x <- add_columns(x, dim = 3.1, addnm = c("pop_SSP1", "pop_SSP2", "pop_SSP3", "pop_SSP4", "pop_SSP5"))
x <- add_columns(x, dim = 3.1, addnm = c("SSP1", "SSP2", "SSP3", "SSP4", "SSP5"))
x[, , 2:6] <- x[, , 1]
x <- (x[, , -1])
}
} else if (src == "Gao") {
x <- readSource("GridPopGao", subtype = subtype, convert = FALSE)
getNames(x, dim = 1) <- paste0("pop_", getNames(x, dim = 1))

if (!urban && subtype == "future") {
x <- collapseNames(dimSums(x, dim = 3.2))
Expand Down Expand Up @@ -90,8 +89,7 @@ calcGridPop <- function(source = "ISIMIP", subtype = "all", # nolint
"Use Gao source instead for cellular urban/rural population")

# urban population at country-level
urbanPop <- calcOutput("Urban", aggregate = FALSE)
getNames(urbanPop) <- gsub("urb_", "", getNames(urbanPop))
urbanPop <- calcOutput("Urban", scenario = c("SSPs", "SDPs"), naming = "scenario", aggregate = FALSE)
# disaggregate to cell level
coordMapping <- toolGetMappingCoord2Country()
urbanPop <- toolAggregate(urbanPop,
Expand All @@ -111,7 +109,7 @@ calcGridPop <- function(source = "ISIMIP", subtype = "all", # nolint
# harmonize future SSPs to divergence year by making them SSP2
selectY <- 1:which(getYears(future, as.integer = TRUE) == harmonize_until)
harmY <- getYears(future, as.integer = TRUE)[selectY]
future[, harmY, ] <- future[, harmY, "pop_SSP2"]
future[, harmY, ] <- future[, harmY, "SSP2"]

# take future years in case of overlap
pYears <- setdiff(getYears(past), getYears(future))
Expand All @@ -126,24 +124,18 @@ calcGridPop <- function(source = "ISIMIP", subtype = "all", # nolint
}

# Add SDP, SDP_EI, SDP_RC and SDP_MC scenarios as copy of SSP1
if ("pop_SSP1" %in% getNames(x, dim = 1) && !("pop_SDP" %in% getNames(x, dim = 1))) {
combinedSDP <- x[, , "pop_SSP1"]
if ("SSP1" %in% getNames(x, dim = 1) && !("SDP" %in% getNames(x, dim = 1))) {
combinedSDP <- x[, , "SSP1"]
for (i in c("SDP", "SDP_EI", "SDP_RC", "SDP_MC")) {
getNames(combinedSDP) <- gsub("SSP1", i, getNames(x[, , "pop_SSP1"]))
getNames(combinedSDP) <- gsub("SSP1", i, getNames(x[, , "SSP1"]))
x <- mbind(x, combinedSDP)
}
}
# Add SSP2EU as copy of SSP2
if ("pop_SSP2" %in% getNames(x, dim = 1) && !("pop_SSP2EU" %in% getNames(x, dim = 1))) {
combinedEU <- x[, , "pop_SSP2"]
getNames(combinedEU) <- gsub("SSP2", "SSP2EU", getNames(x[, , "pop_SSP2"]))
x <- mbind(x, combinedEU)
}

if (scale) {
## Scale to match country-level data
# Country-level population data (in million)
pop <- calcOutput("Population", aggregate = FALSE)
pop <- calcOutput("Population", scenario = c("SSPs", "SDPs"), naming = "scenario", aggregate = FALSE)
# aggregate to country-level and scale to match WDI country-level pop
if (cells == "lpjcell") {
agg <- collapseNames(dimSums(x, dim = c("x", "y")))
Expand Down Expand Up @@ -172,7 +164,7 @@ calcGridPop <- function(source = "ISIMIP", subtype = "all", # nolint
# even division of population across cells
missing <- magclass::where(scF[commonCountries, , ] == 0)$true$regions
for (i in missing) {
x[i, , ] <- pop[i, , "pop_SSP2"] / length(getCells(x[i, , ]))
x[i, , ] <- pop[i, , "SSP2"] / length(getCells(x[i, , ]))
}
}
# unit conversion to million people
Expand All @@ -183,9 +175,6 @@ calcGridPop <- function(source = "ISIMIP", subtype = "all", # nolint
x <- x[, intersect(years, getYears(x)), ]
}

if (subtype == "all") {
getNames(x) <- gsub("pop_", "", getNames(x))
}
# Checks
if (any(is.na(x))) {
stop("Function calcGridPop returned NAs.")
Expand Down
4 changes: 2 additions & 2 deletions R/readGridPopIsimip.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ readGridPopIsimip <- function(subtype) {
sspNaming <- NULL
for (file in files) {
sspNaming <- append(sspNaming,
paste0("pop_", toupper(unlist(regmatches(file,
gregexpr("ssp[0-9]", file))))))
paste0(toupper(unlist(regmatches(file,
gregexpr("ssp[0-9]", file))))))
x[[file]] <- read(file)
}
x <- mbind(x)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat based MAgPIE Input Data Library

R package **mrmagpie**, version **1.53.1**
R package **mrmagpie**, version **1.53.2**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Kristine Karstens <karstens@pik-p

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

Karstens K, Dietrich J, Chen D, Windisch M, Alves M, Beier F, Köberle A, v. Jeetze P, Mishra A, Humpenoeder F, Sauer P (2025). "mrmagpie: madrat based MAgPIE Input Data Library." doi:10.5281/zenodo.4319612 <https://doi.org/10.5281/zenodo.4319612>, Version: 1.53.1, <https://github.com/pik-piam/mrmagpie>.
Karstens K, Dietrich J, Chen D, Windisch M, Alves M, Beier F, Köberle A, v. Jeetze P, Mishra A, Humpenoeder F, Sauer P (2025). "mrmagpie: madrat based MAgPIE Input Data Library." doi:10.5281/zenodo.4319612 <https://doi.org/10.5281/zenodo.4319612>, Version: 1.53.2, <https://github.com/pik-piam/mrmagpie>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,9 +48,9 @@ A BibTeX entry for LaTeX users is
title = {mrmagpie: madrat based MAgPIE Input Data Library},
author = {Kristine Karstens and Jan Philipp Dietrich and David Chen and Michael Windisch and Marcos Alves and Felicitas Beier and Alexandre Köberle and Patrick {v. Jeetze} and Abhijeet Mishra and Florian Humpenoeder and Pascal Sauer},
doi = {10.5281/zenodo.4319612},
date = {2025-01-10},
date = {2025-02-06},
year = {2025},
url = {https://github.com/pik-piam/mrmagpie},
note = {Version: 1.53.1},
note = {Version: 1.53.2},
}
```

0 comments on commit 27ba42d

Please sign in to comment.