diff --git a/.buildlibrary b/.buildlibrary index 02ce032..b6265a0 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '50673798' +ValidationKey: '50693577' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 293451d..00c7fd7 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ 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.56.2 +version: 2.56.3 date-released: '2024-02-26' abstract: Package contains routines to prepare data for validation exercises. authors: diff --git a/DESCRIPTION b/DESCRIPTION index 1c5856a..1145f34 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: mrvalidation Title: madrat data preparation for validation purposes -Version: 2.56.2 +Version: 2.56.3 Date: 2024-02-26 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), diff --git a/R/calcValidFactorReqShares.R b/R/calcValidFactorReqShares.R new file mode 100644 index 0000000..bbda498 --- /dev/null +++ b/R/calcValidFactorReqShares.R @@ -0,0 +1,42 @@ +#' @title calcValidFactorReqShares +#' +#' @description calculates the validation data for labor and capital requirement shares in agriculture +#' (currently the same shares for crop and livestock production based on USDA data) +#' @param subtype for which to report requirement shares, either "crop" or "livestock" +#' +#' @return List of magpie objects with results on country level, weight on country level, unit and description. +#' @author Debbora Leip +#' @examples +#' +#' \dontrun{ +#' calcOutput("ValidFactorReqShares") +#' } +#' + +calcValidFactorReqShares <- function(subtype = "crop") { + + if (!(subtype %in% c("crop", "livestock"))) stop("subtype must be either 'crop' or 'livestock'") + + out <- setNames(calcOutput("AgCapLabourShare", aggregate = FALSE), + paste0("Factor requirement shares|", stringr::str_to_title(subtype), + " products|+|Capital requirement share (%)")) + out <- mbind(out, setNames(1 - out, paste0("Factor requirement shares|", stringr::str_to_title(subtype), + " products|+|Labor requirement share (%)"))) + + out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical") + out <- add_dimension(out, dim = 3.2, add = "model", nm = "USDA") + + + # production as weight (0 weight to countries with unexpectedly high capital shares) + weight <- dimSums(collapseDim(calcOutput("Production", aggregate = FALSE)[, , "dm"]), dim = 3.1) + weight[c("BLZ", "CRI", "DOM", "HND", "JAM", "MEX", "NIC", "PAN", "SLV"), , ] <- 0 + weight <- weight[, getItems(out, dim = 2), ] + weight[out[, , "Capital", pmatch = TRUE] == 0] <- 0 + + + return(list(x = out, + weight = weight, + unit = "%", + description = "Factor requirement shares based on USDA data") + ) +} diff --git a/R/calcValidFeedConversion.R b/R/calcValidFeedConversion.R index c96babd..13ead57 100644 --- a/R/calcValidFeedConversion.R +++ b/R/calcValidFeedConversion.R @@ -2,7 +2,7 @@ #' @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 +#' @param subtractBalanceflow if TRUE, balanceflow is subtracted so that the feed conversion reflects #' our feedbasket calucaltions. If FALSE, it reflects the FAO values and the pasture demand #' #' @@ -19,7 +19,7 @@ #' @importFrom magpiesets reporthelper findset #' @importFrom magclass dimOrder calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow = FALSE) { - ### calculate product specific feed conversion efficiency as quotient between + ### calculate product specific feed conversion as quotient between ### feed and animal products mb <- calcOutput("FAOmassbalance", aggregate = FALSE) @@ -107,32 +107,32 @@ calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow getNames(quotientProductspecfic, dim = 1) <- reportingnames(getNames(quotientProductspecfic, dim = 1)) } - # Calculate feed conversion efficiency total + # Calculate feed conversion total quotientTmp <- collapseNames(dimSums(quotientProductspecfic, dim = c("ItemCodeItem"))[, , "ge"]) indicatorTmp <- collapseNames(dimSums(feedProductspecific, dim = c("ItemCodeItem", "ElementShort"))[, , "ge"]) / quotientTmp - nameIndicator <- "Productivity|Feed conversion efficiency" + nameIndicator <- "Productivity|Feed conversion" indicatorTmp <- setNames(collapseNames(indicatorTmp), paste0(nameIndicator, " (", "GE per GE", ")")) quotientTmp <- setNames(collapseNames(quotientTmp), paste0(nameIndicator, " (", "GE per GE", ")")) x <- mbind(x, indicatorTmp) weight <- mbind(weight, quotientTmp) - # calculate feed conversion efficiency Livestock specific + # calculate feed conversion Livestock specific quotientTmp <- quotientProductspecfic[, , c("ge", "nr")] indicatorTmp <- dimSums(feedProductspecific, dim = c("ItemCodeItem"))[, , c("ge", "nr")] / quotientTmp - prefix <- "Productivity|Feed conversion efficiency|" + prefix <- "Productivity|Feed conversion|" nameIndicator <- paste0(prefix, getNames(indicatorTmp, dim = 1), " (", "GE per GE", ")") x <- mbind(x, setNames(collapseNames(indicatorTmp[, , "ge"]), nameIndicator)) weight <- mbind(weight, setNames(collapseNames(quotientTmp[, , "ge"]), nameIndicator)) - prefix <- "Productivity|Feed protein conversion efficiency|" + prefix <- "Productivity|Feed protein conversion|" nameIndicator <- paste0(prefix, getNames(indicatorTmp, dim = 1), " (", "Nr per Nr", ")") x <- mbind(x, setNames(collapseNames(indicatorTmp[, , "nr"]), nameIndicator)) weight <- mbind(weight, setNames(collapseNames(quotientTmp[, , "nr"]), nameIndicator)) - # calculate feed conversion efficiency Livestock and product specific + # calculate feed conversion Livestock and product specific quotientTmp <- collapseNames(quotientProductspecfic[, , "ge"]) indicatorTmp <- collapseNames(feedProductspecific[, , "ge"]) / quotientTmp - prefix <- "Productivity|Feed conversion efficiency|" + prefix <- "Productivity|Feed conversion|" for (item in getNames(feedProductspecific, dim = 2)) { nameIndicator <- paste0(prefix, item, "|+|", getNames(indicatorTmp, dim = 1), " (", "GE per GE", ")") @@ -142,10 +142,10 @@ calcValidFeedConversion <- function(livestockSystem = TRUE, subtractBalanceflow weight <- mbind(weight, setNames(weightTmp, nameIndicator)) } - # calculate feed conversion efficiency Product specific + # calculate feed conversion Product specific quotientTmp <- collapseNames(dimSums(quotientProductspecfic, dim = c("ItemCodeItem"))[, , "ge"]) indicatorTmp <- collapseNames(dimSums(feedProductspecific, dim = c("ElementShort"))[, , "ge"]) / quotientTmp - prefix <- "Productivity|Feed conversion efficiency|+|" + prefix <- "Productivity|Feed conversion|+|" nameIndicator <- paste0(prefix, getNames(indicatorTmp, dim = 1), " (", "GE per GE", ")") x <- mbind(x, setNames(collapseNames(indicatorTmp), nameIndicator)) weightTmp <- collapseNames(indicatorTmp) * NA diff --git a/R/fullVALIDATION.R b/R/fullVALIDATION.R index 310a551..b510410 100644 --- a/R/fullVALIDATION.R +++ b/R/fullVALIDATION.R @@ -344,6 +344,11 @@ fullVALIDATION <- function(rev = 0.1) { calcOutput(type = "ValidCostsTransport", datasource = "GTAPwholesale", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidFactorReqShares", subtype = "crop", aggregate = "REG+GLO", + file = valfile, append = TRUE, try = TRUE) + calcOutput(type = "ValidFactorReqShares", subtype = "livestock", aggregate = "REG+GLO", + file = valfile, append = TRUE, try = TRUE) + # Diversity indices calcOutput(type = "ValidBII", aggregate = "REG+GLO", file = valfile, append = TRUE, try = TRUE) diff --git a/README.md b/README.md index 98ada74..8ee5fc6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # madrat data preparation for validation purposes -R package **mrvalidation**, version **2.56.2** +R package **mrvalidation**, version **2.56.3** [![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.56.2, . +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 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.56.3, . 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.56.2}, + note = {R package version 2.56.3}, doi = {10.5281/zenodo.4317826}, url = {https://github.com/pik-piam/mrvalidation}, } diff --git a/man/calcValidFactorReqShares.Rd b/man/calcValidFactorReqShares.Rd new file mode 100644 index 0000000..bb72521 --- /dev/null +++ b/man/calcValidFactorReqShares.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcValidFactorReqShares.R +\name{calcValidFactorReqShares} +\alias{calcValidFactorReqShares} +\title{calcValidFactorReqShares} +\usage{ +calcValidFactorReqShares(subtype = "crop") +} +\arguments{ +\item{subtype}{for which to report requirement shares, either "crop" or "livestock"} +} +\value{ +List of magpie objects with results on country level, weight on country level, unit and description. +} +\description{ +calculates the validation data for labor and capital requirement shares in agriculture +(currently the same shares for crop and livestock production based on USDA data) +} +\examples{ + +\dontrun{ +calcOutput("ValidFactorReqShares") +} + +} +\author{ +Debbora Leip +} diff --git a/man/calcValidFeedConversion.Rd b/man/calcValidFeedConversion.Rd index 0cbe82d..6b382ca 100644 --- a/man/calcValidFeedConversion.Rd +++ b/man/calcValidFeedConversion.Rd @@ -9,7 +9,7 @@ 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 +\item{subtractBalanceflow}{if TRUE, balanceflow is subtracted so that the feed conversion reflects our feedbasket calucaltions. If FALSE, it reflects the FAO values and the pasture demand} } \value{