Skip to content

Commit

Permalink
bugfix age-class distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
flohump committed Oct 25, 2024
1 parent 66a78ab commit 644897a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '30453908'
ValidationKey: '30512004'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package .* was built under R version'
Expand All @@ -8,3 +8,4 @@ AcceptedNotes:
- includes the non-default packages
allowLinterWarnings: no
enforceVersionUpdate: no
skipCoverage: no
18 changes: 9 additions & 9 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::lucode2
any::covr
any::madrat
any::magclass
any::citation
any::gms
any::goxygen
any::GDPuc
lucode2
covr
madrat
magclass
citation
gms
goxygen
GDPuc
# piam packages also available on CRAN (madrat, magclass, citation,
# gms, goxygen, GDPuc) will usually have an outdated binary version
# available; by using extra-packages we get the newest version
Expand Down Expand Up @@ -63,6 +63,6 @@ jobs:
shell: Rscript {0}
run: |
nonDummyTests <- setdiff(list.files("./tests/testthat/"), c("test-dummy.R", "_snaps"))
if(length(nonDummyTests) > 0) covr::codecov(quiet = FALSE)
if(length(nonDummyTests) > 0 && !lucode2:::loadBuildLibraryConfig()[["skipCoverage"]]) covr::codecov(quiet = FALSE)
env:
NOT_CRAN: "true"
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: 'mrmagpie: madrat based MAgPIE Input Data Library'
version: 1.52.3
date-released: '2024-09-30'
version: 1.52.4
date-released: '2024-10-25'
abstract: Provides functions for MAgPIE country and cellular input data generation.
authors:
- family-names: Karstens
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: mrmagpie
Title: madrat based MAgPIE Input Data Library
Version: 1.52.3
Date: 2024-09-30
Version: 1.52.4
Date: 2024-10-25
Authors@R: c(
person("Kristine", "Karstens", , "[email protected]", role = c("aut", "cre")),
person("Jan Philipp", "Dietrich", , "[email protected]", role = "aut"),
Expand Down
32 changes: 12 additions & 20 deletions R/calcAgeClassDistribution.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#' @title calcAgeClassDistribution
#' @description This function calculates the share of each age class in secondary forests in each
#' MAgPIE simulation cluster based on Global Forest Age Dataset from Poulter et al. 2019
#' @description This function calculates forest area in 15 age classes based on the
#' Global Forest Age Dataset (GFAD) from Poulter et al. 2019
#' @param cells lpjcell for 67420 cells or magpiecell for 59199 cells
#'
#' @return magpie object in cluster resolution
#' @author Abhijeet Mishra, Felicitas Beier
#' @author Abhijeet Mishra, Felicitas Beier, Florian Humpenoeder
#'
#' @examples
#' \dontrun{
Expand All @@ -23,26 +23,18 @@ calcAgeClassDistribution <- function(cells = "lpjcell") {
cb <- toolGetMapping("LPJ_CellBelongingsToCountries.csv",
type = "cell", where = "mrcommons")
cellArea <- (111e3 * 0.5) * (111e3 * 0.5) * cos(cb$lat / 180 * pi)
cellArea <- as.magpie(cellArea, spatial = 1)
cellArea <- as.magpie(cellArea, spatial = 1) / 1e10 # convert to Mha
getItems(cellArea, dim = 1, raw = TRUE) <- paste(mapping$coords, mapping$iso, sep = ".")
getSets(cellArea) <- c("x", "y", "iso", "year", "data")

######################
forestArea <- poulterDataset * cellArea
out <- poulterDataset * cellArea

forestArea <- dimSums(forestArea, dim = 3.1)
out <- dimSums(out, dim = 3.1)

getNames(forestArea) <- gsub(pattern = "X",
replacement = "class",
x = getNames(forestArea))

## Set age classes to 0 where forest does not exist
## Only checking where zero forest area exists
zeroForestArea <- dimSums(forestArea, dim = 3)
acDistribution <- forestArea / zeroForestArea
acDistribution[magclass::where((setYears(zeroForestArea, "y2000")) == 0)$true$regions, , ] <- 0

out <- acDistribution
getNames(out) <- gsub(pattern = "X",
replacement = "class",
x = getNames(out))

if (cells == "magpiecell") {
out <- toolCoord2Isocell(out, cells = cells)
Expand All @@ -51,8 +43,8 @@ calcAgeClassDistribution <- function(cells = "lpjcell") {

return(list(x = out,
weight = cellArea,
unit = "1",
description = "Fraction of each age class in secondary forest from each spatially
explicit cell as described in Poulter age classes",
unit = "Mha",
description = "Forest area in 15 age classes based the Global Forest Age
Dataset (GFAD) from Poulter et al. 2019",
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 based MAgPIE Input Data Library

R package **mrmagpie**, version **1.52.3**
R package **mrmagpie**, version **1.52.4**

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

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

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

Karstens K, Dietrich J, Chen D, Windisch M, Alves M, Beier F, Köberle A, v. Jeetze P, Mishra A, Humpenoeder F, Sauer P (2024). _mrmagpie: madrat based MAgPIE Input Data Library_. doi:10.5281/zenodo.4319612 <https://doi.org/10.5281/zenodo.4319612>, R package version 1.52.3, <https://github.com/pik-piam/mrmagpie>.
Karstens K, Dietrich J, Chen D, Windisch M, Alves M, Beier F, Köberle A, v. Jeetze P, Mishra A, Humpenoeder F, Sauer P (2024). _mrmagpie: madrat based MAgPIE Input Data Library_. doi:10.5281/zenodo.4319612 <https://doi.org/10.5281/zenodo.4319612>, R package version 1.52.4, <https://github.com/pik-piam/mrmagpie>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrmagpie: madrat based MAgPIE Input Data Library},
author = {Kristine Karstens and Jan Philipp Dietrich and David Chen and Michael Windisch and Marcos Alves and Felicitas Beier and Alexandre Köberle and Patrick {v. Jeetze} and Abhijeet Mishra and Florian Humpenoeder and Pascal Sauer},
year = {2024},
note = {R package version 1.52.3},
note = {R package version 1.52.4},
url = {https://github.com/pik-piam/mrmagpie},
doi = {10.5281/zenodo.4319612},
}
Expand Down
6 changes: 3 additions & 3 deletions man/calcAgeClassDistribution.Rd

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

0 comments on commit 644897a

Please sign in to comment.