
################################
### SEASONAL MULTIMODEL TEST ###
################################

# Load modules
source("modules/Loading/Loading.R")
source("modules/Units/Units.R")
source("modules/Calibration/Calibration.R")
source("modules/Anomalies/Anomalies.R")
source("modules/Skill/Skill.R")
source("modules/Saving/Saving.R")
source("modules/Visualization/Visualization.R")

# Read recipe
recipe_file <- "recipe_multimodel_seasonal.yml"
system(paste0('Rscript split.R ',recipe_file))

for (recipe_file in c("/esarchive/scratch/cdelgado/sunset_outputs/recipe_multimodel_seasonal_20231124155552/logs/recipes/atomic_recipe_01.yml",
                      "/esarchive/scratch/cdelgado/sunset_outputs/recipe_multimodel_seasonal_20231124155552/logs/recipes/atomic_recipe_02.yml",
                      "/esarchive/scratch/cdelgado/sunset_outputs/recipe_multimodel_seasonal_20231124155552/logs/recipes/atomic_recipe_03.yml")){
  
  recipe <- prepare_outputs(recipe_file)
  
  if (recipe$Analysis$Datasets$System$name == 'Multimodel'){
    
    # Load datasets and create multimodel
    data <- Multimodel(recipe)
    
  } else {
    
    # Load datasets
    data <- Loading(recipe)
    # Change units
    data <- Units(recipe, data)
    # Calibrate datasets
    data <- Calibration(recipe, data)
    # Compute anomalies
    data <- Anomalies(recipe, data)
    # Compute percentiles and probability bins
    probabilities <- Probabilities(recipe, data)
    
  }
  
  # Compute skill metrics 
  skill_metrics <- Skill(recipe, data)
  # Plot data
  Visualization(recipe, data, skill_metrics, probabilities, significance = T)
  
}
