Skip to content

Commit

Permalink
Merge pull request #692 from flohump/f_report
Browse files Browse the repository at this point in the history
add check of reporting variables for piamInterfaces
  • Loading branch information
flohump authored Jun 24, 2024
2 parents 1d06d91 + e7223c0 commit 4ca5a4c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-
Expand Down
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions scripts/output/projects/agmip_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ library(magpie4)
library(lucode2)
library(quitte)
library(gms)
library(piamInterfaces)
library(piamutils)
options("magclass.verbosity" = 1)

############################# BASIC CONFIGURATION #############################
Expand All @@ -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)
13 changes: 13 additions & 0 deletions scripts/output/rds_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ library(magpie4)
library(lucode2)
library(quitte)
library(gms)
library(piamInterfaces)
library(piamutils)
options("magclass.verbosity" = 1)

############################# BASIC CONFIGURATION #############################
Expand All @@ -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)
Expand Down

0 comments on commit 4ca5a4c

Please sign in to comment.