diff --git a/.buildlibrary b/.buildlibrary index 733ca63f..be9ffb40 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '43610700' +ValidationKey: '43822590' AutocreateReadme: yes AutocreateCITATION: yes AcceptedWarnings: diff --git a/CITATION.cff b/CITATION.cff index a95c8122..38c6fc37 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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: 'mrmfa: Input data generation for the REMIND MFA' -version: 2.10.0 -date-released: '2026-11-10' +version: 2.11.0 +date-released: '2026-11-12' abstract: The mrmfa packages contains data preprocessing for the REMIND MFA. authors: - family-names: Dürrwächter diff --git a/DESCRIPTION b/DESCRIPTION index 60016b1a..81b3dd04 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrmfa Title: Input data generation for the REMIND MFA -Version: 2.10.0 -Date: 2026-11-10 +Version: 2.11.0 +Date: 2026-11-12 Authors@R: c( person("Jakob", "Dürrwächter", , "jakobdu@pik-potsdam.de", role = c("aut", "cre")), person("Bennet", "Weiss", , "bennet.weiss@pik-potsdam.de", role = "aut"), diff --git a/R/calcCoScalars.R b/R/calcCoScalars.R new file mode 100644 index 00000000..b2152266 --- /dev/null +++ b/R/calcCoScalars.R @@ -0,0 +1,36 @@ +#' Collect scalar parameters +#' +#' @description +#' Stores named scalar values (e.g. the start and end years of the model time +#' periods) in a magpie object, so that they can be written to a file via +#' calcOutput. Written as .cs4r, each line has the form \code{name,value}. +#' +#' @author Jakob Dürrwächter +#' @param scalars Named numeric vector, e.g. +#' \code{c(start_historical = 1900, end_historical = 2022, end_future = 2150)}. +#' @param unit Unit of the scalars. +#' @return List with magpie object of the scalars and metadata in calcOutput format. +#' @examples +#' \dontrun{ +#' calcOutput("CoScalars", scalars = c(start_historical = 1900, end_historical = 2022), +#' file = "st_scalars.cs4r", aggregate = FALSE) +#' } +calcCoScalars <- function(scalars, unit = "various") { + if (!is.numeric(scalars) || length(scalars) == 0) { + stop("scalars must be a non-empty numeric vector.") + } + if (is.null(names(scalars)) || any(names(scalars) == "") || anyDuplicated(names(scalars))) { + stop("All scalars must have unique, non-empty names.") + } + + x <- new.magpie(names = names(scalars), fill = unname(scalars), sets = c("region", "year", "scalar")) + + return(list( + x = x, + weight = NULL, + unit = unit, + isocountries = FALSE, + description = paste0("Scalar parameters: ", paste(names(scalars), collapse = ", ")), + note = "dimensions: (scalar,value)" + )) +} diff --git a/R/fullMFA.R b/R/fullMFA.R index 87444fd2..3350269b 100644 --- a/R/fullMFA.R +++ b/R/fullMFA.R @@ -47,6 +47,9 @@ fullMFA <- function(rev = 0, start_historical <- 1900 end_historical <- 2022 + calcOutput("CoScalars", file = "st_time_range.cs4r", aggregate = FALSE, unit = "year", + scalars = c(start_historical = start_historical, end_historical = end_historical, end_future = end_future)) + # common parameters calcOutput("CoPopulation", file = "st_population.cs4r", scenarios = driverScenarios, collapse = FALSE, smooth = TRUE, years = start_historical:end_future) calcOutput("CoGDP", file = "st_gdppc.cs4r", perCapita = gdpPerCapita, scenarios = driverScenarios, collapse = FALSE, smooth = TRUE, years = start_historical:end_future) @@ -97,6 +100,9 @@ fullMFA <- function(rev = 0, start_historical <- 1880 end_historical <- 2025 + calcOutput("CoScalars", file = "ce_time_range.cs4r", aggregate = FALSE, unit = "year", + scalars = c(start_historical = start_historical, end_historical = end_historical, end_future = end_future)) + # common parameters calcOutput("CoPopulation", file = "ce_population.cs4r", scenarios = driverScenarios, collapse = FALSE, smooth = TRUE, years = start_historical:end_future) calcOutput("CoGDP", file = "ce_gdppc.cs4r", perCapita = gdpPerCapita, scenarios = driverScenarios, collapse = FALSE, smooth = TRUE, years = start_historical:end_future) @@ -146,6 +152,9 @@ fullMFA <- function(rev = 0, start_historical <- 1950 end_historical <- 2024 + calcOutput("CoScalars", file = "pl_time_range.cs4r", aggregate = FALSE, unit = "year", + scalars = c(start_historical = start_historical, end_historical = end_historical, end_future = end_future)) + # common parameters calcOutput("CoPopulation", file = "pl_population.cs4r", scenarios = driverScenarios, collapse = FALSE, smooth = TRUE, years = start_historical:end_future) calcOutput("CoGDP", file = "pl_gdppc.cs4r", perCapita = gdpPerCapita, scenarios = driverScenarios, collapse = FALSE, smooth = TRUE, years = start_historical:end_future) diff --git a/README.md b/README.md index 32c6b025..a353b073 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Input data generation for the REMIND MFA -R package **mrmfa**, version **2.10.0** +R package **mrmfa**, version **2.11.0** [![R build status](https://github.com/pik-piam/mrmfa/workflows/check/badge.svg)](https://github.com/pik-piam/mrmfa/actions) [![codecov](https://codecov.io/gh/pik-piam/mrmfa/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrmfa) @@ -38,7 +38,7 @@ In case of questions / problems please contact Jakob Dürrwächter . +Dürrwächter J, Weiss B, Schweiger L, Benke F, Diez T, Hosak M, Zhang Q (2026). "mrmfa: Input data generation for the REMIND MFA." Version: 2.11.0, . A BibTeX entry for LaTeX users is @@ -46,9 +46,9 @@ A BibTeX entry for LaTeX users is @Misc{, title = {mrmfa: Input data generation for the REMIND MFA}, author = {Jakob Dürrwächter and Bennet Weiss and Leonie Schweiger and Falk Benke and Tobias Diez and Merlin Jo Hosak and Qianzhi Zhang}, - date = {2026-11-10}, + date = {2026-11-12}, year = {2026}, url = {https://github.com/pik-piam/mrmfa}, - note = {Version: 2.10.0}, + note = {Version: 2.11.0}, } ``` diff --git a/man/calcCoScalars.Rd b/man/calcCoScalars.Rd new file mode 100644 index 00000000..2e1f4cb8 --- /dev/null +++ b/man/calcCoScalars.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcCoScalars.R +\name{calcCoScalars} +\alias{calcCoScalars} +\title{Collect scalar parameters} +\usage{ +calcCoScalars(scalars, unit = "various") +} +\arguments{ +\item{scalars}{Named numeric vector, e.g. +\code{c(start_historical = 1900, end_historical = 2022, end_future = 2150)}.} + +\item{unit}{Unit of the scalars.} +} +\value{ +List with magpie object of the scalars and metadata in calcOutput format. +} +\description{ +Stores named scalar values (e.g. the start and end years of the model time +periods) in a magpie object, so that they can be written to a file via +calcOutput. Written as .cs4r, each line has the form \code{name,value}. +} +\examples{ +\dontrun{ +calcOutput("CoScalars", scalars = c(start_historical = 1900, end_historical = 2022), + file = "st_scalars.cs4r", aggregate = FALSE) +} +} +\author{ +Jakob Dürrwächter +}