-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1661 from fbenke-pik/cs2
move compareScenarios core framework to piamPlotComparison
- Loading branch information
Showing
14 changed files
with
69 additions
and
3,099 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
# | AGPL-3.0, you are granted additional permissions described in the | ||
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
library(remind2) | ||
|
||
library(piamPlotComparison) | ||
|
||
if (!exists("source_include")) { | ||
lucode2::readArgs("outputDirs", "outFileName", "profileName") | ||
|
@@ -15,35 +16,33 @@ run_compareScenarios2 <- function( | |
outFileName, | ||
profileName | ||
) { | ||
|
||
stopifnot(length(profileName) == 1 && is.character(profileName) && !is.na(profileName)) | ||
stopifnot(length(outFileName) == 1 && is.character(outFileName) && !is.na(outFileName)) | ||
|
||
# working directory is assumed to be the remind directory | ||
|
||
# load cs2 profiles | ||
profiles <- getCs2Profiles() | ||
profiles <- piamPlotComparison::getCs2Profiles() | ||
|
||
# Create temporary folder. This is necessary because each compareScenarios2 | ||
# run creates a folder named 'figure'. If multiple compareScenarios2 run in | ||
# parallel they would interfere with the others' figure folder. So we create a | ||
# temporary subfolder in which each compareScenarios2 creates its own figure | ||
# folder. | ||
system(paste0("mkdir ", outFileName)) | ||
system(paste0("mkdir ", outFileName)) | ||
outDir <- normalizePath(outFileName, mustWork = TRUE) | ||
|
||
outputDirs <- unique(normalizePath(outputDirs, mustWork = TRUE)) | ||
mifPath <- getMifScenPath(outputDirs, mustWork = TRUE) | ||
histPath <- getMifHistPath(outputDirs[1], mustWork = TRUE) | ||
scenConfigPath <- getCfgScenPath(outputDirs, mustWork = TRUE) | ||
defaultConfigPath <- getCfgDefaultPath(mustWork = TRUE) | ||
mifPath <- remind2::getMifScenPath(outputDirs, mustWork = TRUE) | ||
histPath <- remind2::getMifHistPath(outputDirs[1], mustWork = TRUE) | ||
scenConfigPath <- remind2::getCfgScenPath(outputDirs, mustWork = TRUE) | ||
|
||
# predefined arguments | ||
args <- list( | ||
mifScen = mifPath, | ||
mifHist = histPath, | ||
cfgScen = scenConfigPath, | ||
cfgDefault = defaultConfigPath, | ||
outputDir = outDir, | ||
outputFile = outFileName, | ||
outputFormat = "pdf" | ||
|
@@ -53,38 +52,38 @@ run_compareScenarios2 <- function( | |
message("Applying profile ", profileName) | ||
profile <- profiles[[profileName]] | ||
# Evaluate entries of profile as R code. | ||
profileEval <- lapply( | ||
profileEval <- lapply( | ||
names(profile), | ||
function(nm) { | ||
eval( | ||
parse(text = profile[[nm]]), | ||
parse(text = profile[[nm]]), | ||
# Set variable . to predefined argument value. | ||
# This allows refer to the predefined value in the profile expression. | ||
list("." = args[[nm]])) | ||
list("." = args[[nm]])) | ||
} | ||
) | ||
args[names(profile)] <- profileEval | ||
|
||
# Check outputFile ending. | ||
expectedEnding <- paste0(".", tolower(args$outputFormat)) | ||
if (!endsWith(tolower(args$outputFile), expectedEnding)) { | ||
args$outputFile <- paste0(args$outputFile, expectedEnding) | ||
} | ||
|
||
message("Will make following function call:") | ||
message(" remind2::compareScenarios2(") | ||
for (i in seq_along(args)) | ||
message(" piamPlotComparison::compareScenarios(") | ||
for (i in seq_along(args)) | ||
message(" ", names(args)[i], " = ", capture.output(dput(args[[i]])), if (i < length(args)) ",") | ||
message(" )") | ||
|
||
message("Calling remind2::compareScenarios2()...\n") | ||
do.call(compareScenarios2, args) | ||
message("Calling piamPlotComparison::compareScenarios()...\n") | ||
do.call(piamPlotComparison::compareScenarios, args) | ||
|
||
message("Move outputFile and delete temporary folder.\n") | ||
outputFilePath <- file.path(args$outputDir, args$outputFile) | ||
system(paste0("mv ", outputFilePath, " .")) | ||
system(paste0("rm -rf ", args$outputDir)) | ||
|
||
message("Done!\n") | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
# | REMIND License Exception, version 1.0 (see LICENSE file). | ||
# | Contact: [email protected] | ||
|
||
# Only output messages to the log if it is the first run of exoGAINS to avoid repetition in the log.txt file | ||
|
||
# Only output messages to the log if it is the first run of exoGAINS to avoid repetition in the log.txt file | ||
firstIteration = FALSE | ||
if (file.exists("log.txt")){ | ||
if(!any(grepl("ExoGAINS - log for first iteration...", readLines("log.txt")))){ | ||
|
@@ -50,7 +51,7 @@ message("- reportFE") | |
rem_in_mo <- mbind(rem_in_mo,reportFE(gdx)[,t,]) | ||
|
||
# delete "+" and "++" from variable names | ||
rem_in_mo <- deletePlus(rem_in_mo) | ||
rem_in_mo <- piamutils::deletePlus(rem_in_mo) | ||
|
||
# for easier debugging use rem_in in the remainder of the script | ||
rem_in <- rem_in_mo | ||
|
@@ -129,7 +130,7 @@ ela[,,] <- tmp | |
############################################################## | ||
RA_limited <- RA / (setYears(RA[,2015,] +1E-10)) | ||
RA_limited[RA_limited>5] <- 5 | ||
|
||
E <- ( ef_gains[,,ssp_scenario] / (setYears(ef_gains[,2015,ssp_scenario])+1E-10) + noef ) * setYears(emi_gains[,2015,ssp_scenario]) * ( RA_limited) ^ela | ||
|
||
# Calcualte emissions using different formula: for emisions that have no ef_gains | ||
|
@@ -214,17 +215,17 @@ writeGDX(out,file="pm_emiAPexsolve.gdx",period_with_y = FALSE) | |
# p<-ggplot(data=dat, aes(x=Year, y=Value)) + geom_line(aes(colour=Data2)) + facet_wrap(~Region,scales = "free_y") | ||
# ggsave(filename=paste0("Regions_",sec,".png"),p,scale=1.5,width=32,height=18,unit="cm",dpi=150) | ||
# } | ||
# | ||
# | ||
# stop() | ||
# | ||
# | ||
# # Add missing Int. Shipping sector from extra ECLIPSE file | ||
# RA_ship <- setNames(rem_in["GLO",,"FE|Transport|Liquids (EJ/yr)"],NULL) | ||
# # calculate shippin emission the same way as gains emissions | ||
# ship_E <- (ship_ef/setYears(ship_ef[,2015,])) * setYears(ship_emi[,2015,]) * (RA_ship/setYears(RA_ship[,2015,])) | ||
# E_rem <- add_columns(E_rem,addnm = getNames(ship_E,dim=1)) # filled with NA | ||
# gases <- getNames(E_rem,dim=2) | ||
# E_rem["GLO",,getNames(tmp)] <- ship_E[,,gases][,,ssp_scenario] | ||
# | ||
# | ||
# # Add BC and NOx for missing Int. Aviation sector from extra file from Steve | ||
# RA_avi <- collapseNames(time_interpolate(rem_in["GLO",,"Final Energy|Transportation|Liquids (EJ/yr)"][,,scenario], interpolated_year=getYears(ef_gains), integrate_interpolated_years=TRUE, extrapolation_type="constant")) | ||
# # calculate aviation emission the same way as gains emissions | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.