Skip to content

Commit 9a78ac5

Browse files
committed
update emisCO2
1 parent b1c089e commit 9a78ac5

File tree

5 files changed

+12
-39
lines changed

5 files changed

+12
-39
lines changed

.buildlibrary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ValidationKey: '4431010'
1+
ValidationKey: '4450880'
22
AutocreateReadme: yes
33
AcceptedWarnings:
44
- 'Warning: package ''.*'' was built under R version'

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cff-version: 1.2.0
22
message: If you use this software, please cite it using the metadata from this file.
33
type: software
44
title: 'magpie4: MAgPIE outputs R package for MAgPIE version 4.x'
5-
version: 2.2.3
5+
version: 2.2.4
66
date-released: '2024-05-27'
77
abstract: Common output routines for extracting results from the MAgPIE framework
88
(versions 4.x).

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: magpie4
33
Title: MAgPIE outputs R package for MAgPIE version 4.x
4-
Version: 2.2.3
4+
Version: 2.2.4
55
Date: 2024-05-27
66
Authors@R: c(
77
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),

R/emisCO2.R

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,6 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas",
7575
return(x)
7676
}
7777

78-
.reorder <- function(x) {
79-
a <- getSets(x)
80-
if(a[names(a)=="d3.1"]=="ac") {
81-
a2 <- a
82-
a2[names(a2)=="d3.1"] <- a[names(a)=="d3.2"]
83-
a2[names(a2)=="d3.2"] <- a[names(a)=="d3.1"]
84-
y <- new.magpie(getCells(x),getYears(x),getNames(x,dim=a2[names(a2)=="d3.1"]),fill=0)
85-
names(dimnames(y))[3] <- a2[names(a2)=="d3.1"]
86-
y <- add_dimension(y,3.2,a2[names(a2)=="d3.2"],getNames(x,dim=a2[names(a2)=="d3.2"]))
87-
if(length(a2[names(a2)=="d3.3"])>0) {
88-
y <- add_dimension(y,3.3,a2[names(a2)=="d3.3"],getNames(x,dim=a2[names(a2)=="d3.3"]))
89-
}
90-
names(dimnames(y))[1] <- names(dimnames(x))[1]
91-
names(dimnames(y))[2] <- names(dimnames(x))[2]
92-
y[,,] <- x
93-
return(y)
94-
}
95-
return(x)
96-
}
97-
9878
###
9979
# compose list of total area per land type, compartment
10080
composeAreas <- function() {
@@ -112,7 +92,6 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas",
11292

11393
other <- readGDX(gdx, "ov_land_other", select = list(type = "level"), react = "silent")
11494
if(!is.null(other)) {
115-
other <- .reorder(other)
11695
getSets(other)["d3.1"] <- "land"
11796
} else {
11897
other <- readGDX(gdx, "ov35_other", select = list(type = "level"))
@@ -170,9 +149,9 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas",
170149
other <- readGDX(gdx, "ov_land_other", select = list(type = "level"), react = "silent")
171150
if(!is.null(other)) {
172151
other <- readGDX(gdx, "p35_carbon_density_other", react = "silent")
173-
other <- .reorder(other)
174152
getSets(other)["d3.1"] <- "land"
175153
other <- other[, years, ]
154+
#other[,,"youngsecdf"][,,"ac0"] <- other[,,"othernat"][,,"ac0"]
176155
} else {
177156
other <- readGDX(gdx, "pm_carbon_density_ac")[, years, ]
178157
other <- add_dimension(other, dim = 3.1, add = "land", nm = "other")
@@ -385,10 +364,10 @@ emisCO2 <- function(gdx, file = NULL, level = "cell", unit = "gas",
385364
densityMtC <- densities$other[, , agPools]
386365
p35_maturesecdf <- readGDX(gdx,"p35_maturesecdf", react = "silent")
387366
if(!is.null(p35_maturesecdf)) {
388-
areaBefore <- .reorder(readGDX(gdx, "p35_land_other"))
389-
areaAfter <- .reorder(readGDX(gdx, "ov_land_other", select = list(type = "level")))
367+
areaBefore <- readGDX(gdx, "p35_land_other")
368+
areaAfter <- readGDX(gdx, "ov_land_other", select = list(type = "level"))
390369
reductionMha <- .changeAC(areaBefore, areaAfter, mode = "reduction")
391-
harvestMha <- .reorder(readGDX(gdx, "ov35_hvarea_other", select = list(type = "level"), react = "silent"))
370+
harvestMha <- readGDX(gdx, "ov35_hvarea_other", select = list(type = "level"), react = "silent")
392371
} else {
393372
densityMtC <- densities$other[, , agPools]
394373
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",
702681
# --- Ensure that area - subcomponent residual is nearly zero
703682
# Crop and past are not accounted for in grossEmissions
704683
residual <- output[, , c("crop", "past"), invert = TRUE][, , "residual"]
705-
# saveRDS(residual,"residual.rds")
706-
# round(dimSums(residual,dim=1),6)[,,c("youngsecdf")][,,"litc"]
707-
# round(dimSums(residual,dim=1),6)[,,c("youngsecdf")][,,"vegc"]
708-
p35_forest_recovery_area <- readGDX(gdx,"p35_forest_recovery_area", react = "silent")
709-
if (is.null(p35_forest_recovery_area)) {
710-
if (any(residual > 1e-06, na.rm = TRUE)) {
711-
stop("Inappropriately high residuals in land use sub-components in magpie4::emisCO2")
712-
}
684+
if (any(residual > 1e-06, na.rm = TRUE)) {
685+
stop("Inappropriately high residuals in land use sub-components in magpie4::emisCO2")
713686
}
714687

715688
# --- Ensure that total net emissions are additive of cc, lu, and interaction (now included in cc)

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MAgPIE outputs R package for MAgPIE version 4.x
22

3-
R package **magpie4**, version **2.2.3**
3+
R package **magpie4**, version **2.2.4**
44

55
[![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)
66

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

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

42-
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.2.3, <https://github.com/pik-piam/magpie4>.
42+
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.2.4, <https://github.com/pik-piam/magpie4>.
4343

4444
A BibTeX entry for LaTeX users is
4545

@@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
4848
title = {magpie4: MAgPIE outputs R package for MAgPIE version 4.x},
4949
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},
5050
year = {2024},
51-
note = {R package version 2.2.3},
51+
note = {R package version 2.2.4},
5252
url = {https://github.com/pik-piam/magpie4},
5353
doi = {10.5281/zenodo.1158582},
5454
}

0 commit comments

Comments
 (0)