###############################################################################
## Author: Núria Pérez-Zanón and Victòria Agudetse Roures
## Description: Computes the Niño1+2, Niño3, Niño3.4 and Niño4 indices and some
##              skill metrics for each index.
## Instructions: To run it, follow the steps described in: 
##               use_cases/ex1_3_nino_indices_comparison/ex1_3-handson.md
###############################################################################

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

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

# Load data
data <- Loading(recipe)
# Check units and transform if needed
data <- Units(recipe, data)
# Calibrate data
data <- Calibration(recipe, data)
# Compute tos anomalies
data <- Anomalies(recipe, data)
# Compute Niño Indices
nino_indices <- Indices(data = data, recipe = recipe)

# We can compute the Skill metrics for each of the El Niño indices,
# specifying that the data is spatially aggregated, with the parameter
# agg = "region".
for (index in nino_indices) {
  skill_metrics <- Skill(recipe = recipe, data = index, agg = "region")
}
