#' get_predictions
#'
#' This is a function to get the predictions for a specific output simulated by SCOPE and calculate the accuracy.
#' @param SCOPE_dir the diretory patch of SCOPE
#' @param output_file default "fluxes.csv" for the energy fluxes output
#' @param pred_vec desirble output variables.
#' @param Simulation_Name simulation name stating the directory name generated by the run_SCOPE function.
#' @return The result is a data.frame with all the predicted output per simulation name and date.
#' @examples
#' Examples of uses of the get_predictions function
#' ###############
#' library(tidyverse)
#'
#' Predictions_pixel_1169 <- get_predictions(SCOPE_dir = "D:/SCOPE-master/",
#' output_file = "fluxes.csv",
#' pred_vec = "lEtot",
#' Simulation_Name = "pixel_1169")
#'
#' Predictions_pixel_1169
#'
#' @export
get_predictions <- function(
SCOPE_dir = "D:/SCOPE-master/",
Simulation_Name,
output_file = "fluxes.csv",
pred_vec = "lEtot"
){
Outputs_files_str <- list.files(paste0(path=grep(Simulation_Name,
list.dirs(path=paste0(SCOPE_dir,"output"),
full.names = TRUE,
recursive = FALSE),
value = TRUE),
"/", collapse = NULL, recycle0 = FALSE),
pattern= output_file,
full.names = TRUE)
# the order is wrong 1 10 11 ... 2 20 21 ..
# correct the order 1 2 3 4 ... 55
Outputs_files <- gtools::mixedsort(sort(Outputs_files_str))
# read the list of files
Outputs_list <- lapply(1:length(Outputs_files),
function(i) data.table::fread(Outputs_files[i],skip=2))
# stack all the subsets
prediction <- data.table::as.data.table(dplyr::bind_rows(Outputs_list))
names(prediction) <- names(data.table::fread(Outputs_files[1]))
return(prediction)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.