## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = "center",
  warning = FALSE,
  message = FALSE,
  fig.align = "center",
  fig.width = 7
)

## ----load_package-------------------------------------------------------------
library(clim4health)

## ----vignette_objects, echo = FALSE-------------------------------------------
# c4h_downscale() requires CDO, which may not be available when this vignette
# is built. The code calls are shown but not run; the pre-computed results are
# loaded instead (see dev-utils/vignette_objects.R).
load_vignette_object <- function(name) {
  readRDS(system.file(
    "extdata",
    "vignette_objects",
    paste0("verification_", name, ".rds"),
    package = "clim4health",
    mustWork = TRUE
  ))
}

## -----------------------------------------------------------------------------
hcst_path <- system.file("extdata/hindcast/", package = "clim4health")
hcst_path <- paste0(hcst_path, "/")
hcst <- c4h_load(
  hcst_path,
  variable = "t2m",
  year = 2010:2013,
  month = 1,
  leadtime_month = "all",
  ext = "nc"
)

rean_path <- system.file("extdata/reanalysis/", package = "clim4health")
rean_path <- paste0(rean_path, "/")
rean <- c4h_load(
  rean_path,
  variable = "t2m",
  year = 2010:2013,
  month = 1,
  leadtime_month = 1:3,
  ext = "nc"
)

## ----convert_units------------------------------------------------------------
hcst <- c4h_convert_units(hcst, to = "celsius")
rean <- c4h_convert_units(rean, to = "celsius")

## ----downscale, eval = FALSE--------------------------------------------------
# dwn <- c4h_downscale(
#   "Intbc",
#   exp = hcst,
#   obs = rean,
#   method_remap = "bilinear",
#   method_bc = "evmos"
# )

## ----downscale_load, echo = FALSE---------------------------------------------
dwn <- load_vignette_object("intbc")

## -----------------------------------------------------------------------------
skill <- c4h_verify(
  exp = dwn$exp,
  obs = dwn$obs,
  metrics = c("BSS", "CRPSS"),
  brier_thresholds = c(0.1, 0.9)
)

## -----------------------------------------------------------------------------
names(skill)

## -----------------------------------------------------------------------------
names(skill$BSS10)

print(skill$BSS10$bss$dims)

## ----fig.height=2.5-----------------------------------------------------------
c4h_plotskill(
  skill$BSS10$bss,
  skill$BSS10$sign,
  ensemble = TRUE,
  boundaries = "countries"
)

