Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace speed_aggregate #113

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '27903624'
ValidationKey: '27948800'
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 .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: '^tests/testthat/_snaps/.*$'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.0
rev: 7910e0323d7213f34275a7a562b9ef0fde8ce1b9 # frozen: v0.4.2
hooks:
- id: parsable-R
- id: deps-in-desc
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: 'mrcommons: MadRat commons Input Data Library'
version: 1.40.7
date-released: '2024-04-19'
version: 1.40.8
date-released: '2024-05-07'
abstract: Provides useful functions and a common structure to all the input data required
to run models like MAgPIE and REMIND of model input data.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mrcommons
Type: Package
Title: MadRat commons Input Data Library
Version: 1.40.7
Date: 2024-04-19
Version: 1.40.8
Date: 2024-05-07
Authors@R: c(person("Benjamin Leon", "Bodirsky", email = "[email protected]", role = "aut"),
person("Kristine", "Karstens", role = "aut"),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ importFrom(lpjmlkit,read_io)
importFrom(luscale,getAggregationMatrix)
importFrom(luscale,groupAggregate)
importFrom(luscale,rename_dimnames)
importFrom(luscale,speed_aggregate)
importFrom(madrat,calcOutput)
importFrom(madrat,getISOlist)
importFrom(madrat,metadataGFZ)
Expand Down
2 changes: 0 additions & 2 deletions R/calcBodyHeight.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#' Also,the year 1965 is extrapolatedusing the worldbank population
#' data and sex, age, and education structure of 1970.
#' @export
#' @importFrom luscale speed_aggregate

calcBodyHeight <- function(convert = TRUE) {

demo <- calcOutput("Demography", education = FALSE, aggregate = FALSE)
Expand Down
21 changes: 10 additions & 11 deletions R/calcDemography.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ calcDemography <- function(convert = TRUE, education = TRUE) {
lutz <- readSource("Lutz2014", convert = convert)

mapping2 <- toolGetMapping(type = "sectoral", name = "lutz2hic2.csv",
where = "mappingfolder")
demo <- luscale::speed_aggregate(x = lutz, rel = mapping2, from = "lutz", to = "hic", dim = 3.2)
where = "mappingfolder")
demo <- toolAggregate(x = lutz, rel = mapping2, from = "lutz", to = "hic", dim = 3.2)

demo <- demo[, , "B", invert = TRUE]
demo <- demo[, , "All", invert = TRUE]
Expand All @@ -39,8 +39,7 @@ calcDemography <- function(convert = TRUE, education = TRUE) {
naming = "scenario",
years = magpiesets::findset("time"),
aggregate = FALSE)
diff <- dimSums(demo, dim = c("sex", "age", "education")) - population[, getYears(demo),
getNames(demo, dim = 1)]
diff <- dimSums(demo, dim = c("sex", "age", "education")) - population[, getYears(demo), getNames(demo, dim = 1)]
diff[] <- abs(diff)
if (sum(diff) > 100) {
vcat(2, paste0(
Expand All @@ -59,13 +58,13 @@ calcDemography <- function(convert = TRUE, education = TRUE) {
}

# recalibration to SSP population scenarios
# create SSP2EU and SDP scenarios columns based on SSP2 and SSP1
if (any(c("SDP", "SDP_EI", "SDP_MC", "SDP_RC", "SSP2EU") %in% getNames(population))) {
demo <- add_columns(demo, addnm = c("SDP", "SDP_EI", "SDP_MC", "SDP_RC", "SSP2EU"),
dim = 3.1, fill = NA)
demo[, , "SSP2EU"] <- demo[, , "SSP2"]
demo[, , "SDP", pmatch = TRUE] <- demo[, , "SSP1"]
}
# create SSP2EU and SDP scenarios columns based on SSP2 and SSP1
if (any(c("SDP", "SDP_EI", "SDP_MC", "SDP_RC", "SSP2EU") %in% getNames(population))) {
demo <- add_columns(demo, addnm = c("SDP", "SDP_EI", "SDP_MC", "SDP_RC", "SSP2EU"),
dim = 3.1, fill = NA)
demo[, , "SSP2EU"] <- demo[, , "SSP2"]
demo[, , "SDP", pmatch = TRUE] <- demo[, , "SSP1"]
}

demoShr <- demo / dimSums(demo, dim = c("sex", "age", "education"))
vcat(verbosity = 2, paste0("Year 1965 in demography data missing. Used values of 1970 instead"))
Expand Down
4 changes: 2 additions & 2 deletions R/calcIntakeBodyweight.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ calcIntakeBodyweight <- function(bodyweight, bodyheight = NULL, inactivity, tmea
requirement <- readSource("HHS_USDA", convert = FALSE)
weight <- requirement * 0 + 1
mapping <- toolGetMapping(type = "sectoral", name = "HHS_USDA2hic.csv", where = "mappingfolder")
requirement <- speed_aggregate(x = requirement, rel = mapping, weight = weight,
from = "HHS_USDA", to = "hic", dim = 3.2)
requirement <- toolAggregate(x = requirement, rel = mapping, weight = weight,
from = "HHS_USDA", to = "hic", dim = 3.2)

standardizedRequirement <- (collapseNames(requirement[, , "Sedentary"])
* inactivity + collapseNames(requirement[, , "Active"]) * (1 - inactivity))
Expand Down
2 changes: 1 addition & 1 deletion R/convertLutz2014.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ convertLutz2014 <- function(x) {

x <- toolCountryFill(x, fill = NA, no_remove_warning = "ANT")

# BB: use of speed_aggregate with an external mapping could replace the following function and speed it up
# BB: use of toolAggregate with an external mapping could replace the following function and speed it up
fillCountryByAverageOfRegion <- function(x, country, region) {
vcat(2, paste0("interpolating country: ", country))
values <- x[region, , ]
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 commons Input Data Library

R package **mrcommons**, version **1.40.7**
R package **mrcommons**, version **1.40.8**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

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

Bodirsky B, Karstens K, Baumstark L, Weindl I, Wang X, Mishra A, Wirth S, Stevanovic M, Steinmetz N, Kreidenweis U, Rodrigues R, Popov R, Humpenoeder F, Giannousakis A, Levesque A, Klein D, Araujo E, Beier F, Oeser J, Pehl M, Leip D, Crawford M, Molina Bacca E, von Jeetze P, Martinelli E, Schreyer F, Soergel B, Sauer P, Hötten D, Hasse R, Abrahão G, Weigmann P, Dietrich J (2024). _mrcommons: MadRat commons Input Data Library_. doi: 10.5281/zenodo.3822009 (URL: https://doi.org/10.5281/zenodo.3822009), R package version 1.40.7, <URL: https://github.com/pik-piam/mrcommons>.
Bodirsky B, Karstens K, Baumstark L, Weindl I, Wang X, Mishra A, Wirth S, Stevanovic M, Steinmetz N, Kreidenweis U, Rodrigues R, Popov R, Humpenoeder F, Giannousakis A, Levesque A, Klein D, Araujo E, Beier F, Oeser J, Pehl M, Leip D, Crawford M, Molina Bacca E, von Jeetze P, Martinelli E, Schreyer F, Soergel B, Sauer P, Hötten D, Hasse R, Abrahão G, Weigmann P, Dietrich J (2024). _mrcommons: MadRat commons Input Data Library_. doi:10.5281/zenodo.3822009 <https://doi.org/10.5281/zenodo.3822009>, R package version 1.40.8, <https://github.com/pik-piam/mrcommons>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,8 +48,8 @@ A BibTeX entry for LaTeX users is
title = {mrcommons: MadRat commons Input Data Library},
author = {Benjamin Leon Bodirsky and Kristine Karstens and Lavinia Baumstark and Isabelle Weindl and Xiaoxi Wang and Abhijeet Mishra and Stephen Wirth and Mishko Stevanovic and Nele Steinmetz and Ulrich Kreidenweis and Renato Rodrigues and Roman Popov and Florian Humpenoeder and Anastasis Giannousakis and Antoine Levesque and David Klein and Ewerton Araujo and Felicitas Beier and Julian Oeser and Michaja Pehl and Debbora Leip and Michael Crawford and Edna {Molina Bacca} and Patrick {von Jeetze} and Eleonora Martinelli and Felix Schreyer and Bjoern Soergel and Pascal Sauer and David Hötten and Robin Hasse and Gabriel Abrahão and Pascal Weigmann and Jan Philipp Dietrich},
year = {2024},
note = {R package version 1.40.7},
doi = {10.5281/zenodo.3822009},
note = {R package version 1.40.8},
url = {https://github.com/pik-piam/mrcommons},
doi = {10.5281/zenodo.3822009},
}
```