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")
library(igraph)


#SUNSET loading module execution
recipe_file <- "recipes/atomic_recipes/recipe_test_provenance2.yml"  
        #"recipes/examples/NAO_recipe.yml" 
        #"recipes/atomic_recipes/recipe_seasonal_provenance.yml"  
        #"recipes/atomic_recipes/recipe_system7c3s-tas.yml"

#Loading MODULE
recipe <- prepare_outputs(recipe_file)
data <- Loading(recipe)

#Units MODULE
data <- Units(recipe, data)
data <- SunsetProv.Dataset(recipe, data)

#Calibration MODULE
data <- Calibration(recipe, data)

#Anomalies MODULE
data <- Anomalies(recipe, data)

#Indices MODULE
nino_indices <- Indices(data = data, recipe = recipe)
data <- SunsetProv.Indices(recipe, nino_indices)

#Downscaling MODULE
#data <- Downscaling(recipe,data)
#data <- SunsetProv.Downscaling(recipe,data)

#Skill MODULE
data <- SunsetProv.Skill(recipe, data)

#Scorecards MODULE
#data <- SunsetProv.Scorecards(recipe,data)

#Visualization MODULE
#data <- SunsetProv.Visualization(recipe,data)
 
#JSON generation
graph2json(data$graph.prov$graph, 
"/esarchive/scratch/apuiggro/sunset/graph333333.json")