diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c38f4392..90765b0b7 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 ba7685499..ab960bac8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,13 +22,15 @@ 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 (>= 0.20.7), + piamutils, quitte, raster, remulator, diff --git a/scripts/output/projects/agmip_report.R b/scripts/output/projects/agmip_report.R index 23d42af20..df59d4973 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 4dfefd03f..e02197b0b 100644 --- a/scripts/output/rds_report.R +++ b/scripts/output/rds_report.R @@ -17,6 +17,8 @@ library(magpie4) library(lucode2) library(quitte) library(gms) +library(piamInterfaces) +library(piamutils) options("magclass.verbosity" = 1) ############################# BASIC CONFIGURATION ############################# @@ -35,8 +37,19 @@ resultsarchive <- "/p/projects/rd3mod/models/results/magpie" report <- getReport(gdx, scenario = cfg$title, dir = outputdir) + +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 ", + "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) +q <- droplevels(q) if(all(is.na(q$value))) stop("No values in reporting!") saveRDS(q, file = rds, version = 2)