Skip to content

Commit

Permalink
bugfix timber demand validation
Browse files Browse the repository at this point in the history
  • Loading branch information
flohump committed Feb 13, 2024
1 parent 8893265 commit abfaf96
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '50531434'
ValidationKey: '50561428'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/lorenzwalthert/precommit
rev: v0.3.2.9025
rev: v0.4.0
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: 'mrvalidation: madrat data preparation for validation purposes'
version: 2.55.7
date-released: '2024-02-09'
version: 2.55.8
date-released: '2024-02-13'
abstract: Package contains routines to prepare data for validation exercises.
authors:
- family-names: Bodirsky
Expand Down
4 changes: 2 additions & 2 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.55.7
Date: 2024-02-09
Version: 2.55.8
Date: 2024-02-13
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
65 changes: 36 additions & 29 deletions R/calcValidProduction.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title calcValidProduction
#' @description calculates the validation data for production of agricultural products
#'
#' @param datasource Datasource of validation data.
#'
#' @param datasource Datasource of validation data.
#' @param detail if FALSE, only larger product categories are reported
#' @param nutrient The nutrient in which the results shall be reported.
#'
Expand All @@ -11,37 +11,44 @@
#' \code{\link{calcFAOmassbalance}},
#' \code{\link{calcValidDemand}}
#' @examples
#'
#' \dontrun{
#' \dontrun{
#' calcOutput("ValidProduction")
#' }
#'
#'

#' @importFrom magpiesets reporthelper summationhelper
calcValidProduction<-function(datasource="FAO", detail=T, nutrient="dm"){

if(datasource=="FAO"){
mb<-collapseNames(calcOutput("FAOmassbalance",aggregate = F)[,,nutrient][,,"production"])
mb[,,"woodfuel"] <- mb[,,"woodfuel"] * 0.5 ## For the moment MAgPIE is only modeling 50% of wood demand to be met by traditional woody biomass
out<-reporthelper(x=mb,dim = 3.1,level_zero_name = "Production",detail = detail)
} else stop("No data exist for the given datasource!")

calcValidProduction <- function(datasource = "FAO", detail = TRUE, nutrient = "dm") {

if (datasource == "FAO") {
mb <- collapseNames(calcOutput("FAOmassbalance", aggregate = FALSE)[, , nutrient][, , "production"])
out <- reporthelper(x = mb, dim = 3.1, level_zero_name = "Production", detail = detail)
} else {
stop("No data exist for the given datasource!")
}

out <- summationhelper(out)
out <- add_dimension(out, dim=3.1, add="scenario", nm="historical")
out <- add_dimension(out, dim=3.2, add="model", nm=datasource)
out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)
names(dimnames(out))[3] <- "scenario.model.variable"
if(nutrient=="dm"){unit="Mt DM/yr"
} else if (nutrient=="nr"){unit="Mt Nr/yr"
} else if (nutrient=="p"){unit="Mt P/yr"
} else if (nutrient=="k"){unit="Mt K/yr"
} else if (nutrient=="ge"){unit="PJ/yr"
} else if (nutrient=="wm"){unit="Mt WM/yr"}
getNames(out) <- sub("\\|$","",getNames(out))
getNames(out) <- paste0(getNames(out)," (",unit,")")

return(list(x=out,
weight=NULL,
unit=unit,
description="Agricultural Production")
if (nutrient == "dm") {
unit <- "Mt DM/yr"
} else if (nutrient == "nr") {
unit <- "Mt Nr/yr"
} else if (nutrient == "p") {
unit <- "Mt P/yr"
} else if (nutrient == "k") {
unit <- "Mt K/yr"
} else if (nutrient == "ge") {
unit <- "PJ/yr"
} else if (nutrient == "wm") {
unit <- "Mt WM/yr"
}
getNames(out) <- sub("\\|$", "", getNames(out))
getNames(out) <- paste0(getNames(out), " (", unit, ")")

return(list(x = out,
weight = NULL,
unit = unit,
description = "Agricultural Production")
)
}
}
6 changes: 3 additions & 3 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.55.7**
R package **mrvalidation**, version **2.55.8**

[![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.55.7, <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.55.8, <https://github.com/pik-piam/mrvalidation>.

A BibTeX entry for LaTeX users is

Expand All @@ -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.7},
note = {R package version 2.55.8},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
Expand Down
5 changes: 2 additions & 3 deletions man/calcValidProduction.Rd

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

0 comments on commit abfaf96

Please sign in to comment.