Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '55784700'
ValidationKey: '56029250'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
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: 'mrvalidation: madrat data preparation for validation purposes'
version: 2.70.0
date-released: '2026-07-27'
version: 2.71.0
date-released: '2026-08-10'
abstract: Package contains routines to prepare data for validation exercises.
authors:
- family-names: Bodirsky
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrvalidation
Title: madrat data preparation for validation purposes
Version: 2.70.0
Date: 2026-07-27
Version: 2.71.0
Date: 2026-08-10
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion R/calcValidCarbon.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ calcValidCarbon <- function(datasource = "LPJmL4_for_MAgPIE_44ac93de:GSWP3-W5E5:
stock <- mbind(setNames(soilc, "soilc"), setNames(litc, "litc"), setNames(vegc, "vegc"))
rm(soilc, litc, vegc)

area <- dimSums(calcOutput("LUH3", landuseTypes = "LUH3", irrigation = FALSE,
area <- dimSums(calcOutput("LanduseInitialisation",
cellular = TRUE, years = "y1995",
aggregate = FALSE),
dim = 3)
Expand Down
23 changes: 14 additions & 9 deletions R/calcValidCroparea.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#' @title calcValidCroparea
#'
#' @description Returns historical areas of individual crops. These are derived by
#' correcting harvested areas to match to physical cropland areas. Both these
#' datasets are from FAO. Output is meant to be used for model validation.
#' @description Returns historical areas of individual crops, meant to be used for
#' model validation. The default source is the madrat croparea preprocessing, which
#' harmonises LandInG against LUH and calibrates it to LanduseInitialisation cropland;
#' it is no longer FAOSTAT, so the series is labelled accordingly rather than as "FAO".
#' Ostberg2023 is a slightly modified version of
#' https://gmd.copernicus.org/articles/16/3375/2023/gmd-16-3375-2023-assets.html
#'
#' @param datasource "FAO": croparea according to FAOSTAT,
#' @param datasource "MadratLandInGLUH": croparea as returned by calcCroparea, i.e.
#' LandInG harmonised against LUH and calibrated
#' to LanduseInitialisation cropland
#' "ostberg2023": croparea according to LandInG data harmonization
#' by Ostberg et al. (2023)
#' "FAOfallow": fallow land according to FAOSTAT
#' by Ostberg et al. (2023), uncorrected
#' "FAOfallow": fallow land according to FAOSTAT
#' @param detail TRUE: data provided for different crop types, FALSE: aggregated data
#'
#' @return magpie object
Expand All @@ -18,9 +21,9 @@
#' @importFrom magclass getNames
#'

calcValidCroparea <- function(datasource = "FAO", detail = FALSE) {
calcValidCroparea <- function(datasource = "MadratLandInGLUH", detail = FALSE) {

if (datasource == "FAO") {
if (datasource == "MadratLandInGLUH") {
data <- calcOutput("Croparea", sectoral = "kcr", physical = TRUE, aggregate = FALSE)
out <- reporthelper(x = data, dim = 3.1,
level_zero_name = "Resources|Land Cover|Cropland|Croparea",
Expand All @@ -32,12 +35,14 @@ calcValidCroparea <- function(datasource = "FAO", detail = FALSE) {
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)

} else if (datasource == "ostberg2023") {
# read in uncorrected/raw data from LandInG toolbox by Sebastian Ostberg
# based on FAO-LUH2v2
data <- calcOutput("CropareaLandInG", aggregate = FALSE)
croparea <- reporthelper(x = data, dim = 3.1,
level_zero_name = "Resources|Land Cover|Cropland|Croparea",
detail = detail)
croparea <- summationhelper(croparea, sep = "+")
fallow <- setNames(calcOutput("FallowLand",
fallow <- setNames(calcOutput("Fallow",
aggregate = FALSE,
cellular = FALSE),
paste("Resources|Land Cover|Cropland|+|",
Expand Down
37 changes: 19 additions & 18 deletions R/calcValidCropareaDiversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ calcValidCropareaDiversity <- function(index = "shannon", groupdiv = "agg1") {
area <- readSource("LandInG", subtype = "harvestedArea")
area <- area[, , c("pasture"), invert = TRUE]
area <- collapseNames(area[, , "irrigated"]) + collapseNames(area[, , "rainfed"])
fallow <- calcOutput("FallowLand", aggregate = FALSE, cellular = TRUE)
fallow <- calcOutput("Fallow", aggregate = FALSE, cellular = TRUE)
fallow <- setNames(fallow, "fallow")
area <- mbind(area, fallow)
combinedYears <- intersect(getYears(fallow), getYears(area))
area <- mbind(area[, combinedYears, ], fallow[, combinedYears, ])

land <- dimSums(area, dim = 3)

Expand Down Expand Up @@ -89,26 +90,26 @@ calcValidCropareaDiversity <- function(index = "shannon", groupdiv = "agg1") {
)
} else if (groupdiv == "agg2") {
mix <- c(
cellvalue["tece"], #c3
cellvalue["maiz"] + cellvalue["trce"], #c4
cellvalue["rice_pro"], #rice
cellvalue["puls_pro"] + cellvalue["soybean"] + cellvalue["groundnut"], #legumes
cellvalue["begr"] + cellvalue["sugr_cane"] + cellvalue["betr"] + cellvalue["oilpalm"], #plantations
cellvalue["potato"] + cellvalue["cassav_sp"] + cellvalue["sugr_beet"], #roots
cellvalue["rapeseed"] + cellvalue["sunflower"] + cellvalue["cottn_pro"], #non-legume oil crops
rep(cellvalue["fallow"] / 2, 2), #fallow
rep(cellvalue["foddr"] / 2, 2), #foddr
rep(cellvalue["others"] / 5, 5) #fruits vegetables nuts
cellvalue["tece"], # c3
cellvalue["maiz"] + cellvalue["trce"], # c4
cellvalue["rice_pro"], # rice
cellvalue["puls_pro"] + cellvalue["soybean"] + cellvalue["groundnut"], # legumes
cellvalue["begr"] + cellvalue["sugr_cane"] + cellvalue["betr"] + cellvalue["oilpalm"], # plantations
cellvalue["potato"] + cellvalue["cassav_sp"] + cellvalue["sugr_beet"], # roots
cellvalue["rapeseed"] + cellvalue["sunflower"] + cellvalue["cottn_pro"], # non-legume oil crops
rep(cellvalue["fallow"] / 2, 2), # fallow
rep(cellvalue["foddr"] / 2, 2), # foddr
rep(cellvalue["others"] / 5, 5) # fruits vegetables nuts
)
} else if (groupdiv == "agg3") {
mix <- c(
cellvalue["tece"] + cellvalue["maiz"] + cellvalue["trce"] + cellvalue["rice_pro"], #rice
cellvalue["puls_pro"] + cellvalue["soybean"] + cellvalue["groundnut"], #legumes
cellvalue["begr"] + cellvalue["sugr_cane"] + cellvalue["betr"] + cellvalue["oilpalm"], #plantations
cellvalue["tece"] + cellvalue["maiz"] + cellvalue["trce"] + cellvalue["rice_pro"], # rice
cellvalue["puls_pro"] + cellvalue["soybean"] + cellvalue["groundnut"], # legumes
cellvalue["begr"] + cellvalue["sugr_cane"] + cellvalue["betr"] + cellvalue["oilpalm"], # plantations
cellvalue["potato"] + cellvalue["cassav_sp"] + cellvalue["sugr_beet"] +
cellvalue["rapeseed"] + cellvalue["sunflower"] + cellvalue["cottn_pro"] + cellvalue["foddr"], #other
cellvalue["others"], #fruits vegetables nuts
cellvalue["fallow"] #fallow
cellvalue["rapeseed"] + cellvalue["sunflower"] + cellvalue["cottn_pro"] + cellvalue["foddr"], # other
cellvalue["others"], # fruits vegetables nuts
cellvalue["fallow"] # fallow
)
} else {
mix <- cellvalue
Expand Down
3 changes: 2 additions & 1 deletion R/calcValidGridCroparea.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ calcValidGridCroparea <- function(physical = TRUE) {
descName <- "harvested area"
}

out <- calcOutput("Croparea", cellular = TRUE, aggregate = FALSE, physical = physical, irrigation = TRUE)
out <- calcOutput("Croparea", cellular = TRUE, aggregate = FALSE,
physical = physical, irrigation = TRUE)
getNames(out, dim = 1) <- reportingnames(getNames(out, dim = 1))
getNames(out, dim = 2) <- reportingnames(getNames(out, dim = 2))
out <- clean_magpie(out)
Expand Down
4 changes: 2 additions & 2 deletions R/calcValidGridYields.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ calcValidGridYields <- function(datasource = "downscaledFAO", future = NULL, phy
refYear <- "y2010"

out <- calcOutput("YieldsCalibrated", source = c(lpjml = lpjml, isimip = isimip),
climatetype = climatetype, refYear = refYear, cells = "magpiecell",
multicropping = physical, aggregate = FALSE)[, , findset("kcr")]
climatetype = climatetype, refYear = refYear, cells = "lpjcell",
multicropping = FALSE, aggregate = FALSE)[, , findset("kcr")]

getNames(out, dim = 1) <- reportingnames(getNames(out, dim = 1))
getNames(out, dim = 2) <- reportingnames(getNames(out, dim = 2))
Expand Down
21 changes: 14 additions & 7 deletions R/calcValidTau.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#'
#' @description Returns historical land use intensity estimates (tau).
#'
#' @param datasource Currently available: \code{"FAO2012"} (original data set)
#' and \code{"FAOonline"} (projection of tau values from 1995 based on recent FAO yield
#' projections.)
#' @param datasource Currently available: \code{"FAO2012"} (original data set),
#' \code{"FAOonline"} (projection of tau values from 1995 based on recent FAO yield
#' projections) and \code{"MadratLandInGFAOLUH"} (projection from 1995 based on the
#' calcValidYield series, i.e. FAO production over LandInG croparea).
#' @return tau time series
#' @author Jan Philipp Dietrich

Expand Down Expand Up @@ -44,8 +45,13 @@ calcValidTau <- function(datasource = "FAO2012") {
out <- tauHist
description <- "Historic Trends in Agricultural Land Use Intensity Tau based on FAO yield trends (updated)"
sourceName <- "dietrich_et_al_2012_updated"
} else if (datasource == "FAOValidYields") {
cropYields <- calcOutput("ValidYield", aggregate = FALSE)[, , "historical.FAO.Productivity|Yield|+|Crops (t DM/ha)"]
} else if (datasource == "MadratLandInGFAOLUH") {
# the model name is stamped onto the series by calcValidYield, so ask for the
# datasource explicitly and build the subscript from the same string
yieldSource <- "MadratLandInGFAOLUH"
cropYields <- calcOutput("ValidYield", datasource = yieldSource, aggregate = FALSE)
cropYields <- cropYields[, , paste0("historical.", yieldSource,
".Productivity|Yield|+|Crops (t DM/ha)")]
yieldIndex <- collapseDim(cropYields / cropYields[, 1995, ])

# average growth rates of more than 20% per year are assumed to be incorrect
Expand All @@ -58,8 +64,9 @@ calcValidTau <- function(datasource = "FAO2012") {
weight[is.na(tauHist)] <- 0
tauHist[is.na(tauHist)] <- 0
out <- tauHist
description <- "Trends in Agricultural Land Use Intensity Tau based on FAO yield trends from calcValidYield"
sourceName <- "yield validation FAO"
description <- paste("Trends in Agricultural Land Use Intensity Tau based on the",
"calcValidYield series, i.e. FAO production over LandInG croparea")
sourceName <- "yield validation MadratLandInGFAOLUH"
} else {
stop("Unknown datasource chosen in calcValidTau!")
}
Expand Down
86 changes: 0 additions & 86 deletions R/calcValidTauPastr.R

This file was deleted.

Loading