diff --git a/.buildlibrary b/.buildlibrary index c228547..01d893a 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,7 +1,8 @@ -ValidationKey: '4207815' +ValidationKey: '4360620' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' AcceptedNotes: unable to verify current time AutocreateReadme: yes allowLinterWarnings: yes +enforceVersionUpdate: no diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 870f216..f6ea5d4 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -23,7 +23,6 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: extra-packages: | - gamstransfer=?ignore any::lucode2 any::covr any::madrat @@ -36,7 +35,7 @@ jobs: # gms, goxygen, GDPuc) will usually have an outdated binary version # available; by using extra-packages we get the newest version - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: 3.9 @@ -49,6 +48,11 @@ jobs: shell: Rscript {0} run: lucode2:::validkey(stopIfInvalid = TRUE) + - name: Verify that lucode2::buildLibrary was successful + if: github.event_name == 'pull_request' + shell: Rscript {0} + run: lucode2:::isVersionUpdated() + - name: Checks shell: Rscript {0} run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f13466..243f46a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/CITATION.cff b/CITATION.cff index 05260ea..052ada8 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.1.3 -date-released: '2024-02-02' +version: 2.2.0 +date-released: '2024-04-08' 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 67566b0..c6fb17c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mrsoil Type: Package Title: MadRat Soil Organic Carbon Budget Library -Version: 2.1.3 -Date: 2024-02-02 +Version: 2.2.0 +Date: 2024-04-08 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. diff --git a/R/calcCarbonInputMultiplier.R b/R/calcCarbonInputMultiplier.R index 153c217..db1b75d 100644 --- a/R/calcCarbonInputMultiplier.R +++ b/R/calcCarbonInputMultiplier.R @@ -3,6 +3,8 @@ #' using the steady-state method (Tier 2) of the 2019 Refinement to the 2006 IPP Guidelines #' for National Greenhouse Gas Inventories #' +#' @param inputType switch between 'kcr' (default), or 'kli', 'generic' +#' #' @return magpie object on choosen resolution #' @author Kristine Karstens #' @@ -13,7 +15,7 @@ #' #' @importFrom magpiesets findset -calcCarbonInputMultiplier <- function() { +calcCarbonInputMultiplier <- function(inputType = "kcr") { soilParam <- readSource("IPCCSoil", convert = FALSE) @@ -23,20 +25,23 @@ calcCarbonInputMultiplier <- function() { f2struc2act <- setNames(soilParam[, , tillage2param], names(tillage2param)) f4act2slo <- calcOutput("TransferActive2Slow", aggregate = FALSE) - inputProp <- NULL - # get lignin to c and nitrogen to c values for all residues classes - inputProp <- mbind(inputProp, - calcOutput("ParamResidues", input = "IPCC+woody", aggregate = FALSE)) - # get lignin to c and nitrogen to c values for all manure classes - inputProp <- mbind(inputProp, - calcOutput("ParamManure", input = "IPCC", aggregate = FALSE)) - # get lignin to c and nitrogen to c values for generic input classes - param <- readSource("IPCC", subtype = "residues_table5p5b", convert = FALSE) - generic <- "Generic value for crops not indicated below" - c2dm <- 0.45 - inputProp <- mbind(inputProp, - setNames(param[, , generic] / c2dm, - paste0("generic.", gsub("_dm", "", getNames(param, dim = 2))))) + # get lignin to c and nitrogen to c values for input classes + if (inputType == "kcr") { + # get lignin to c and nitrogen to c values for crop type residue classes + inputProp <- calcOutput("ParamResidues", input = "IPCC+woody", aggregate = FALSE) + } else if (inputType == "kli") { + # get lignin to c and nitrogen to c values for all manure classes + inputProp <- calcOutput("ParamManure", input = "IPCC", aggregate = FALSE) + } else if (inputType == "generic") { + # get lignin to c and nitrogen to c values for generic input classes + param <- readSource("IPCC", subtype = "residues_table5p5b", convert = FALSE) + generic <- "Generic value for crops not indicated below" + c2dm <- 0.45 + inputProp <- setNames(param[, , generic] / c2dm, + paste0("generic.", gsub("_dm", "", getNames(param, dim = 2)))) + } else { + stop("inputType setting unknown.") + } # calculate carbon input multipliers for crop-related inputs out <- toolCarbonInputMultiplier(inputProp = inputProp, @@ -44,10 +49,20 @@ calcCarbonInputMultiplier <- function() { f4act2slo = f4act2slo, f2struc2act = f2struc2act) - weight <- collapseNames(calcOutput("ResBiomass", cellular = TRUE, aggregate = FALSE)[, "y1995", "c"]) - weight <- mbind(dimSums(weight, dim = 3.1), - setNames(dimSums(weight, dim = 3), "generic"), - collapseNames(calcOutput("CarbonManure", aggregate = FALSE)[, "y1995", "c"])) + # get weights + if (inputType %in% c("kcr", "generic")) { + + weight <- collapseNames(calcOutput("ResBiomass", cellular = TRUE, aggregate = FALSE)[, "y1995", "c"]) + weight <- ifelse(inputType == "kcr", + dimSums(weight, dim = 3.1), # for kcr + setNames(dimSums(weight, dim = 3), "generic")) # for 'generic' + } else if (inputType == "kli") { + + weight <- collapseNames(calcOutput("CarbonManure", aggregate = FALSE)[, "y1995", "c"]) + } else { + stop("inputType setting unknown.") + } + weight <- weight + 10^-10 # important for empty categories such as betr, begr getSets(out, fulldim = FALSE)[1] <- "x.y.iso" @@ -56,7 +71,7 @@ calcCarbonInputMultiplier <- function() { return(list(x = out, weight = weight, unit = "tC per ha", - description = "Carbon input multiplier in tonnes carbon per hectare/ tonnes carbon per hectare + description = "Carbon input multiplier in tonnes carbon per hectare / tonnes carbon per hectare to all carbon subpools for different tillage and input (manure and residue) types", isocountries = FALSE)) } diff --git a/R/calcSoilCarbon.R b/R/calcSoilCarbon.R index 86b7ce9..033cbfe 100644 --- a/R/calcSoilCarbon.R +++ b/R/calcSoilCarbon.R @@ -40,6 +40,7 @@ calcSoilCarbon <- function(output = "actualstate", landuse)[, , output] getSets(out, fulldim = FALSE)[1] <- "x.y.iso" + out <- collapseDim(out) return(list(x = out, weight = NULL, diff --git a/README.md b/README.md index 2541eb8..198c5d7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MadRat Soil Organic Carbon Budget Library -R package **mrsoil**, version **2.1.3** +R package **mrsoil**, version **2.2.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.1.3, . +Karstens K, Dietrich J (2024). _mrsoil: MadRat Soil Organic Carbon Budget Library_. doi:10.5281/zenodo.4317933 , R package version 2.2.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.1.3}, + note = {R package version 2.2.0}, doi = {10.5281/zenodo.4317933}, url = {https://github.com/pik-piam/mrsoil}, } diff --git a/man/calcCarbonInputMultiplier.Rd b/man/calcCarbonInputMultiplier.Rd index 8d5d565..e89dc4c 100644 --- a/man/calcCarbonInputMultiplier.Rd +++ b/man/calcCarbonInputMultiplier.Rd @@ -4,7 +4,10 @@ \alias{calcCarbonInputMultiplier} \title{calcCarbonInputMulitplier} \usage{ -calcCarbonInputMultiplier() +calcCarbonInputMultiplier(inputType = "kcr") +} +\arguments{ +\item{inputType}{switch between 'kcr' (default), or 'kli', 'generic'} } \value{ magpie object on choosen resolution