Skip to content

Commit

Permalink
introduce new litter funtion!
Browse files Browse the repository at this point in the history
  • Loading branch information
k4rst3ns committed Jan 31, 2024
1 parent f3c5fb4 commit 6e0913a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
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: '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.
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut","cre")),
person("Jan Philipp", "Dietrich", email = "[email protected]", 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.
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions R/calcCarbonInputMultiplier.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand All @@ -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))
}
50 changes: 50 additions & 0 deletions R/calcLitterSoilinput.R
Original file line number Diff line number Diff line change
@@ -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))
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -38,7 +38,7 @@ In case of questions / problems please contact Kristine Karstens <karstens@pik-p

To cite package **mrsoil** in publications use:

Karstens K, Dietrich J (2024). _mrsoil: MadRat Soil Organic Carbon Budget Library_. doi:10.5281/zenodo.4317933 <https://doi.org/10.5281/zenodo.4317933>, R package version 2.0.0, <https://github.com/pik-piam/mrsoil>.
Karstens K, Dietrich J (2024). _mrsoil: MadRat Soil Organic Carbon Budget Library_. doi:10.5281/zenodo.4317933 <https://doi.org/10.5281/zenodo.4317933>, R package version 2.1.0, <https://github.com/pik-piam/mrsoil>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
Expand Down
33 changes: 33 additions & 0 deletions man/calcLitterSoilinput.Rd

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

0 comments on commit 6e0913a

Please sign in to comment.