###############################################################################
## Author: Núria Pérez-Zanón
## Description: Computes the Niño1+2, Niño3, Niño3.4 and Niño4 indices and some
##              some skill metrics for each index.
## Instructions: To run it, modify the recipe to set your own output directory.
###############################################################################

# Load modules
source("modules/Loading/Loading.R")
source("modules/Anomalies/Anomalies.R")
source("modules/Indices/Indices.R")
source("modules/Skill/Skill.R")

# Read recipe
recipe_file <- "use_cases/ex1_3_nino_indices_comparison/ex1_3-recipe.yml"
recipe <- prepare_outputs(recipe_file)

data <- Loading(recipe)
data <- Units(recipe, data)
data <- Anomalies(recipe, data)
nino_indices <- Indices(data = data, recipe = recipe)

str(nino_indices, max.level = 3)
for (index in nino_indices) {
  skill_metrics <- Skill(recipe = recipe, data = index, agg = "region")
}

# skill_metrics <- Skill(recipe = recipe, data = nino_indices$Nino1,
#                                        agg = 'region')
# skill_metrics <- Skill(recipe = recipe, data = nino_indices$Nino3,
#                                        agg = 'region')
# 
# skill_metrics <- Skill(recipe = recipe, data = nino_indices$Nino4,
#                                        agg = 'region')
# 
# skill_metrics <- Skill(recipe = recipe, data = nino_indices$Nino3.4,
#                                        agg = 'region')
# 
