From 9a78ac59ac6e4030f6b40c7b57d67c7daccf038e Mon Sep 17 00:00:00 2001 From: florianh Date: Mon, 27 May 2024 17:13:06 +0200 Subject: [PATCH] update emisCO2 --- .buildlibrary | 2 +- CITATION.cff | 2 +- DESCRIPTION | 2 +- R/emisCO2.R | 39 ++++++--------------------------------- README.md | 6 +++--- 5 files changed, 12 insertions(+), 39 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 7a3bbe8..c0552e3 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4431010' +ValidationKey: '4450880' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index f2ccaa7..7390d49 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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.2.3 +version: 2.2.4 date-released: '2024-05-27' abstract: Common output routines for extracting results from the MAgPIE framework (versions 4.x). diff --git a/DESCRIPTION b/DESCRIPTION index 0816ffd..f52b9db 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: magpie4 Title: MAgPIE outputs R package for MAgPIE version 4.x -Version: 2.2.3 +Version: 2.2.4 Date: 2024-05-27 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), diff --git a/R/emisCO2.R b/R/emisCO2.R index df49c74..b23095a 100644 --- a/R/emisCO2.R +++ b/R/emisCO2.R @@ -75,26 +75,6 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas", return(x) } - .reorder <- function(x) { - a <- getSets(x) - if(a[names(a)=="d3.1"]=="ac") { - a2 <- a - a2[names(a2)=="d3.1"] <- a[names(a)=="d3.2"] - a2[names(a2)=="d3.2"] <- a[names(a)=="d3.1"] - y <- new.magpie(getCells(x),getYears(x),getNames(x,dim=a2[names(a2)=="d3.1"]),fill=0) - names(dimnames(y))[3] <- a2[names(a2)=="d3.1"] - y <- add_dimension(y,3.2,a2[names(a2)=="d3.2"],getNames(x,dim=a2[names(a2)=="d3.2"])) - if(length(a2[names(a2)=="d3.3"])>0) { - y <- add_dimension(y,3.3,a2[names(a2)=="d3.3"],getNames(x,dim=a2[names(a2)=="d3.3"])) - } - names(dimnames(y))[1] <- names(dimnames(x))[1] - names(dimnames(y))[2] <- names(dimnames(x))[2] - y[,,] <- x - return(y) - } - return(x) - } - ### # compose list of total area per land type, compartment composeAreas <- function() { @@ -112,7 +92,6 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas", other <- readGDX(gdx, "ov_land_other", select = list(type = "level"), react = "silent") if(!is.null(other)) { - other <- .reorder(other) getSets(other)["d3.1"] <- "land" } else { other <- readGDX(gdx, "ov35_other", select = list(type = "level")) @@ -170,9 +149,9 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas", other <- readGDX(gdx, "ov_land_other", select = list(type = "level"), react = "silent") if(!is.null(other)) { other <- readGDX(gdx, "p35_carbon_density_other", react = "silent") - other <- .reorder(other) getSets(other)["d3.1"] <- "land" other <- other[, years, ] + #other[,,"youngsecdf"][,,"ac0"] <- other[,,"othernat"][,,"ac0"] } else { other <- readGDX(gdx, "pm_carbon_density_ac")[, years, ] other <- add_dimension(other, dim = 3.1, add = "land", nm = "other") @@ -385,10 +364,10 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas", densityMtC <- densities$other[, , agPools] p35_maturesecdf <- readGDX(gdx,"p35_maturesecdf", react = "silent") if(!is.null(p35_maturesecdf)) { - areaBefore <- .reorder(readGDX(gdx, "p35_land_other")) - areaAfter <- .reorder(readGDX(gdx, "ov_land_other", select = list(type = "level"))) + areaBefore <- readGDX(gdx, "p35_land_other") + areaAfter <- readGDX(gdx, "ov_land_other", select = list(type = "level")) reductionMha <- .changeAC(areaBefore, areaAfter, mode = "reduction") - harvestMha <- .reorder(readGDX(gdx, "ov35_hvarea_other", select = list(type = "level"), react = "silent")) + harvestMha <- readGDX(gdx, "ov35_hvarea_other", select = list(type = "level"), react = "silent") } else { densityMtC <- densities$other[, , agPools] reductionMha <- readGDX(gdx, "ov35_other_reduction", select = list(type = "level"), react = "silent") @@ -702,14 +681,8 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas", # --- Ensure that area - subcomponent residual is nearly zero # Crop and past are not accounted for in grossEmissions residual <- output[, , c("crop", "past"), invert = TRUE][, , "residual"] - # saveRDS(residual,"residual.rds") - # round(dimSums(residual,dim=1),6)[,,c("youngsecdf")][,,"litc"] - # round(dimSums(residual,dim=1),6)[,,c("youngsecdf")][,,"vegc"] - p35_forest_recovery_area <- readGDX(gdx,"p35_forest_recovery_area", react = "silent") - if (is.null(p35_forest_recovery_area)) { - if (any(residual > 1e-06, na.rm = TRUE)) { - stop("Inappropriately high residuals in land use sub-components in magpie4::emisCO2") - } + if (any(residual > 1e-06, na.rm = TRUE)) { + stop("Inappropriately high residuals in land use sub-components in magpie4::emisCO2") } # --- Ensure that total net emissions are additive of cc, lu, and interaction (now included in cc) diff --git a/README.md b/README.md index aa58047..00c4a18 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MAgPIE outputs R package for MAgPIE version 4.x -R package **magpie4**, version **2.2.3** +R package **magpie4**, version **2.2.4** [![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) @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky , R package version 2.2.3, . +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 , R package version 2.2.4, . A BibTeX entry for LaTeX users is @@ -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.2.3}, + note = {R package version 2.2.4}, url = {https://github.com/pik-piam/magpie4}, doi = {10.5281/zenodo.1158582}, }