Skip to content

Commit

Permalink
added deforestation and emission from other land conversion emission
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimishr committed Sep 7, 2023
1 parent 4b66d95 commit aa67400
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 154 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '2335409377'
ValidationKey: '233715440'
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: 1.191.11
version: 1.192.0
date-released: '2023-09-07'
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: 1.191.11
Version: 1.192.0
Date: 2023-09-07
Authors@R: c(
person("Benjamin Leon", "Bodirsky", , "[email protected]", role = c("aut", "cre")),
Expand Down
62 changes: 61 additions & 1 deletion R/emisCO2.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,60 @@ dummy <- a
emis_degrad <- emis_degrad / timestep_length
emis_degrad[, 1, ] <- NA

## Emission deforestation ----
emis_deforestation <- emis_other_land <- dummy

### Find changes in secdf ---
secdforest <- collapseNames(readGDX(gdx, "ov35_secdforest")[,, "level"])
secdforest_change <- secdforest[, 1,]
secdforest_change[secdforest_change!=0] <- 0
for (t in 2:nyears(secdforest)) {
temp <- setYears(secdforest[, t - 1, ], getYears(secdforest[, t, ])) - secdforest[, t, ]
temp[temp<0] <- 0 # age-classes which increased in future, it does not count as "deforestation"
secdforest_change <- mbind(secdforest_change,temp)
}

### Find changes in primf ----
primforest <- collapseNames(readGDX(gdx, "ov_land")[,,"primforest"][,, "level"])
primforest_change <- primforest[, 1,]
primforest_change[primforest_change!=0] <- 0
for (t in 2:nyears(primforest)) {
temp <- setYears(primforest[, t - 1, ], getYears(primforest[, t, ])) - primforest[, t, ]
temp[temp<0] <- 0 # if primf increased in future, it does not count as "deforestation"
primforest_change <- mbind(primforest_change,temp)
}

### Find changes in other land ----
other <- collapseNames(readGDX(gdx, "ov35_other")[,, "level"])
other_change <- other[, 1,]
other_change[other_change!=0] <- 0
for (t in 2:nyears(other)) {
temp <- setYears(other[, t - 1, ], getYears(other[, t, ])) - other[, t, ]
temp[temp<0] <- 0 # age-classes which increased in future, it does not count as "other land conversion"
other_change <- mbind(other_change,temp)
}

if (all(!is.null(secdforest_change),
!is.null(primforest_change))) {
agPools <- c("vegc", "litc")
pm_carbon_density_ac <- readGDX(gdx, "pm_carbon_density_ac")[, getYears(timestep_length), ]
emis_deforestation[, , "secdforest"][, , agPools] <- dimSums(pm_carbon_density_ac[, , agPools] * secdforest_change, dim = "ac")
fm_carbon_density <- readGDX(gdx, "fm_carbon_density")[, getYears(emis_deforestation), ]
names(dimnames(fm_carbon_density))[2] <- "t"
emis_deforestation[, , "primforest"][, , agPools] <- primforest_change * fm_carbon_density[, , "primforest"][, , agPools]
}
emis_deforestation <- emis_deforestation / timestep_length
emis_deforestation[, 1, ] <- NA

if (all(!is.null(other_change))) {
agPools <- c("vegc", "litc")
pm_carbon_density_ac <- readGDX(gdx, "pm_carbon_density_ac")[, getYears(timestep_length), ]
emis_other_land[, , "other"][, , agPools] <- dimSums(pm_carbon_density_ac[, , agPools] * other_change, dim = "ac")
}
emis_other_land <- emis_other_land / timestep_length
emis_other_land[, 1, ] <- NA


# ### emis_harvest (wood)
# emis_harvest <- dummy
# ov_hvarea_forestry <- readGDX(gdx,"ov_hvarea_forestry",select = list(type="level"),react = "silent")
Expand Down Expand Up @@ -357,8 +411,14 @@ dummy <- a
# emis_harvest <- add_dimension(emis_harvest, dim = 3.3,
# nm = "lu_harvest", add = "type")

emis_deforestation <- add_dimension(emis_deforestation, dim = 3.3,
nm = "lu_deforestation", add = "type")

emis_other_land <- add_dimension(emis_other_land, dim = 3.3,
nm = "lu_other_conversion", add = "type")

# bind together
a <- mbind(emis_total, emis_cc, emis_lu, emis_luc, emis_regrowth, emis_degrad)
a <- mbind(emis_total, emis_cc, emis_lu, emis_luc, emis_regrowth, emis_degrad, emis_deforestation, emis_other_land)

# calc emis_total
# calc emis_cc #vegc,litc,soilc #natural + indirect human effects
Expand Down
Loading

0 comments on commit aa67400

Please sign in to comment.