source('modules/Loading/GRIB/GrbLoad.R')
source('modules/Loading//Loading_GRIB.R')
source("tools/libs.R") # for prepare_outputs.R

recipe <- "modules/Loading/testing_recipes/recipe_GRIB_system5_era5.yml"
recipe <- prepare_outputs(recipe)

# Load datasets
data <- load_datasets(recipe)

str(data)

#============================
# Test the remaining modules
#============================
source("modules/Calibration/Calibration.R")
source("modules/Skill/Skill.R")
source("modules/Saving/Saving.R")
source("modules/Visualization/Visualization.R")

# Calibrate data
suppressWarnings({invisible(capture.output(
calibrated_data <- calibrate_datasets(recipe, data)
))})
#pryr::mem_used()
#975 MB

# Compute skill metrics
suppressWarnings({invisible(capture.output(
skill_metrics <- compute_skill_metrics(recipe, calibrated_data)
))})

suppressWarnings({invisible(capture.output(
probs <- compute_probabilities(recipe, calibrated_data)
))})

# Saving
suppressWarnings({invisible(capture.output(
save_data(recipe = recipe, data = calibrated_data,
	  skill_metrics = skill_metrics, probabilities = probs,
          archive = read_yaml("conf/archive_GRIB.yml")$archive)
))})

# Plotting
suppressWarnings({invisible(capture.output(
plot_data(recipe = recipe,  data = calibrated_data,
	  skill_metrics = skill_metrics, probabilities = probs,
	  significance = T,
          archive = read_yaml("conf/archive_GRIB.yml")$archive)
))})
outdir <- get_dir(recipe)

