Skip to content

Commit

Permalink
Fix NA in SOC share calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
k4rst3ns committed Jun 16, 2024
1 parent 84b14ed commit b9ff29e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '51515100'
ValidationKey: '51534990'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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.59.0
version: 2.59.1
date-released: '2024-06-16'
abstract: Package contains routines to prepare data for validation exercises.
authors:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mrvalidation
Title: madrat data preparation for validation purposes
Version: 2.59.0
Version: 2.59.1
Date: 2024-06-16
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
Expand Down
6 changes: 5 additions & 1 deletion R/calcValidSOCShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ calcValidSOCShare <- function(datasource = "histSOCbudget") {
equStock <- mbind(equStock, add_dimension(dimSums(equStock, dim = 3.1), add = "landuse", nm = "total"))
pEquStock <- mbind(pEquStock, add_dimension(dimSums(pEquStock, dim = 3.1), add = "landuse", nm = "total"))

somShare <- somStock / natStock
unit <- "(tC/tC)"
zeroOrderName <- "Resources|Soil Carbon|Actual|Carbon Share|SOC in top 30 cm"
somShare <- somStock / natStock
# replace NAs with 1, as the weights are zero for this country the value does not matter
somShare <- toolConditionalReplace(somShare, "is.na()", replaceby = 1)
out <- mbind(setNames(somShare[, , "total"], paste0(zeroOrderName, " ", unit)),
setNames(somShare[, , "crop"], paste0(zeroOrderName, "|+|Cropland Soils ", unit)),
setNames(somShare[, , "natveg"], paste0(zeroOrderName, "|+|Noncropland Soils ", unit)))
Expand All @@ -47,6 +49,8 @@ calcValidSOCShare <- function(datasource = "histSOCbudget") {

zeroOrderName <- "Resources|Soil Carbon|Target|Carbon Share|SOC in top 30 cm"
equSomShare <- equStock / pEquStock
# replace NAs with 1, as the weights are zero for this country the value does not matter
equSomShare <- toolConditionalReplace(equSomShare, "is.na()", replaceby = 1)
out <- mbind(out,
setNames(equSomShare[, , "total"], paste0(zeroOrderName, " ", unit)),
setNames(equSomShare[, , "crop"], paste0(zeroOrderName, "|+|Cropland Soils ", unit)),
Expand Down
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.59.0**
R package **mrvalidation**, version **2.59.1**

[![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.59.0, <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.59.1, <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.59.0},
note = {R package version 2.59.1},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
Expand Down

0 comments on commit b9ff29e

Please sign in to comment.