Skip to content

Commit

Permalink
fallowland croparea reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
bodirsky committed Jan 5, 2024
1 parent eacb2a4 commit 82e66a7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '49690966'
ValidationKey: '49909310'
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.52.2
date-released: '2023-12-12'
version: 2.53.0
date-released: '2024-01-05'
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.52.2
Date: 2023-12-12
Version: 2.53.0
Date: 2024-01-05
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
person("Stephen", "Wirth", role = "aut"),
Expand Down
55 changes: 37 additions & 18 deletions R/calcValidCroparea.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
#' calcValidCroparea
#'
#'
#' 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.
#'
#'
#' Ostberg2023 is a slightly modified version of
#' https://gmd.copernicus.org/articles/16/3375/2023/gmd-16-3375-2023-assets.html
#'
#'
#' @param datasource Currently only "FAO" available
#' @param detail how much detail?
#' @return list of magpie object with data and weight
#' @author Ulrich Kreidenweis
#' @importFrom magpiesets reporthelper summationhelper
#' @importFrom magclass getNames
calcValidCroparea <- function(datasource="FAO", detail=F) {
calcValidCroparea <- function(datasource = "FAO", detail = FALSE) {

if(datasource=="FAO"){
data <- calcOutput("Croparea",sectoral="kcr",physical=TRUE,aggregate = FALSE)
out <- reporthelper(x=data, dim=3.1, level_zero_name = "Resources|Land Cover|Cropland", detail = detail)
if (datasource == "FAO") {
data <- calcOutput("Croparea", sectoral = "kcr", physical = TRUE, aggregate = FALSE)
out <- reporthelper(x = data, dim = 3.1, level_zero_name = "Resources|Land Cover|Cropland", detail = detail)
out <- summationhelper(out)
getNames(out) <- paste(getNames(out),"(million ha)",sep=" ")

out <- add_dimension(out, dim=3.1, add="scenario", nm="historical")
out <- add_dimension(out, dim=3.2, add="model", nm=datasource)
} else stop("No data exist for the given datasource!")

return(list(x=out,
weight=NULL,
unit="million ha",
description="")
)
getNames(out) <- paste(getNames(out), "(million ha)", sep = " ")

out <- add_dimension(out, dim = 3.1, add = "scenario", nm = "historical")
out <- add_dimension(out, dim = 3.2, add = "model", nm = datasource)
} else if (datasource == "ostberg2023") {
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",
aggregate = FALSE,
cellular = FALSE),
paste("Resources|Land Cover|Cropland|+|", reportingnames("fallow"), sep = ""))
cropland <- setNames(dimSums(mbind(data, fallow), dim = 3.1),
"Resources|Land Cover|Cropland|+|Croparea")
out <- mbind(cropland, fallow, croparea)
getNames(out) <- paste(getNames(out), "(million ha)", sep = " ")
} else {
stop("No data exist for the given datasource!")
}

return(list(x = out,
weight = NULL,
unit = "million ha",
description = "")
)
}
2 changes: 2 additions & 0 deletions R/fullVALIDATION.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ fullVALIDATION <- function(rev = 0.1) {
# Croparea
calcOutput(type = "ValidCroparea", datasource = "FAO", aggregate = "REG+GLO",
file = valfile, append = TRUE, detail = TRUE, try = TRUE) # ready
calcOutput(type = "ValidCroparea", datasource = "ostberg2023", aggregate = "REG+GLO",
file = valfile, append = TRUE, detail = TRUE, try = TRUE) # ready
# Land Cover
calcOutput(type = "ValidLand", datasource = "FAO_crop_past", aggregate = "REG+GLO",
file = valfile, append = TRUE, try = TRUE) # ready
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# madrat data preparation for validation purposes

R package **mrvalidation**, version **2.52.2**
R package **mrvalidation**, version **2.53.0**

[![CRAN status](https://www.r-pkg.org/badges/version/mrvalidation)](https://cran.r-project.org/package=mrvalidation) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4317826.svg)](https://doi.org/10.5281/zenodo.4317826) [![R build status](https://github.com/pik-piam/mrvalidation/workflows/check/badge.svg)](https://github.com/pik-piam/mrvalidation/actions) [![codecov](https://codecov.io/gh/pik-piam/mrvalidation/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrvalidation) [![r-universe](https://pik-piam.r-universe.dev/badges/mrvalidation)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,16 +39,16 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

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

Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2023). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.52.2, <URL: https://github.com/pik-piam/mrvalidation>.
Bodirsky B, Wirth S, Karstens K, Humpenoeder F, Stevanovic M, Mishra A, Biewald A, Weindl I, Beier F, Chen D, Crawford M, Leip D, Molina Bacca E, Kreidenweis U, W. Yalew A, von Jeetze P, Wang X, Dietrich J, Alves M (2024). _mrvalidation: madrat data preparation for validation purposes_. doi: 10.5281/zenodo.4317826 (URL: https://doi.org/10.5281/zenodo.4317826), R package version 2.53.0, <URL: https://github.com/pik-piam/mrvalidation>.

A BibTeX entry for LaTeX users is

```latex
@Manual{,
title = {mrvalidation: madrat data preparation for validation purposes},
author = {Benjamin Leon Bodirsky and Stephen Wirth and Kristine Karstens and Florian Humpenoeder and Mishko Stevanovic and Abhijeet Mishra and Anne Biewald and Isabelle Weindl and Felicitas Beier and David Chen and Michael Crawford and Debbora Leip and Edna {Molina Bacca} and Ulrich Kreidenweis and Amsalu {W. Yalew} and Patrick {von Jeetze} and Xiaoxi Wang and Jan Philipp Dietrich and Marcos Alves},
year = {2023},
note = {R package version 2.52.2},
year = {2024},
note = {R package version 2.53.0},
doi = {10.5281/zenodo.4317826},
url = {https://github.com/pik-piam/mrvalidation},
}
Expand Down
4 changes: 3 additions & 1 deletion man/calcValidCroparea.Rd

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

0 comments on commit 82e66a7

Please sign in to comment.