###############################################################################
## Author: A. Llabrés-Brustenga
## Description: Example script for use of module indicators.
###############################################################################

# Load modules
source("modules/Loading/Loading.R")
source("modules/Units/Units.R")
source("modules/Indicators/Indicators.R")

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

# Load datasets
data_raw <- Loading(recipe)

# Change units: very important to estimate evapotranspiration!
data_units <- Units(recipe, data_raw)

# Obtain SPEI and/or SPI according to recipe
result <- Indicators(recipe, data_units)

# the result is a list with the requested indicators, e.g.:
# > summary(result$SPEI$obs$data)
#   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
#  -Inf  -0.782  -0.026     NaN   0.827     Inf   13200
# > summary(result$SPEI$hcst$data)
#   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
#   -3.2    -0.8     0.0     0.0     0.8     3.3  330000