Skip to content

Commit

Permalink
Merge pull request #694 from flohump/f_report
Browse files Browse the repository at this point in the history
update merge_report and rds_report
  • Loading branch information
flohump authored Jul 1, 2024
2 parents 941c28b + 26d30d0 commit aafa9a5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### changed
- **21_trade** refactor equations for enhanced readablility and improve documentation
- **script** rewrite of merge_report.R based on rds files and rbind, which allows for more flexibility when merging reports. Avoid inconsistent use of "GLO" instead of "World" in report.rds files.

### added
- **scripts** added output report `EU_report.R` that uses `EU_report.Rmd`
Expand Down
23 changes: 10 additions & 13 deletions scripts/output/merge_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,24 @@ if(!exists("source_include")) {
cat("\nStarting output generation\n")

missing <- NULL
out <- NULL

if(file.exists("output/report_all.mif")) file.rename("output/report_all.mif","output/report_all.bak")
if(file.exists("output/report_all.rds")) file.rename("output/report_all.rds","output/report_all_bak.rds")
if(file.exists("output/report_all.mif")) file.rename("output/report_all.mif","output/report_all_bak.mif")

for (i in 1:length(outputdir)) {
print(paste("Processing",outputdir[i]))
#gdx file
rep<-file.path(outputdir[i],"report.mif")
rep<-file.path(outputdir[i],"report.rds")
if(file.exists(rep)) {
#get scenario name
cfg <- gms::loadConfig(file.path(outputdir[i], "config.yml"))
scen <- cfg$title
#read-in reporting file
a <- read.report(rep,as.list = FALSE)
getNames(a,dim=1) <- scen
#add to reporting mif file
write.report(a,file="output/report_all.mif",append=TRUE,ndigit = 4,skipempty = FALSE)
a <- readRDS(rep)
out <- rbind(out,a)
} else missing <- c(missing,outputdir[i])
}

saveRDS(out,file="output/report_all.rds")
write.mif(out,"output/report_all.mif")

if (!is.null(missing)) {
cat("\nList of folders with missing report.mif\n")
print(missing)
}

if(file.exists("output/report_all.mif")) saveRDS(read.quitte("output/report_all.mif"),file = "output/report_all.rds")
5 changes: 5 additions & 0 deletions scripts/output/rds_report.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ for (mapping in c("AR6", "NAVIGATE", "SHAPE", "AR6_MAgPIE")) {
}

write.report(report, file = mif)

q <- as.quitte(report)
# as.quitte converts "World" into "GLO". But we want to keep "World" and therefore undo these changes
q <- droplevels(q)
levels(q$region)[levels(q$region) == "GLO"] <- "World"
q$region <- factor(q$region,levels = sort(levels(q$region)))

if(all(is.na(q$value))) stop("No values in reporting!")

saveRDS(q, file = rds, version = 2)
Expand Down
6 changes: 6 additions & 0 deletions scripts/output/rds_report_iso.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ rds_iso <- paste0(outputdir, "/report_iso.rds")
###############################################################################

report <- getReportIso(gdx, scenario = cfg$title, dir = outputdir)

q <- as.quitte(report)
# as.quitte converts "World" into "GLO". But we want to keep "World" and therefore undo these changes
q <- droplevels(q)
levels(q$region)[levels(q$region) == "GLO"] <- "World"
q$region <- factor(q$region,levels = sort(levels(q$region)))

if (all(is.na(q$value))) {
stop("No values in reporting!")
}
Expand Down

0 comments on commit aafa9a5

Please sign in to comment.