From 009f2f2671062c5a26ce9ca950074c9a0007d125 Mon Sep 17 00:00:00 2001 From: bodirsky Date: Mon, 5 Feb 2024 15:33:24 +0100 Subject: [PATCH] minor --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- R/calcValidFeedConversion.R | 18 ++++++++++++++++-- README.md | 6 +++--- man/calcValidFeedConversion.Rd | 5 ++++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 1610db5..c856adb 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '50446608' +ValidationKey: '50481690' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index c76d1da..83ab8d8 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: 'mrvalidation: madrat data preparation for validation purposes' -version: 2.55.4 -date-released: '2024-01-30' +version: 2.55.5 +date-released: '2024-02-05' abstract: Package contains routines to prepare data for validation exercises. authors: - family-names: Bodirsky diff --git a/DESCRIPTION b/DESCRIPTION index c867ff9..f14e57d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: mrvalidation Title: madrat data preparation for validation purposes -Version: 2.55.4 -Date: 2024-01-30 +Version: 2.55.5 +Date: 2024-02-05 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), person("Stephen", "Wirth", role = "aut"), diff --git a/R/calcValidFeedConversion.R b/R/calcValidFeedConversion.R index b5ec733..2957735 100644 --- a/R/calcValidFeedConversion.R +++ b/R/calcValidFeedConversion.R @@ -2,6 +2,9 @@ #' @description calculates various feed indicators #' #' @param livestockSystem if TRUE, ruminant meat and milk are aggregated, and poultry meat and egg are aggregated +#' @param subtractBalanceflow if TRUE, balanceflow is subtracted so that the feed efficiency reflects +#' our feedbasket calucaltions. If FALSE, it reflects the FAO values and the pasture demand +#' #' #' @return List of magpie objects with results on country level, weight on country level, unit and description. #' @author Benjamin Leon Bodirsky, github Copilot @@ -13,14 +16,25 @@ #' calcOutput("ValidFeed") #' } #' -#' @importFrom magpiesets reporthelper +#' @importFrom magpiesets reporthelper findset #' @importFrom magclass dimOrder -calcValidFeedConversion <- function(livestockSystem = TRUE) { +calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow = FALSE) { ### calculate product specific feed conversion efficiency as quotient between ### feed and animal products mb <- calcOutput("FAOmassbalance", aggregate = FALSE) + # subtract balanceflow + if (subtractBalanceflow) { + balanceflow <- calcOutput("FeedBalanceflow", aggregate = FALSE, future = FALSE) + getNames(balanceflow, dim = 1) <- paste0("feed_", getNames(balanceflow, dim = 1)) + balanceflow <- balanceflow * calcOutput("Attributes", aggregate = FALSE) + balanceflow <- as.magpie(aperm(unwrap(balanceflow), c(1, 2, 4, 3, 5))) + balanceflowTotal <- dimSums(balanceflow, dim = 3.2) + mb[, , findset("kap", alias = "feed")] <- mb[, , findset("kap", alias = "feed")] - balanceflow + mb[, , "feed"] <- mb[, , "feed"] - balanceflowTotal + } + mb <- mb[, , c("ge", "nr")] x <- NULL weight <- NULL diff --git a/README.md b/README.md index d94389e..0d53483 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat data preparation for validation purposes -R package **mrvalidation**, version **2.55.4** +R package **mrvalidation**, version **2.55.5** [![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) @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky , R package version 2.55.4, . +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 , R package version 2.55.5, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ 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.55.4}, + note = {R package version 2.55.5}, doi = {10.5281/zenodo.4317826}, url = {https://github.com/pik-piam/mrvalidation}, } diff --git a/man/calcValidFeedConversion.Rd b/man/calcValidFeedConversion.Rd index ffdf58f..0cbe82d 100644 --- a/man/calcValidFeedConversion.Rd +++ b/man/calcValidFeedConversion.Rd @@ -4,10 +4,13 @@ \alias{calcValidFeedConversion} \title{calcValidFeedConversion} \usage{ -calcValidFeedConversion(livestockSystem = TRUE) +calcValidFeedConversion(livestockSystem = TRUE, subtractBalanceflow = FALSE) } \arguments{ \item{livestockSystem}{if TRUE, ruminant meat and milk are aggregated, and poultry meat and egg are aggregated} + +\item{subtractBalanceflow}{if TRUE, balanceflow is subtracted so that the feed efficiency reflects +our feedbasket calucaltions. If FALSE, it reflects the FAO values and the pasture demand} } \value{ List of magpie objects with results on country level, weight on country level, unit and description.