Skip to content

Commit

Permalink
added detailed raw emissions to reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
flohump committed Jul 15, 2024
1 parent 3a9c6eb commit 7d3f122
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '5198859'
ValidationKey: '5218778'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'magpie4: MAgPIE outputs R package for MAgPIE version 4.x'
version: 2.6.1
version: 2.6.2
date-released: '2024-07-15'
abstract: Common output routines for extracting results from the MAgPIE framework
(versions 4.x).
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: magpie4
Title: MAgPIE outputs R package for MAgPIE version 4.x
Version: 2.6.1
Version: 2.6.2
Date: 2024-07-15
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
Expand Down
88 changes: 86 additions & 2 deletions R/reportEmissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,98 @@ reportEmissions <- function(gdx, storageWood = TRUE) {

rawYearlyCO2 <- .calcCO2(.lowpass = 0, .cumulative = FALSE)

if ("other" %in% getNames(rawYearlyCO2$regrowth)) {
otherSet <- "other"
} else {
otherSet <- c("other_othernat", "other_youngsecdf")
}

# nolint start
emissionsReport <- with(rawYearlyCO2, mbind(
emissionsReport,

setNames(totalNetFlux, "Emissions|CO2|Land RAW (Mt CO2/yr)"),
setNames(eLanduseChange, "Emissions|CO2|Land RAW|+|Land-use Change RAW (Mt CO2/yr)"),
setNames(eClimateChange, "Emissions|CO2|Land RAW|+|Indirect RAW (Mt CO2/yr)")
setNames(eClimateChange, "Emissions|CO2|Land RAW|+|Indirect (Mt CO2/yr)"),
setNames(eLanduseChange, "Emissions|CO2|Land RAW|+|Land-use Change (Mt CO2/yr)"),

# Gross emissions - Deforestation
setNames(dimSums(deforestation, dim = 3), "Emissions|CO2|Land RAW|Land-use Change|+|Deforestation (Mt CO2/yr)"),
setNames(deforestation[, , "primforest"], "Emissions|CO2|Land RAW|Land-use Change|Deforestation|+|Primary forests (Mt CO2/yr)"),
setNames(deforestation[, , "crop_treecover"], "Emissions|CO2|Land RAW|Land-use Change|Deforestation|+|Cropland Tree Cover (Mt CO2/yr)"),
setNames(deforestation[, , "secdforest"], "Emissions|CO2|Land RAW|Land-use Change|Deforestation|+|Secondary forests (Mt CO2/yr)"),
setNames(deforestation[, , "forestry_plant"], "Emissions|CO2|Land RAW|Land-use Change|Deforestation|+|Forestry plantations (Mt CO2/yr)"),

# Gross emissions - Degradataion
setNames(dimSums(degradation, dim = 3), "Emissions|CO2|Land RAW|Land-use Change|+|Forest degradation (Mt CO2/yr)"),
setNames(degradation[, , "primforest"], "Emissions|CO2|Land RAW|Land-use Change|Forest degradation|+|Primary forests (Mt CO2/yr)"),
setNames(degradation[, , "secdforest"], "Emissions|CO2|Land RAW|Land-use Change|Forest degradation|+|Secondary forests (Mt CO2/yr)"),

# Gross emissions - Other conversion
setNames(dimSums(other_conversion[, , otherSet], dim = 3), "Emissions|CO2|Land RAW|Land-use Change|+|Other land conversion (Mt CO2/yr)"),

# Regrowth
setNames(dimSums(regrowth, dim = 3), "Emissions|CO2|Land RAW|Land-use Change|+|Regrowth (Mt CO2/yr)"),
setNames(regrowth[, , "forestry_aff"], "Emissions|CO2|Land RAW|Land-use Change|Regrowth|+|CO2-price AR (Mt CO2/yr)"),
setNames(regrowth[, , "forestry_ndc"], "Emissions|CO2|Land RAW|Land-use Change|Regrowth|+|NPI_NDC AR (Mt CO2/yr)"),
setNames(regrowth[, , "forestry_plant"], "Emissions|CO2|Land RAW|Land-use Change|Regrowth|+|Timber Plantations (Mt CO2/yr)"),
setNames(regrowth[, , "crop_treecover"], "Emissions|CO2|Land RAW|Land-use Change|Regrowth|+|Cropland Tree Cover (Mt CO2/yr)"),
setNames(regrowth[, , "secdforest"], "Emissions|CO2|Land RAW|Land-use Change|Regrowth|+|Secondary Forest (Mt CO2/yr)"),
setNames(dimSums(regrowth[, , otherSet], dim = 3), "Emissions|CO2|Land RAW|Land-use Change|Regrowth|+|Other Land (Mt CO2/yr)"),

# Gross emissions - Peatland
setNames(peatland, "Emissions|CO2|Land RAW|Land-use Change|+|Peatland (Mt CO2/yr)"),

# SOM
setNames(dimSums(som, dim = 3), "Emissions|CO2|Land RAW|Land-use Change|+|SOM (Mt CO2/yr)"),

# residual
setNames(dimSums(residual, dim = 3), "Emissions|CO2|Land RAW|Land-use Change|+|Residual (Mt CO2/yr)"),

# Carbon pools
setNames(totalPools, paste0("Emissions|CO2|Land RAW|++|", getNames(totalPools), " (Mt CO2/yr)")),
setNames(climatePools, paste0("Emissions|CO2|Land RAW|Indirect|++|", getNames(climatePools), " (Mt CO2/yr)")),
setNames(landusePools, paste0("Emissions|CO2|Land RAW|Land-use Change|++|", getNames(landusePools), " (Mt CO2/yr)"))

))

# Only attempt to append wood-related reports if the forestry module was activated
if (!is.null(rawYearlyCO2$harvest)) {

emissionsReport <- with(rawYearlyCO2, mbind(
emissionsReport,

setNames(dimSums(harvest, dim = 3) +
emisWoodInflow + emisBuildingInflow, "Emissions|CO2|Land RAW|Land-use Change|+|Timber (Mt CO2/yr)"),
setNames(dimSums(harvest, dim = 3), "Emissions|CO2|Land RAW|Land-use Change|Timber|+|Wood Harvest (Mt CO2/yr)"),
setNames(harvest[, , "forestry_plant"], "Emissions|CO2|Land RAW|Land-use Change|Timber|Wood Harvest|+|Timber Plantations (Mt CO2/yr)"),
setNames(harvest[, , "primforest"], "Emissions|CO2|Land RAW|Land-use Change|Timber|Wood Harvest|+|Primary Forest (Mt CO2/yr)"),
setNames(harvest[, , "secdforest"], "Emissions|CO2|Land RAW|Land-use Change|Timber|Wood Harvest|+|Secondary Forest (Mt CO2/yr)"),
setNames(dimSums(harvest[, , otherSet], dim = 3), "Emissions|CO2|Land RAW|Land-use Change|Timber|Wood Harvest|+|Other Land (Mt CO2/yr)"),
setNames(storage, "Emissions|CO2|Land RAW|Land-use Change|Timber|+|Storage (Mt CO2/yr)"), # carbon stored in wood products + release from wood products
setNames(emisWoodNet, "Emissions|CO2|Land RAW|Land-use Change|Timber|Storage|+|Industrial roundwood (Mt CO2/yr)"), # carbon stored in Industrial roundwood + release from Industrial roundwood
setNames(emisWoodInflow, "Emissions|CO2|Land RAW|Land-use Change|Timber|Storage|Industrial roundwood|Inflow (Mt CO2/yr)"), # carbon stored in Industrial roundwood
setNames(emisWoodOutflow, "Emissions|CO2|Land RAW|Land-use Change|Timber|Storage|Industrial roundwood|Outflow (Mt CO2/yr)"), # slow release from Industrial roundwood
setNames(emisBuildingNet, "Emissions|CO2|Land RAW|Land-use Change|Timber|Storage|+|Buildings (Mt CO2/yr)"), # carbon stored in wood buildings + release from wood buildings
setNames(emisBuildingInflow, "Emissions|CO2|Land RAW|Land-use Change|Timber|Storage|Buildings|Inflow (Mt CO2/yr)"), # carbon stored in wood buildings
setNames(emisBuildingOutflow, "Emissions|CO2|Land RAW|Land-use Change|Timber|Storage|Buildings|Outflow (Mt CO2/yr)") # slow release from wood buildings
))

}

checkEmis <- emissionsReport[, , "Emissions|CO2|Land RAW|+|Land-use Change (Mt CO2/yr)"] -
dimSums(emissionsReport[, , c("Emissions|CO2|Land RAW|Land-use Change|+|Deforestation (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|Forest degradation (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|Other land conversion (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|Regrowth (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|Peatland (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|SOM (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|Residual (Mt CO2/yr)",
"Emissions|CO2|Land RAW|Land-use Change|+|Timber (Mt CO2/yr)")], dim = 3)

if (any(abs(checkEmis) > 1e-03, na.rm = TRUE)) {
warning("CO2 emission sub-categories do not add up to total")
}

# nolint end


Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MAgPIE outputs R package for MAgPIE version 4.x

R package **magpie4**, version **2.6.1**
R package **magpie4**, version **2.6.2**

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

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

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

Bodirsky B, Humpenoeder F, Dietrich J, Stevanovic M, Weindl I, Karstens K, Wang X, Mishra A, Beier F, Breier J, Yalew A, Chen D, Biewald A, Wirth S, von Jeetze P, Leip D, Crawford M, Alves M (2024). _magpie4: MAgPIE outputs R package for MAgPIE version 4.x_. doi:10.5281/zenodo.1158582 <https://doi.org/10.5281/zenodo.1158582>, R package version 2.6.1, <https://github.com/pik-piam/magpie4>.
Bodirsky B, Humpenoeder F, Dietrich J, Stevanovic M, Weindl I, Karstens K, Wang X, Mishra A, Beier F, Breier J, Yalew A, Chen D, Biewald A, Wirth S, von Jeetze P, Leip D, Crawford M, Alves M (2024). _magpie4: MAgPIE outputs R package for MAgPIE version 4.x_. doi:10.5281/zenodo.1158582 <https://doi.org/10.5281/zenodo.1158582>, R package version 2.6.2, <https://github.com/pik-piam/magpie4>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {magpie4: MAgPIE outputs R package for MAgPIE version 4.x},
author = {Benjamin Leon Bodirsky and Florian Humpenoeder and Jan Philipp Dietrich and Miodrag Stevanovic and Isabelle Weindl and Kristine Karstens and Xiaoxi Wang and Abhijeet Mishra and Felicitas Beier and Jannes Breier and Amsalu Woldie Yalew and David Chen and Anne Biewald and Stephen Wirth and Patrick {von Jeetze} and Debbora Leip and Michael Crawford and Marcos Alves},
year = {2024},
note = {R package version 2.6.1},
note = {R package version 2.6.2},
url = {https://github.com/pik-piam/magpie4},
doi = {10.5281/zenodo.1158582},
}
Expand Down

0 comments on commit 7d3f122

Please sign in to comment.