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/Indices/Indices.R")
source("modules/Downscaling/Downscaling.R")
source("tools/s2dv_cube2Climate4R.R")
source("SUNSET_PROV/R/Prov.Dataset.R")
source("SUNSET_PROV/R/Prov.DatasetSubset.R")
source("SUNSET_PROV/R/SunsetProv.Dataset.R")
source("SUNSET_PROV/R/getSpatialExtent.R")
source("SUNSET_PROV/R/Prov.Reggriding.R")
source("SUNSET_PROV/R/Prov.Calibration.R")
source("SUNSET_PROV/R/SunsetProv.Calibration.R")
source("SUNSET_PROV/R/SunsetProv.Anomalies.R")
source("SUNSET_PROV/R/Prov.Anomalies.R")
source("SUNSET_PROV/R/SunsetProv.Command.R")
source("SUNSET_PROV/R/SunsetProv.Downscaling.R")
source("SUNSET_PROV/R/SunsetProv.Skill.R")
source("SUNSET_PROV/R/Prov.Skill.R")
source("SUNSET_PROV/R/Prov.Visualization.R")
source("SUNSET_PROV/R/SunsetProv.Visualization.R")
source("SUNSET_PROV/R/keep_latest_node.R")
source("SUNSET_PROV/R/SunsetProv.Scorecards.R")
source("SUNSET_PROV/R/SunsetProv.Indices.R")
source("SUNSET_PROV/R/provenance-helpers.R")
source("SUNSET_PROV/R/igraph-helpers.R")
source("SUNSET_PROV/R/graph2json.R")
source("SUNSET_PROV/R/Prov.Skill_Indices.R")
library(igraph)

# Read recipe
recipe_file <- "recipes/examples/Nino_recipe.yml"
recipe <- prepare_outputs(recipe_file)

# Load datasets
data <- Loading(recipe)

# Compute anomalies
data <- Anomalies(recipe, data)

# Compute index NAO
#nino_data <- Indices(recipe, data)

graph.prov <- SunsetProv.Indices(recipe, data$graph.prov)


# Compute skill metrics
#for (index in nino_data) {
#  index$graph.prov <- graph.prov
#  nino_skill_metrics <- Skill(recipe = recipe, data = index, agg = "region")
#  graph.prov <- nino_skill_metrics$graph.prov
#}

graph2json(graph.prov$graph,
  "/esarchive/scratch/apuiggro/sunset/graph333333.json")
