From a9f2de7112d05219ebba1eac4310ae66afa21c47 Mon Sep 17 00:00:00 2001 From: pvjeetze Date: Tue, 29 Oct 2024 11:12:43 +0100 Subject: [PATCH 1/3] peatland considered during disaggregation --- scripts/output/extra/disaggregation.R | 96 +++++++++++++++------------ 1 file changed, 53 insertions(+), 43 deletions(-) diff --git a/scripts/output/extra/disaggregation.R b/scripts/output/extra/disaggregation.R index e4e963989..2c6608bc2 100644 --- a/scripts/output/extra/disaggregation.R +++ b/scripts/output/extra/disaggregation.R @@ -87,7 +87,8 @@ if (length(map_file) > 1) { } .dissagLandConsv <- function(gdx, cfg, map_file, wdpa_hr_file, consv_prio_hr_file) { - land_consv_lr <- readGDX(gdx, "p22_conservation_area", react = "silent") + land_consv_lr <- readGDX(gdx, "pm_land_conservation", react = "silent") + land_consv_lr <- dimSums(land_consv_lr, dim=3.2) wdpa_hr <- read.magpie(wdpa_hr_file) map <- readRDS(map_file) @@ -275,6 +276,8 @@ if (cfg$gms$urban == "exo_nov21") { # Prepare land conservation data # ---------------------------------------- +message("Disaggregating conservation land") + land_consv_hr <- NULL if (file.exists(wdpa_hr_file)) { land_consv_hr <- .dissagLandConsv(gdx, cfg, map_file, wdpa_hr_file, consv_prio_hr_file) @@ -300,6 +303,30 @@ avl_cropland_hr <- file.path(outputdir, "avl_cropland_0.5.mz") # available cropl marginal_land <- cfg$gms$c29_marginal_land # marginal land scenario snv_pol_fader <- readGDX(gdx, "i29_snv_scenario_fader") + +# -------------------------------- +# Disaggregate peatland +# -------------------------------- + +message("Disaggregating peatland") + +# check for peatland version +if (cfg$gms$peatland == "v2") { + peat_lr <- PeatlandArea(gdx, level = "cell", sum = FALSE) + peat_ini_hr <- read.magpie(peatland_v2_hr_file) + peat_ini_hr <- add_columns(peat_ini_hr, addnm = "rewetted", dim = "d3", fill = 0) + peat_ini_hr <- add_columns(peat_ini_hr, addnm = "unused", dim = "d3", fill = 0) + peat_hr <- suppressWarnings(luscale::interpolate2(peat_lr, peat_ini_hr, map_file)) + peat_hr <- peat_hr[, getYears(peat_hr, as.integer = T) >= cfg$gms$s58_fix_peatland, ] +} else if (cfg$gms$peatland == "on") { + peat_lr <- PeatlandArea(gdx, level = "cell", sum = TRUE) + peat_ini_hr <- mbind(setNames(read.magpie(peatland_on_intact_hr_file), "intact"), setNames(read.magpie(peatland_on_degrad_hr_file), "degrad")) + peat_ini_hr <- add_columns(peat_ini_hr, addnm = "rewet", dim = "d3", fill = 0) + peat_hr <- suppressWarnings(luscale::interpolate2(peat_lr, peat_ini_hr, map_file)) + peat_hr <- peat_hr[, getYears(peat_hr, as.integer = T) >= cfg$gms$s58_fix_peatland, ] +} +peat_hr <- .fixCoords(peat_hr) + # ============================================ # Start disaggregation # ============================================ @@ -319,6 +346,7 @@ land_hr <- interpolateAvlCroplandWeighted( marginal_land = marginal_land, urban_land_hr = urban_land_hr, land_consv_hr = land_consv_hr, + peat_hr = peat_hr, snv_pol_shr = snv_pol_shr, snv_pol_fader = snv_pol_fader ) @@ -335,6 +363,30 @@ land_hr <- .fixCoords(land_hr) ) gc() +# ----------------------------------- +# Create peatland outputs +# ----------------------------------- + +# Write output +.writeDisagg(peat_hr, peatland_hr_out_file, + comment = "unit: Mha per grid-cell", + message = "Write outputs peatland Mha" +) +gc() + +out <- peat_hr / dimSums(land_hr[, getYears(peat_hr), ], dim = 3) +out[is.nan(out)] <- 0 +out[is.infinite(out)] <- 0 + +rm(land_hr, peat_hr) + +.writeDisagg(out, peatland_hr_share_out_file, + comment = "unit: grid-cell land area fraction", + message = "Write outputs peatland share" +) +gc() + + # --------------------------------- # Split land pools # --------------------------------- @@ -532,46 +584,4 @@ rm(bii_hr) gc() -# -------------------------------- -# Disaggregate peatland -# -------------------------------- - -message("Disaggregating peatland") - -# check for peatland version -if (cfg$gms$peatland == "v2") { - peat_lr <- PeatlandArea(gdx, level = "cell", sum = FALSE) - peat_ini_hr <- read.magpie(peatland_v2_hr_file) - peat_ini_hr <- add_columns(peat_ini_hr, addnm = "rewetted", dim = "d3", fill = 0) - peat_ini_hr <- add_columns(peat_ini_hr, addnm = "unused", dim = "d3", fill = 0) - peat_hr <- suppressWarnings(luscale::interpolate2(peat_lr, peat_ini_hr, map_file)) - peat_hr <- peat_hr[, getYears(peat_hr, as.integer = T) >= cfg$gms$s58_fix_peatland, ] -} else if (cfg$gms$peatland == "on") { - peat_lr <- PeatlandArea(gdx, level = "cell", sum = TRUE) - peat_ini_hr <- mbind(setNames(read.magpie(peatland_on_intact_hr_file), "intact"), setNames(read.magpie(peatland_on_degrad_hr_file), "degrad")) - peat_ini_hr <- add_columns(peat_ini_hr, addnm = "rewet", dim = "d3", fill = 0) - peat_hr <- suppressWarnings(luscale::interpolate2(peat_lr, peat_ini_hr, map_file)) - peat_hr <- peat_hr[, getYears(peat_hr, as.integer = T) >= cfg$gms$s58_fix_peatland, ] -} -peat_hr <- .fixCoords(peat_hr) - -# Write output -.writeDisagg(peat_hr, peatland_hr_out_file, - comment = "unit: Mha per grid-cell", - message = "Write outputs peatland Mha" -) -gc() - -out <- peat_hr / dimSums(land_hr[, getYears(peat_hr), ], dim = 3) -out[is.nan(out)] <- 0 -out[is.infinite(out)] <- 0 - -rm(land_hr, peat_hr) - -.writeDisagg(out, peatland_hr_share_out_file, - comment = "unit: grid-cell land area fraction", - message = "Write outputs peatland share" -) -gc() - message("Finished disaggregation") From 12c7df64441607a587631ebc74144626a5596cc5 Mon Sep 17 00:00:00 2001 From: pvjeetze Date: Tue, 29 Oct 2024 11:22:17 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a648c02d..2ad2663b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - **scripts** REMIND coupling reads data in US$2017, not US$2005 - **config** updated input data to rev4.113 - **config** SHAPE scenarios start year of dietary shift changed to 2025 +- **extra/disaggregation** Peatland now considered in disaggregation of land pools ### added - **62_material** added switch to turn off future material demand for bioplastic @@ -21,9 +22,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - ### fixed -- **11_costs** changed equation to fix bug in total water cost calculation -- **29_cropland** treecover age-class growth was not working properly because ac_sub was erroneously not fixed -- **scripts** script/output/extra/resubmit.R +- **11_costs** changed equation to fix bug in total water cost calculation +- **29_cropland** treecover age-class growth was not working properly because ac_sub was erroneously not fixed +- **scripts** script/output/extra/resubmit.R ## [4.8.2] - 2024-09-24 From 629d61a211055a1b5640c53cad99098d28ac5ca9 Mon Sep 17 00:00:00 2001 From: florianh Date: Sun, 3 Nov 2024 19:30:40 +0100 Subject: [PATCH 3/3] bugfix --- scripts/output/extra/disaggregation.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/output/extra/disaggregation.R b/scripts/output/extra/disaggregation.R index 2c6608bc2..29a72de73 100644 --- a/scripts/output/extra/disaggregation.R +++ b/scripts/output/extra/disaggregation.R @@ -378,8 +378,6 @@ out <- peat_hr / dimSums(land_hr[, getYears(peat_hr), ], dim = 3) out[is.nan(out)] <- 0 out[is.infinite(out)] <- 0 -rm(land_hr, peat_hr) - .writeDisagg(out, peatland_hr_share_out_file, comment = "unit: grid-cell land area fraction", message = "Write outputs peatland share" @@ -526,6 +524,10 @@ if (grepl("grass", cfg$gms$past)) { "past", "manpast", gsub("range", "rangeland", getNames(land_lr)) ) + getNames(land_consv_hr) <- gsub( + "past", "manpast", + gsub("range", "rangeland", getNames(land_consv_hr)) + ) } else { # Disaggregate pasture land_ini_lr <- mbind( @@ -537,6 +539,11 @@ if (grepl("grass", cfg$gms$past)) { land_lr[, , c("past"), invert = TRUE], collapseNames(land_lr[, , "past"]) * side_layers_lr[, , c("manpast", "rangeland")] ) + + land_consv_hr <- mbind( + land_consv_hr[, , c("past"), invert = TRUE], + collapseNames(land_consv_hr[, , "past"]) * side_layers_hr[, , c("manpast", "rangeland")] + ) } # Sort and rename @@ -556,6 +563,7 @@ land_bii_hr <- interpolateAvlCroplandWeighted( marginal_land = marginal_land, urban_land_hr = urban_land_hr, land_consv_hr = land_consv_hr, + peat_hr = peat_hr, snv_pol_shr = snv_pol_shr, snv_pol_fader = snv_pol_fader, unit = "share"