Skip to content

Commit 1f66183

Browse files
committed
fix units for soil carbon
1 parent 2530b69 commit 1f66183

17 files changed

+82
-50
lines changed

.buildlibrary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ValidationKey: '4380441'
1+
ValidationKey: '4574470'
22
AcceptedWarnings:
33
- 'Warning: package ''.*'' was built under R version'
44
- 'Warning: namespace ''.*'' is not available and has been replaced'

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exclude: '^tests/testthat/_snaps/.*$'
44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.5.0
6+
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0
77
hooks:
88
- id: check-case-conflict
99
- id: check-json
@@ -15,7 +15,7 @@ repos:
1515
- id: mixed-line-ending
1616

1717
- repo: https://github.com/lorenzwalthert/precommit
18-
rev: v0.4.0
18+
rev: 7910e0323d7213f34275a7a562b9ef0fde8ce1b9 # frozen: v0.4.2
1919
hooks:
2020
- id: parsable-R
2121
- id: deps-in-desc

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cff-version: 1.2.0
22
message: If you use this software, please cite it using the metadata from this file.
33
type: software
44
title: 'mrsoil: MadRat Soil Organic Carbon Budget Library'
5-
version: 2.2.1
6-
date-released: '2024-04-08'
5+
version: 2.3.0
6+
date-released: '2024-06-15'
77
abstract: This packages provides functions for soil organic carbon budget for mineral
88
soils using the steady-state method (Tier 2) of the 2019 Refinement to the 2006
99
IPP Guidelines for National Greenhouse Gas Inventories.

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: mrsoil
22
Type: Package
33
Title: MadRat Soil Organic Carbon Budget Library
4-
Version: 2.2.1
5-
Date: 2024-04-08
4+
Version: 2.3.0
5+
Date: 2024-06-15
66
Authors@R: c(person("Kristine", "Karstens", email = "karstens@pik-potsdam.de", role = c("aut","cre")),
77
person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = "aut"))
88
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.
@@ -11,9 +11,11 @@ Depends:
1111
magclass(>= 5.15.4),
1212
madrat(>= 1.86.0),
1313
mrcommons(>= 0.11.9),
14+
mrlandcore (>= 1.0.0),
1415
mrdrivers(>= 1.0.0)
1516
Imports:
1617
magpiesets,
18+
mstools (>= 0.6.0),
1719
readxl,
1820
lpjclass,
1921
utils,

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import(madrat)
66
import(magclass)
77
import(mrcommons)
88
import(mrdrivers)
9+
import(mrlandcore)
910
importFrom(jsonlite,fromJSON)
1011
importFrom(lpjclass,read.LPJ_input)
1112
importFrom(madrat,toolSubtypeSelect)
@@ -15,6 +16,9 @@ importFrom(magclass,dimCode)
1516
importFrom(magclass,setNames)
1617
importFrom(magpiesets,addLocation)
1718
importFrom(magpiesets,findset)
19+
importFrom(mstools,toolGetMappingCoord2Country)
20+
importFrom(mstools,toolHarmonize2Baseline)
21+
importFrom(mstools,toolSmooth)
1822
importFrom(readxl,read_excel)
1923
importFrom(stats,quantile)
2024
importFrom(utils,download.file)

R/calcDecayFuture.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#'
2323
#' @import madrat
2424
#' @import magclass
25+
#' @importFrom mstools toolSmooth toolHarmonize2Baseline
2526

2627
calcDecayFuture <- function(lpjmlNatveg = "LPJmL4_for_MAgPIE_44ac93de",
2728
climatetype = "GSWP3-W5E5:historical") {

R/calcSoilCarbon.R

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @return magpie object in cellular resolution
55
#' @author Kristine Karstens
66
#'
7-
#' @param output "actualstate" (default), "carbontransfer", "interstate", "naturalstate"
7+
#' @param output "all" (default), "actualstate", "carbontransfer", "interstate", "naturalstate"
88
#' @param lpjmlNatveg Switch between LPJmL natveg versionstop
99
#' @param climatetype Switch between different climate scenarios
1010
#'
@@ -15,36 +15,55 @@
1515
#' @importFrom magclass setNames
1616
#' @importFrom magpiesets findset
1717

18-
calcSoilCarbon <- function(output = "actualstate",
18+
calcSoilCarbon <- function(output = "all",
1919
lpjmlNatveg = "LPJmL4_for_MAgPIE_44ac93de",
2020
climatetype = "GSWP3-W5E5:historical") {
21-
#######################
22-
### Load Data & Ini ###
23-
#######################
24-
25-
# Load Landuse data
26-
landuse <- calcOutput("Landuse", aggregate = FALSE)
27-
soilCarbonSteadyState <- calcOutput("SteadyState", lpjmlNatveg = lpjmlNatveg,
28-
climatetype = climatetype, aggregate = FALSE)
29-
decay <- calcOutput("DecayRaw", lpjmlNatveg = lpjmlNatveg,
30-
climatetype = climatetype, aggregate = FALSE)
31-
soilCarbonInit <- calcOutput("SoilCarbonSpinup", aggregate = FALSE)
32-
33-
######################
34-
### Carbon Cycling ###
35-
######################
36-
37-
out <- toolSoilCarbonCycling(soilCarbonInit,
38-
soilCarbonSteadyState,
39-
decay,
40-
landuse)[, , output]
41-
42-
getSets(out, fulldim = FALSE)[1] <- "x.y.iso"
43-
out <- collapseDim(out)
21+
22+
if (output == "all") {
23+
#######################
24+
### Load Data & Ini ###
25+
#######################
26+
27+
# Load Landuse data
28+
landuse <- calcOutput("Landuse", aggregate = FALSE)
29+
soilCarbonSteadyState <- calcOutput("SteadyState", lpjmlNatveg = lpjmlNatveg,
30+
climatetype = climatetype, aggregate = FALSE)
31+
decay <- calcOutput("DecayRaw", lpjmlNatveg = lpjmlNatveg,
32+
climatetype = climatetype, aggregate = FALSE)
33+
soilCarbonInit <- calcOutput("SoilCarbonSpinup", aggregate = FALSE)
34+
35+
######################
36+
### Carbon Cycling ###
37+
######################
38+
39+
out <- toolSoilCarbonCycling(soilCarbonInit,
40+
soilCarbonSteadyState,
41+
decay,
42+
landuse)
43+
44+
45+
getSets(out, fulldim = FALSE)[1] <- "x.y.iso"
46+
out <- collapseDim(out)
47+
48+
} else if (output %in% c("actualstate", "interstate", "naturalstate")) {
49+
50+
out <- calcOutput("SoilCarbon", aggregate = FALSE, output = "all",
51+
lpjmlNatveg = lpjmlNatveg, climatetype = climatetype)[, , "output"]
52+
landuse <- calcOutput("Landuse", aggregate = FALSE)[, getYears(out), ]
53+
out <- out * landuse
54+
55+
} else if (output == "carbontransfer") {
56+
57+
out <- calcOutput("SoilCarbon", aggregate = FALSE, output = "all",
58+
lpjmlNatveg = lpjmlNatveg, climatetype = climatetype)[, , "output"]
59+
60+
} else {
61+
stop("'output' unknown.")
62+
}
4463

4564
return(list(x = out,
4665
weight = NULL,
47-
unit = "Mt C",
66+
unit = ifelse(output == "all", "tC per ha", "Mt C"),
4867
description = "Carbon budget on croplands for historical period",
4968
isocountries = FALSE)
5069
)

R/calcSoilCarbonSpinup.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ calcSoilCarbonSpinup <- function(lpjmlNatveg = "LPJmL4_for_MAgPIE_44ac93de",
5656

5757
return(list(x = soilCarbonInit,
5858
weight = NULL,
59-
unit = "Mt C",
59+
unit = "tC per ha",
6060
min = 0,
6161
description = "Soil carbon stocks on croplands for starting of the modelling period",
6262
isocountries = FALSE)

R/calcWaterEffectDecomposition.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#' }
2020
#'
2121
#' @importFrom magpiesets findset
22+
#' @importFrom mstools toolGetMappingCoord2Country
2223

2324
calcWaterEffectDecomposition <- function(irrigation = "mixedirrig",
2425
lpjmlNatveg = "LPJmL4_for_MAgPIE_44ac93de",

R/correctPorwolliksGriddedTillage.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @return List of magpie objects with results on cellular level, weight, unit and description.
55
#' @author Kristine Karstens
66
#' @seealso
7-
#' \code{\link[mrcommons]{readLPJmL}},
7+
#' \code{\link[mrlandcore]{readLPJmL_new}},
88
#' \code{\link[lpjclass]{read.LPJ_input}}
99
#' @examples
1010
#' \dontrun{

R/imports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Generated by lucode2: do not edit by hand
22

3-
#' @import magclass madrat mrcommons mrdrivers
3+
#' @import magclass madrat mrcommons mrlandcore mrdrivers
44
NULL

R/readPorwolliksGriddedTillage.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#' @return List of magpie objects with results on cellular level, weight, unit and description.
44
#' @author Kristine Karstens
55
#' @seealso
6-
#' \code{\link[mrcommons]{readLPJmL}},
6+
#' \code{\link[mrlandcore]{readLPJmL_new}},
77
#' \code{\link[lpjclass]{read.LPJ_input}}
88
#' @examples
99
#' \dontrun{

R/toolSoilCarbonCycling.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ toolSoilCarbonCycling <- function(soilCarbonInit, soilCarbonSteadyState, decay,
2929
# cut decay rates above 1
3030
decay[decay > 1] <- 1
3131

32-
# Initialize outputs
32+
# Initialize outputs (by binding 0. year with an object that runs over the full period of years.
33+
# steadystate is here just a place holder for structure, so teh values are set to zero)
3334
soilCarbon <- mbind(collapseDim(soilCarbonInit[, , "actualstate"], dim = 3.1), soilCarbonSteadyState)
3435
soilCarbonNatural <- mbind(collapseDim(soilCarbonInit[, , "naturalstate"], dim = 3.1), soilCarbonSteadyState)
35-
soilCarbon[, years, ] <- 0
36+
soilCarbon[, years, ] <- 0
37+
soilCarbonNatural[, years, ] <- 0
3638
soilCarbonTransfer <- soilCarbonInter <- soilCarbon
3739
soilCarbonTransfer[] <- soilCarbonInter[] <- 0
3840

@@ -55,10 +57,13 @@ toolSoilCarbonCycling <- function(soilCarbonInit, soilCarbonSteadyState, decay,
5557
(soilCarbonSteadyState[, t, ] - soilCarbonInter[, t, ]) * decay[, t, ])
5658

5759
# Calculate counterfactual potential natural vegetation stocks
58-
soilCarbonNatural[, t, ] <- (setYears(soilCarbonNatural[, t - 1, ], t) +
59-
(soilCarbonSteadyState[, t, ] -
60-
setYears(soilCarbonNatural[, t - 1, ], t)) * decay[, t, ])
61-
soilCarbonNatural[, , "crop"] <- 0
60+
n <- "natveg"
61+
soilCarbonNatural[, t, n] <- (setYears(soilCarbonNatural[, t - 1, n], t) +
62+
(soilCarbonSteadyState[, t, n] -
63+
setYears(soilCarbonNatural[, t - 1, n], t)) * decay[, t, n])
64+
# Set crop values to the natveg values to create an output object
65+
# that calculates a full carbon stock of a natveg world, when multiplying with landuse information
66+
soilCarbonNatural[, , "crop"] <- soilCarbonNatural[, , n]
6267

6368
print(t)
6469
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MadRat Soil Organic Carbon Budget Library
22

3-
R package **mrsoil**, version **2.2.1**
3+
R package **mrsoil**, version **2.3.0**
44

55
[![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)
66

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

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

41-
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.2.1, <https://github.com/pik-piam/mrsoil>.
41+
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.3.0, <https://github.com/pik-piam/mrsoil>.
4242

4343
A BibTeX entry for LaTeX users is
4444

@@ -47,7 +47,7 @@ A BibTeX entry for LaTeX users is
4747
title = {mrsoil: MadRat Soil Organic Carbon Budget Library},
4848
author = {Kristine Karstens and Jan Philipp Dietrich},
4949
year = {2024},
50-
note = {R package version 2.2.1},
50+
note = {R package version 2.3.0},
5151
doi = {10.5281/zenodo.4317933},
5252
url = {https://github.com/pik-piam/mrsoil},
5353
}

man/calcSoilCarbon.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/correctPorwolliksGriddedTillage.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/readPorwolliksGriddedTillage.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)