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)


#Recipe
recipe_file <- "recipes/atomic_recipes/recipe_test_provenance1.yml"

#Loading recipe
recipe <- prepare_outputs(recipe_file)

#Loading module
data <- Loading(recipe)

#Units module
data <- Units(recipe, data)

#Calibration
data <- Calibration(recipe, data)

# Anomalies
data <- Anomalies(recipe, data)

# Compute skill metrics
skill_metrics <- Skill(recipe, data)

# Compute percentiles and probability bins
probabilities <- Probabilities(recipe, data) #No provenance for probability calculations

#Define provenance graph for Visualization
graph.prov <- skill_metrics$graph.prov

#Visualization
Visualization(recipe, data, graph.prov,
              skill_metrics = skill_metrics,
              probabilities = probabilities,
              significance = TRUE)

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