Skip to content
Snippets Groups Projects
Commit e50cc58b authored by Johannes Koch's avatar Johannes Koch
Browse files

Allow for directory reselsection

parent f5b0686d
No related branches found
No related tags found
1 merge request!187Allow for directory reselsection
......@@ -36,7 +36,8 @@ rm_timestamp <- function(strings,
return(my_strings_wo_timeStamp)
}
policy_costs_pdf <- function(policy_costs, fileName="PolicyCost.pdf") {
policy_costs_pdf <- function(policy_costs,
fileName="PolicyCost.pdf") {
cat(paste0("A pdf with the name ",crayon::green(fileName)," is being created in the main remind folder.\n"))
......@@ -112,24 +113,21 @@ policy_costs_pdf <- function(policy_costs, fileName="PolicyCost.pdf") {
}
write_new_reporting <- function(mif_path, scen_name, new_polCost_data) {
write_new_reporting <- function(mif_path,
scen_name,
new_polCost_data) {
new_mif_path <- paste0(substr(mif_path,1,nchar(mif_path)-4),"_adjustedPolicyCosts.mif")
cat(paste0("A mif file with the name ",crayon::green(paste0("REMIND_generic_",scen_name,"_adjustedPolicyCosts.mif"))," is being created in the ",scen_name," outputfolder.\n"))
my_data <- magclass::read.report(mif_path)
#my_variables <- grep("Policy Cost", magclass::getNames(my_data[[1]][[1]]), value = TRUE)
#my_data[[1]][[1]][,,my_variables] <- new_polCost_data[,,my_variables]
my_variables <- grep("Policy Cost", magclass::getNames(my_data[[1]][[1]]), value = TRUE, invert = T)
magclass::getSets(new_polCost_data)[1] <- "region"
magclass::getSets(new_polCost_data)[2] <- "year"
magclass::getSets(new_polCost_data)[3] <- "variable"
my_data <- magclass::mbind(my_data[[1]][[1]][,,my_variables], new_polCost_data)
my_data <- magclass::add_dimension(my_data,dim=3.1,add = "model",nm = "REMIND")
my_data <- magclass::add_dimension(my_data,dim=3.1,add = "scenario",nm = scen_name)
......@@ -155,44 +153,68 @@ if(!exists("source_include")) {
}
# Check that "outputdirs" has an even number of entries.
if (length(outputdirs) %% 2!=0) {
cat(paste0(crayon::red("\nERROR: "), "The number of directories is not even!\n"))
cat("Remember, the order in which you choose the directories should be:\n")
cat("\t1: policy run 1\n\t2: reference run 1\n\t3: policy run 2\n\t4: reference run 2\nand so on...\n")
cat(crayon::red("\nStopping execution now.\n\n"))
stop("Number of directories is not even!")
}
# Get gdx paths
pol_gdxs <- paste0(outputdirs[seq(1,length(outputdirs),2)], "/fulldata.gdx")
ref_gdxs <- paste0(outputdirs[seq(2,length(outputdirs),2)], "/fulldata.gdx")
# Get run names
pol_names <- rm_timestamp(basename(dirname(pol_gdxs)))
ref_names <- rm_timestamp(basename(dirname(ref_gdxs)))
# Define pol-ref, policyCost pair names
pc_pairs <- paste0(pol_names, "_w.r.t_",ref_names)
# If this scrpit was called from output.R, check with user if the pol-ref pairs
# are the ones she wanted.
if(exists("source_include")) {
cat(crayon::blue("\nPlease confirm the set-up:\n"))
cat("From the order with which you selected the directories, the following policy costs will be computed:\n")
cat(crayon::green(paste0("\t", pc_pairs ,"\n")))
cat("Is that what you intended?\n")
cat(paste0("Type '",crayon::green("y"),"' to continue, '",crayon::red("n"),"' to abort: "))
user_input <- get_line()
if(!user_input %in% c("y","Y","yes")) {
cat(crayon::red("\nShame... \n"))
cat("Remember, the order in which you choose the directories should be:\n")
# Go into a while loop, until the user is happy with his input, or gives up and exits
happy_with_input <- FALSE
while (!happy_with_input) {
# Check that "outputdirs" has an even number of entries.
if (length(outputdirs) %% 2!=0) {
cat(paste0(crayon::red("\nERROR: "), "The number of directories is not even!\n"))
cat("Remember, your choice of directories should be made in the follwing manner:\n")
cat("\t1: policy run 1\n\t2: reference run 1\n\t3: policy run 2\n\t4: reference run 2\nand so on...\n")
cat(crayon::red("\nStopping execution now.\n\n"))
stop("Wrong set up.")
} else cat(crayon::green("Great!\n"))
if (exists("choose_folder")) {
outputdirs <- choose_folder("./output",crayon::blue("Please reselect your ouput folders"))
outputdirs <- paste0("output/",outputdirs)
} else {
cat(crayon::red("\nStopping execution now.\n\n"))
stop("Number of directories is not even!")
}
next()
}
# Get gdx paths
pol_gdxs <- paste0(outputdirs[seq(1,length(outputdirs),2)], "/fulldata.gdx")
ref_gdxs <- paste0(outputdirs[seq(2,length(outputdirs),2)], "/fulldata.gdx")
# Get run names
pol_names <- rm_timestamp(basename(dirname(pol_gdxs)))
ref_names <- rm_timestamp(basename(dirname(ref_gdxs)))
# Define pol-ref, policyCost pair names
pc_pairs <- paste0(pol_names, "_w.r.t_",ref_names)
# If this scrpit was called from output.R, check with user if the pol-ref pairs
# are the ones she wanted.
if(exists("source_include")) {
cat(crayon::blue("\nPlease confirm the set-up:\n"))
cat("From the order with which you selected the directories, the following policy costs will be computed:\n")
cat(crayon::green(paste0("\t", pc_pairs ,"\n")))
cat("Is that what you intended?\n")
cat(paste0("Type '",crayon::green("y"),"' to continue, '",crayon::blue("r"),"' to reselect output directories, '",crayon::red("n"),"' to abort: "))
user_input <- get_line()
if(user_input %in% c("y","Y","yes")) {
happy_with_input <- TRUE
cat(crayon::green("Great!\n"))
} else if(user_input %in% c("r","R","reselect")) {
if (exists("choose_folder")) {
cat("Remember, the order in which you choose the directories should be:\n")
cat("\t1: policy run 1\n\t2: reference run 1\n\t3: policy run 2\n\t4: reference run 2\nand so on...\n")
outputdirs <- choose_folder("./output",crayon::blue("Reselect your ouput folders now"))
outputdirs <- paste0("output/",outputdirs)
} else {
cat(crayon::red("\nStopping execution now.\n\n"))
stop("Couldn't find choosefolder() function")
}
} else {
cat(crayon::red("\nGood-bye (windows xp shutting down music)... \n"))
cat(crayon::red("\nStopping execution now.\n\n"))
stop("I can't figure this **** out. I give up. ")
}
}
}
# Tell the user what is going on
cat(crayon::blue("\nPolicy cost computations:\n"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment