Commit fd1d0485 authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

add unittest for new mean/median/quantile# masking conditions

No related merge requests found
Pipeline #39152 passed with stages
in 3 minutes and 18 seconds
Showing with 37 additions and 1 deletion
+37 -1
...@@ -193,7 +193,7 @@ TEST(ProbabilistTests, TestMaskingConditions) ...@@ -193,7 +193,7 @@ TEST(ProbabilistTests, TestMaskingConditions)
// generate dummy empty masks required to access next optional argument // generate dummy empty masks required to access next optional argument
xt::xtensor<bool, 4> masks; xt::xtensor<bool, 4> masks;
// conditions on streamflow ________________________________________________ // conditions on streamflow values _________________________________________
// compute scores using masking conditions on streamflow to subset whole record // compute scores using masking conditions on streamflow to subset whole record
xt::xtensor<std::array<char, 32>, 2> q_conditions = { xt::xtensor<std::array<char, 32>, 2> q_conditions = {
...@@ -226,6 +226,42 @@ TEST(ProbabilistTests, TestMaskingConditions) ...@@ -226,6 +226,42 @@ TEST(ProbabilistTests, TestMaskingConditions)
) << "Failure for (" << metrics[m] << ")"; ) << "Failure for (" << metrics[m] << ")";
} }
// conditions on streamflow statistics _____________________________________
// compute scores using masking conditions on streamflow to subset whole record
xt::xtensor<std::array<char, 32>, 2> q_conditions_ = {
{{"q_prd_mean{>=median}"}}
};
auto q_prd_mean = xt::mean(predicted, {0}, xt::keep_dims);
double median = xt::median(q_prd_mean);
std::vector<xt::xarray<double>> metrics_q_conditioned_ =
evalhyd::evalp(
observed,
xt::view(predicted, xt::newaxis(), xt::newaxis(), xt::all(), xt::all()),
metrics, thresholds,
masks, q_conditions_
);
// compute scores using "NaN-ed" time indices where conditions on streamflow met
std::vector<xt::xarray<double>> metrics_q_preconditioned_ =
evalhyd::evalp(
xt::where(q_prd_mean >= median, observed, NAN),
xt::view(predicted, xt::newaxis(), xt::newaxis(), xt::all(), xt::all()),
metrics, thresholds
);
// check results are identical
for (int m = 0; m < metrics.size(); m++)
{
EXPECT_TRUE(
xt::allclose(
metrics_q_conditioned_[m], metrics_q_preconditioned_[m]
)
) << "Failure for (" << metrics[m] << ")";
}
// conditions on temporal indices __________________________________________ // conditions on temporal indices __________________________________________
// compute scores using masking conditions on time indices to subset whole record // compute scores using masking conditions on time indices to subset whole record
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment