diff --git a/.buildlibrary b/.buildlibrary index eaff75e..a1d8684 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '3946000' +ValidationKey: '4147920' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index 34a731e..3a7c13d 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: 'mrsoil: MadRat Soil Organic Carbon Budget Library' -version: 2.0.0 -date-released: '2024-01-08' +version: 2.1.0 +date-released: '2024-01-30' abstract: This packages provides functions for soil organic carbon budget for mineral soils using the steady-state method (Tier 2) of the 2019 Refinement to the 2006 IPP Guidelines for National Greenhouse Gas Inventories. diff --git a/DESCRIPTION b/DESCRIPTION index 513789e..e8e82c8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mrsoil Type: Package Title: MadRat Soil Organic Carbon Budget Library -Version: 2.0.0 -Date: 2024-01-08 +Version: 2.1.0 +Date: 2024-01-30 Authors@R: c(person("Kristine", "Karstens", email = "karstens@pik-potsdam.de", role = c("aut","cre")), person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = "aut")) Description: This packages provides functions for soil organic carbon budget for mineral soils using the steady-state method (Tier 2) of the 2019 Refinement to the 2006 IPP Guidelines for National Greenhouse Gas Inventories. @@ -23,7 +23,7 @@ URL: https://github.com/pik-piam/mrsoil, https://doi.org/10.5281/zenodo.4317933 BugReports: https://github.com/pik-piam/mrsoil/issues Encoding: UTF-8 LazyData: no -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Suggests: knitr, rmarkdown, diff --git a/R/calcCarbonInputMultiplier.R b/R/calcCarbonInputMultiplier.R index 3766cdf..153c217 100644 --- a/R/calcCarbonInputMultiplier.R +++ b/R/calcCarbonInputMultiplier.R @@ -38,7 +38,7 @@ calcCarbonInputMultiplier <- function() { setNames(param[, , generic] / c2dm, paste0("generic.", gsub("_dm", "", getNames(param, dim = 2))))) - # calculate carbon input multipliers + # calculate carbon input multipliers for crop-related inputs out <- toolCarbonInputMultiplier(inputProp = inputProp, soilParam = soilParam, f4act2slo = f4act2slo, @@ -48,6 +48,7 @@ calcCarbonInputMultiplier <- function() { weight <- mbind(dimSums(weight, dim = 3.1), setNames(dimSums(weight, dim = 3), "generic"), collapseNames(calcOutput("CarbonManure", aggregate = FALSE)[, "y1995", "c"])) + weight <- weight + 10^-10 # important for empty categories such as betr, begr getSets(out, fulldim = FALSE)[1] <- "x.y.iso" getSets(weight, fulldim = FALSE)[1] <- "x.y.iso" @@ -56,6 +57,6 @@ calcCarbonInputMultiplier <- function() { weight = weight, unit = "tC per ha", description = "Carbon input multiplier in tonnes carbon per hectare/ tonnes carbon per hectare - to all carbon subpools for different tillage and input types", + to all carbon subpools for different tillage and input (manure and residue) types", isocountries = FALSE)) } diff --git a/R/calcLitterSoilinput.R b/R/calcLitterSoilinput.R new file mode 100644 index 0000000..4f59ec6 --- /dev/null +++ b/R/calcLitterSoilinput.R @@ -0,0 +1,50 @@ +#' @title calcLitterSoilinput +#' @description Calculates Carbon Input from litter to the soil pools of the three pool model (Tier 2 IPCC) +#' +#' @param lpjmlNatveg Switch between LPJmL natveg versionstop +#' @param climatetype Switch between different climate scenarios +#' @param fixFpc if TRUE using fixed (old) fpc data +#' +#' @return List of magpie object with results on cellular level, weight on cellular level, unit and description. +#' @author Kristine Karstens +#' @examples +#' \dontrun{ +#' calcOutput("calcLitterSoilinput", aggregate = FALSE) +#' } + +calcLitterSoilinput <- function(lpjmlNatveg = "LPJmL4_for_MAgPIE_44ac93de", + climatetype = "GSWP3-W5E5:historical", + fixFpc = FALSE) { + + # Load soil parameter collection + soilParam <- readSource("IPCCSoil", convert = FALSE) + # Load fractional transfer coefficients for active to slow (sand fraction depending) + f4act2slo <- calcOutput("TransferActive2Slow", aggregate = FALSE) + # Stabilization efficiencies for structural decay products entering the active pool + # for natural vegetation is no tillage + f2struc2act <- collapseDim(soilParam[, , "f2_nt"]) + + litter <- calcOutput("CarbonLitter", lpjmlNatveg = lpjmlNatveg, climatetype = climatetype, + mode = "magpieInput", fixFpc = fixFpc, aggregate = FALSE) + + alpha <- dimSums(toolCarbonInputMultiplier(inputProp = litter[, , c("LC", "NC")], + soilParam = soilParam, + f4act2slo = f4act2slo, + f2struc2act = f2struc2act) * + collapseDim(litter[, , "c"]), dim = 3.2) + + alpha <- toolConditionalReplace(alpha, conditions = c("is.na()", "<0", "is.infinite()"), replaceby = 0) + + weight <- calcOutput("LanduseInitialisation", aggregate = FALSE, cellular = TRUE, years = "y1995") + weight <- collapseDim(dimSums(weight[, , "crop", invert = TRUE], dim = 3)) + + getSets(out, fulldim = FALSE)[1] <- "x.y.iso" + getSets(weight, fulldim = FALSE)[1] <- "x.y.iso" + + return(list(x = out, + weight = weight, + unit = "tC per ha", + description = paste0("Litter C input to the soil pools of the 3-pool-model for natural vegetation"), + min = 0, + isocountries = FALSE)) +} diff --git a/README.md b/README.md index 4fed0a9..6d79ce2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat Soil Organic Carbon Budget Library -R package **mrsoil**, version **2.0.0** +R package **mrsoil**, version **2.1.0** [![CRAN status](https://www.r-pkg.org/badges/version/mrsoil)](https://cran.r-project.org/package=mrsoil) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4317933.svg)](https://doi.org/10.5281/zenodo.4317933) [![R build status](https://github.com/pik-piam/mrsoil/workflows/check/badge.svg)](https://github.com/pik-piam/mrsoil/actions) [![codecov](https://codecov.io/gh/pik-piam/mrsoil/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrsoil) [![r-universe](https://pik-piam.r-universe.dev/badges/mrsoil)](https://pik-piam.r-universe.dev/builds) @@ -38,7 +38,7 @@ In case of questions / problems please contact Kristine Karstens , R package version 2.0.0, . +Karstens K, Dietrich J (2024). _mrsoil: MadRat Soil Organic Carbon Budget Library_. doi:10.5281/zenodo.4317933 , R package version 2.1.0, . A BibTeX entry for LaTeX users is @@ -47,7 +47,7 @@ A BibTeX entry for LaTeX users is title = {mrsoil: MadRat Soil Organic Carbon Budget Library}, author = {Kristine Karstens and Jan Philipp Dietrich}, year = {2024}, - note = {R package version 2.0.0}, + note = {R package version 2.1.0}, doi = {10.5281/zenodo.4317933}, url = {https://github.com/pik-piam/mrsoil}, } diff --git a/man/calcLitterSoilinput.Rd b/man/calcLitterSoilinput.Rd new file mode 100644 index 0000000..14a812d --- /dev/null +++ b/man/calcLitterSoilinput.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcLitterSoilinput.R +\name{calcLitterSoilinput} +\alias{calcLitterSoilinput} +\title{calcLitterSoilinput} +\usage{ +calcLitterSoilinput( + lpjmlNatveg = "LPJmL4_for_MAgPIE_44ac93de", + climatetype = "GSWP3-W5E5:historical", + fixFpc = FALSE +) +} +\arguments{ +\item{lpjmlNatveg}{Switch between LPJmL natveg versionstop} + +\item{climatetype}{Switch between different climate scenarios} + +\item{fixFpc}{if TRUE using fixed (old) fpc data} +} +\value{ +List of magpie object with results on cellular level, weight on cellular level, unit and description. +} +\description{ +Calculates Carbon Input from litter to the soil pools of the three pool model (Tier 2 IPCC) +} +\examples{ +\dontrun{ +calcOutput("calcLitterSoilinput", aggregate = FALSE) +} +} +\author{ +Kristine Karstens +}