An error occurred while loading the file. Please try again.
-
fbourgin authoredbb0b67fd
context("test handling of missing data for probabilistic evaluation")
library(testthat)
library(evalhyd)
# create some predicted and observed streamflow with NaN for missing data
obs_nan = rbind(
c(4.7, NA, 5.5, 2.7, 4.1)
)
prd_nan = array(
rbind(
c(5.3, 4.2, 5.7, 2.3, NA),
c(4.3, 4.2, 4.7, 4.3, NA),
c(5.3, 5.2, 5.7, 2.3, NA)
),
dim = c(1, 1, 3, 5)
)
# create some predicted and observed streamflow with dropped missing data
obs_drp = rbind(
c(4.7, 5.5, 2.7)
)
prd_drp = array(
rbind(
c(5.3, 5.7, 2.3),
c(4.3, 4.7, 4.3),
c(5.3, 5.7, 2.3)
),
dim = c(1, 1, 3, 3)
)
# check subset/NaN-ed result in same numerical output
thr = array(
c(690, 534, 445),
dim=c(1,3)
)
lvl = c(30., 80.)
metrics = c("BS", "BSS", "BS_CRD", "BS_LBD", "REL_DIAG", "CRPS_FROM_BS",
"CRPS_FROM_ECDF",
"QS", "CRPS_FROM_QS",
"POD", "POFD", "FAR", "CSI", "ROCSS",
"CR", "AW", "AWN", "WS",
"ES")
for (metric in metrics)
{
testthat::test_that(
"missing data",
{
testthat::expect_equal(
evalhyd::evalp(obs_nan, prd_nan, c(metric), thr, "high", lvl),
evalhyd::evalp(obs_drp, prd_drp, c(metric), thr, "high", lvl),
tolerance=1e-7
)
}
)
}