source("modules/Loading/Loading.R")
source("modules/Saving/Saving.R")
source("modules/Units/Units.R")
source("modules/Visualization/Visualization.R")
source("modules/Aggregation/Aggregation.R")

args = commandArgs(trailingOnly = TRUE)
recipe_file <- args[1]
#recipe_file <- "/esarchive/scratch/ptrascas/R/dev-test_bigpredidata/sunset/sunset/recipes/recipe_bigpredidata_oper_test_sfcWind.yml"
#recipe_file <- "/esarchive/scratch/ptrascas/R/dev-test_bigpredidata/sunset/sunset/recipes/recipe_bigpredidata_oper.yml"
recipe <- read_atomic_recipe(recipe_file)
#recipe <- prepare_outputs(recipe_file)
# Load datasets
data <- Loading(recipe)
data <- Units(recipe, data)

source("modules/Crossval/Crossval_anomalies.R")
data <- Crossval_anomalies(recipe = recipe, data = data)

# Save calibrated hindcast, forecast and probabilities

source("modules/Crossval/Crossval_metrics.R")
skill_metrics <- Crossval_metrics(recipe = recipe, data_crossval = data,
                                  fair = FALSE, nmemb = NULL, nmemb_ref = NULL)

Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics,
              significance = TRUE, probabilities = data$probs)
#if (!is.null(data$fcst)) {
#  # Required to plot a forecast:
#  data$fcst <- res$fcst
#  Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics,
#		significance = TRUE, probabilities = res$probs)
#} else {
#    Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics, 
#		  significance = TRUE)
#}

