From 2a8defcf3964b761a33db7a6aea6c311351effa6 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 13:35:29 +0200 Subject: [PATCH 01/10] rds_report check --- CHANGELOG.md | 1 + DESCRIPTION | 3 ++- scripts/output/rds_report.R | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c38f4392c..90765b0b7b 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/). ### added - **scripts** added output report `EU_report.R` that uses `EU_report.Rmd` - **70_livestock** added realization `fbask_jan16_sticky` +- **script** check of variables needed in piamInterfaces in report_rds.R ### removed - diff --git a/DESCRIPTION b/DESCRIPTION index ba76854991..88cdfb4567 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,13 +22,14 @@ Imports: m4fsdp, madrat, magclass (>= 6.14.0), - magpie4 (>= 2.3.10), + magpie4 (>= 2.5.6), MagpieNCGains, magpiesets, mip, mrcommons, patchwork, piamenv (>= 0.3.4), + piamInterfaces, quitte, raster, remulator, diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index 4dfefd03fa..d0a3aebc32 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -17,6 +17,7 @@ library(magpie4) library(lucode2) library(quitte) library(gms) +library(piamInterfaces) options("magclass.verbosity" = 1) ############################# BASIC CONFIGURATION ############################# @@ -35,6 +36,16 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) + +for (mapping in c("AR6", "NAVIGATE")) { + missingVariables <- setdiff(getMappingVariables(mapping,"M"),getNames(report,dim="variable")) + if (length(missingVariables) > 0) { + warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", + "for mapping ", mapping, ", but cannot be found in the MAgPIE report.\nPlease either fix in magpie4 or adjust the mapping in piamInterfaces.\n- ", + paste(missingVariables, collapse = ",\n- "), "\n") + } +} + write.report(report, file = mif) q <- as.quitte(report) if(all(is.na(q$value))) stop("No values in reporting!") From ead3de4ad6f936858eafa122f7c3984fa8df0432 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 13:54:28 +0200 Subject: [PATCH 02/10] bugfix --- DESCRIPTION | 1 + scripts/output/rds_report.R | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 88cdfb4567..3e994e25e6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,6 +30,7 @@ Imports: patchwork, piamenv (>= 0.3.4), piamInterfaces, + piamutils, quitte, raster, remulator, diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index d0a3aebc32..dc660d5e5a 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -17,7 +17,8 @@ library(magpie4) library(lucode2) library(quitte) library(gms) -library(piamInterfaces) +library(piamInterfaces) +library(piamutils) options("magclass.verbosity" = 1) ############################# BASIC CONFIGURATION ############################# @@ -39,6 +40,7 @@ report <- getReport(gdx, scenario = cfg$title, dir = outputdir) for (mapping in c("AR6", "NAVIGATE")) { missingVariables <- setdiff(getMappingVariables(mapping,"M"),getNames(report,dim="variable")) + missingVariables <- deletePlus(missingVariables) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", "for mapping ", mapping, ", but cannot be found in the MAgPIE report.\nPlease either fix in magpie4 or adjust the mapping in piamInterfaces.\n- ", From 790e82920b60289ce031873f78ddd3a241e66aa7 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 14:04:28 +0200 Subject: [PATCH 03/10] bugfix --- scripts/output/rds_report.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index dc660d5e5a..df83de3662 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -39,8 +39,7 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) for (mapping in c("AR6", "NAVIGATE")) { - missingVariables <- setdiff(getMappingVariables(mapping,"M"),getNames(report,dim="variable")) - missingVariables <- deletePlus(missingVariables) + missingVariables <- setdiff(deletePlus(getMappingVariables(mapping,"M")),getNames(report,dim="variable")) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", "for mapping ", mapping, ", but cannot be found in the MAgPIE report.\nPlease either fix in magpie4 or adjust the mapping in piamInterfaces.\n- ", From f0ffea51268b5d53e6cee05dab090dcc6b736c29 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 14:22:41 +0200 Subject: [PATCH 04/10] bugfix --- scripts/output/rds_report.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index df83de3662..5616b2f0dc 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -39,7 +39,7 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) for (mapping in c("AR6", "NAVIGATE")) { - missingVariables <- setdiff(deletePlus(getMappingVariables(mapping,"M")),getNames(report,dim="variable")) + missingVariables <- sort(setdiff(getMappingVariables(mapping,"M"),unique(deletePlus(getNames(report,dim="variable"))))) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", "for mapping ", mapping, ", but cannot be found in the MAgPIE report.\nPlease either fix in magpie4 or adjust the mapping in piamInterfaces.\n- ", From 8e400c9ddd0c056d817b43a8d229790f79df565a Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 14:31:30 +0200 Subject: [PATCH 05/10] bugfix --- scripts/output/rds_report.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index 5616b2f0dc..a01f7beffd 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -39,7 +39,7 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) for (mapping in c("AR6", "NAVIGATE")) { - missingVariables <- sort(setdiff(getMappingVariables(mapping,"M"),unique(deletePlus(getNames(report,dim="variable"))))) + missingVariables <- sort(setdiff(unique(deletePlus(getMappingVariables(mapping,"M"))),unique(deletePlus(getNames(report,dim="variable"))))) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", "for mapping ", mapping, ", but cannot be found in the MAgPIE report.\nPlease either fix in magpie4 or adjust the mapping in piamInterfaces.\n- ", From 836d518220b7c7be5f6a0c2e3f62782aed3d179b Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 15:16:56 +0200 Subject: [PATCH 06/10] added SHAPE --- scripts/output/rds_report.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index a01f7beffd..07d86e7f69 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -38,7 +38,7 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) -for (mapping in c("AR6", "NAVIGATE")) { +for (mapping in c("AR6", "NAVIGATE", "SHAPE")) { missingVariables <- sort(setdiff(unique(deletePlus(getMappingVariables(mapping,"M"))),unique(deletePlus(getNames(report,dim="variable"))))) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", From 612ce8e9f202d604e602fa18c8202858adfcfab8 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 15:53:28 +0200 Subject: [PATCH 07/10] added AR6_MAgPIE and AgMIP --- scripts/output/rds_report.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index 07d86e7f69..539e813ca9 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -38,7 +38,7 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) -for (mapping in c("AR6", "NAVIGATE", "SHAPE")) { +for (mapping in c("AR6", "NAVIGATE", "SHAPE", "AR6_MAgPIE", "AgMIP")) { missingVariables <- sort(setdiff(unique(deletePlus(getMappingVariables(mapping,"M"))),unique(deletePlus(getNames(report,dim="variable"))))) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", From 2dfff7f9082ed5d09230d7c050c1efc2869fb633 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 16:46:12 +0200 Subject: [PATCH 08/10] update agmip --- scripts/output/projects/agmip_report.R | 11 +++++++++++ scripts/output/rds_report.R | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/output/projects/agmip_report.R b/scripts/output/projects/agmip_report.R index 23d42af202..df59d49730 100644 --- a/scripts/output/projects/agmip_report.R +++ b/scripts/output/projects/agmip_report.R @@ -15,6 +15,8 @@ library(magpie4) library(lucode2) library(quitte) library(gms) +library(piamInterfaces) +library(piamutils) options("magclass.verbosity" = 1) ############################# BASIC CONFIGURATION ############################# @@ -31,6 +33,15 @@ rds <- paste0(outputdir, "/agmip_report.rds") report <- getReportAgMIP(gdx, scenario = cfg$title, dir = outputdir) +for (mapping in c("AgMIP")) { + missingVariables <- sort(setdiff(unique(deletePlus(getMappingVariables(mapping,"M"))),unique(deletePlus(getNames(report,dim="variable"))))) + if (length(missingVariables) > 0) { + warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", + "for mapping ", mapping, ", but cannot be found in the MAgPIE report.\nPlease either fix in magpie4 or adjust the mapping in piamInterfaces.\n- ", + paste(missingVariables, collapse = ",\n- "), "\n") + } +} + ### regional aggregation write.report(report, file = mif, skipempty = FALSE) saveRDS(as.quitte(report), file = rds) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index 539e813ca9..9b182e8ddb 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -38,7 +38,7 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) -for (mapping in c("AR6", "NAVIGATE", "SHAPE", "AR6_MAgPIE", "AgMIP")) { +for (mapping in c("AR6", "NAVIGATE", "SHAPE", "AR6_MAgPIE")) { missingVariables <- sort(setdiff(unique(deletePlus(getMappingVariables(mapping,"M"))),unique(deletePlus(getNames(report,dim="variable"))))) if (length(missingVariables) > 0) { warning("# The following ", length(missingVariables), " variables are expected in the piamInterfaces package ", From 0f48ca6cc636ac0268eadddb933ddd556553c86f Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 17:51:24 +0200 Subject: [PATCH 09/10] piamInterface version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3e994e25e6..ab960bac8f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Imports: mrcommons, patchwork, piamenv (>= 0.3.4), - piamInterfaces, + piamInterfaces (>= 0.20.7), piamutils, quitte, raster, From e7223c016b1c0a367e9066f7586a41ab91790351 Mon Sep 17 00:00:00 2001 From: florianh Date: Fri, 21 Jun 2024 19:00:03 +0200 Subject: [PATCH 10/10] bugfix GLO World --- scripts/output/rds_report.R | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/output/rds_report.R b/scripts/output/rds_report.R index 9b182e8ddb..e02197b0b3 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -49,6 +49,7 @@ for (mapping in c("AR6", "NAVIGATE", "SHAPE", "AR6_MAgPIE")) { write.report(report, file = mif) q <- as.quitte(report) +q <- droplevels(q) if(all(is.na(q$value))) stop("No values in reporting!") saveRDS(q, file = rds, version = 2)