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

Update in accordance with mrdrivers update #21

Merged
merged 2 commits into from
Nov 6, 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
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '52359240'
ValidationKey: '52426361'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
Expand All @@ -8,3 +8,4 @@ AcceptedNotes:
- Depends: includes the non-default packages
allowLinterWarnings: no
enforceVersionUpdate: no
skipCoverage: no
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:
shell: Rscript {0}
run: |
nonDummyTests <- setdiff(list.files("./tests/testthat/"), c("test-dummy.R", "_snaps"))
if(length(nonDummyTests) > 0) covr::codecov(quiet = FALSE)
if(length(nonDummyTests) > 0 && !lucode2:::loadBuildLibraryConfig()[["skipCoverage"]]) covr::codecov(quiet = FALSE)
env:
NOT_CRAN: "true"
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: 'mrvalidation: madrat data preparation for validation purposes'
version: 2.61.6
date-released: '2024-10-19'
version: 2.61.7
date-released: '2024-11-06'
abstract: Package contains routines to prepare data for validation exercises.
authors:
- family-names: Bodirsky
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrvalidation
Title: madrat data preparation for validation purposes
Version: 2.61.6
Date: 2024-10-19
Version: 2.61.7
Date: 2024-11-06
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down Expand Up @@ -34,7 +34,7 @@ Depends:
madrat (>= 2.11.3),
magclass (>= 3.17),
mrcommons (>= 1.41.0),
mrdrivers (>= 0.2.2),
mrdrivers (>= 4.0.0),
mrfactors (>= 0.4.0),
mrfaocore (>= 1.0.0),
mrlandcore (>= 1.0.0),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ importFrom(madrat,toolGetMapping)
importFrom(madrat,toolNAreplace)
importFrom(madrat,toolSplitSubtype)
importFrom(madrat,toolSubtypeSelect)
importFrom(madrat,vcat)
importFrom(magclass,"getCells<-")
importFrom(magclass,"getComment<-")
importFrom(magclass,"getItems<-")
importFrom(magclass,"getNames<-")
importFrom(magclass,"getRegions<-")
importFrom(magclass,"getSets<-")
importFrom(magclass,"getYears<-")
importFrom(magclass,add_columns)
importFrom(magclass,add_dimension)
Expand Down
21 changes: 8 additions & 13 deletions R/calcValidIncome.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
#' Returns historical development of income and future projections of income dynamics
#'
#'
#' @param datasource To switch between historical values of James et al (default) or
#' with future projections for different scenarios (James_OECD_Nakicenovic)
#' @param datasource "WDI_SSPs", the only one option at the moment.
#' @return list of magpie object with data and weight. Since intensive and extensive variables
#' are mixed please keep the mixed_aggregation
#' @importFrom madrat vcat calcOutput
#' @importFrom magclass mbind add_dimension getSets getSets<- collapseNames getYears
#' @author Florian Humpenoeder, Abhijeet Mishra, Kristine Karstens
calcValidIncome <- function(datasource = "WDI_SSPs") {

calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") {

if (datasource == "WDI-MI_SSPs-MI") {
if (datasource == "WDI_SSPs") {

.tmp <- function(x, nm) {
getSets(x)[3] <- "scenario"
Expand Down Expand Up @@ -64,10 +60,9 @@ calcValidIncome <- function(datasource = "WDI-MI_SSPs-MI") {
stop("Given datasource currently not supported!")
}

return(list(x = out,
weight = weight,
mixed_aggregation = TRUE,
unit = "(million) US Dollar 2017 equivalents in MER/yr, MER/cap/yr, PPP/yr, PPP/cap/yr",
description = "Income")
)
list(x = out,
weight = weight,
mixed_aggregation = TRUE,
unit = "(million) US Dollar 2017 equivalents in MER/yr, MER/cap/yr, PPP/yr, PPP/cap/yr",
description = "Income")
}
56 changes: 17 additions & 39 deletions R/calcValidPopulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,31 @@
#'
#' Returns historical development of population and future projections of population dynamics
#'
#'
#' @param PopulationPast population past data source
#' @param PopulationFuture population future data source
#' @param TimeFromFindSet boolean deciding something
#' @param pastData population past data source
#' @param futureData population future data source
#' @return list of magpie object with data and weight
#' @author Florian Humpenoeder, Jan Philipp Dietrich, David Chen
#' @importFrom magclass getRegions
#' @import mrdrivers
calcValidPopulation <- function(PopulationPast = "WDI-UN_PopDiv-MI",
PopulationFuture = c("SSPs-UN_PopDiv-MI",
"SDPs-UN_PopDiv-MI",
"SSP2EU-UN_PopDiv-MI"),
TimeFromFindSet = TRUE) {

past <- calcOutput("PopulationPast",
PopulationPast = PopulationPast,
aggregate = FALSE)
getNames(past) <- paste("historical", paste0(PopulationPast), "Population (million people)", sep = ".")
getSets(past)[3] <- "scenario.model.variable"
calcValidPopulation <- function(pastData = "WDI-UN_PopDiv-MI", futureData = "SSPs-UN_PopDiv") {

future <- NULL
for (i in 1:length(PopulationFuture)) {
tmp <- calcOutput("PopulationFuture",
PopulationFuture = PopulationFuture[i],
extension2150 = "bezier",
aggregate = FALSE)
future <- mbind(future, tmp)
}
past <- calcOutput("PopulationPast", pastData = pastData, aggregate = FALSE)
future <- calcOutput("PopulationFuture", futureData = futureData, aggregate = FALSE)


getNames(future) <- paste(sub("^pop_", "", getNames(future)),
paste0(PopulationFuture, collapse = "_and_"),
"Population (million people)",
sep = ".")
getNames(past) <- paste("historical", pastData, "Population (million people)", sep = ".")
getNames(future) <- paste(getNames(future), futureData, "Population (million people)", sep = ".")
getSets(past)[3] <- "scenario.model.variable"
getSets(future)[3] <- "scenario.model.variable"

out <- new.magpie(getRegions(past),
union(getYears(past), getYears(future)),
c(getNames(past), getNames(future)),
out <- new.magpie(cells_and_regions = getItems(past, 1),
years = union(getYears(past), getYears(future)),
names = c(getNames(past), getNames(future)),
sets = c("region", "year", "scenario.model.variable"),
fill = NA)
out[, getYears(past), getNames(past)] <- past
out[, getYears(future), getNames(future)] <- future

getSets(out, fulldim = FALSE)[3] <- "scenario.model.variable"
return(list(x = out, weight = NULL, unit = "million",
description = paste0("Population data. Datasource for the Past: ",
PopulationPast,
". Datasource for the Future: ",
paste0(PopulationFuture, collapse = ", "))))
list(x = out,
weight = NULL,
unit = "million",
description = paste0("Population data. Datasource for the Past: ", pastData, ". Datasource for the Future: ",
futureData))
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat data preparation for validation purposes

R package **mrvalidation**, version **2.61.6**
R package **mrvalidation**, version **2.61.7**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

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

Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi:10.5281/zenodo.4317826 <https://doi.org/10.5281/zenodo.4317826>, R package version 2.61.6, <https://github.com/pik-piam/mrvalidation>.
Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi:10.5281/zenodo.4317826 <https://doi.org/10.5281/zenodo.4317826>, R package version 2.61.7, <https://github.com/pik-piam/mrvalidation>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,8 +48,8 @@ A BibTeX entry for LaTeX users is
title = {mrvalidation: madrat data preparation for validation purposes},
author = {Benjamin Leon Bodirsky and Stephen Wirth and Kristine Karstens and Florian Humpenoeder and Mishko Stevanovic and Abhijeet Mishra and Anne Biewald and Isabelle Weindl and Felicitas Beier and David Chen and Michael Crawford and Debbora Leip and Edna {Molina Bacca} and Ulrich Kreidenweis and Amsalu {W. Yalew} and Patrick {von Jeetze} and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves},
year = {2024},
note = {R package version 2.61.6},
url = {https://github.com/pik-piam/mrvalidation},
note = {R package version 2.61.7},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
```
5 changes: 2 additions & 3 deletions man/calcValidIncome.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions man/calcValidPopulation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading