
###########################################
### SEASONAL MULTIMODEL TEST - LAUNCHER ###
###########################################

# 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")
source("modules/Multimodel/Multimodel.R")

# Read recipe
args = commandArgs(trailingOnly = TRUE)
recipe_file <- args[1]
recipe <- read_atomic_recipe(recipe_file)

if (recipe$Analysis$Datasets$System$name == 'Multimodel') {
  # Load datasets and create multimodel
  mm <- Multimodel(recipe)
  data <- mm$data
  probabilities <- mm$prob
} else {
  # Load datasets
  data <- Loading(recipe)
  # Change units
  data <- Units(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)
