diff --git a/tests/test_probabilist.cpp b/tests/test_probabilist.cpp index c2c0497b46bbb74c02f1bc48d434d78511faf30b..2bfc446f2255c4475bc46215ff4dd0f0e83dba61 100644 --- a/tests/test_probabilist.cpp +++ b/tests/test_probabilist.cpp @@ -193,7 +193,7 @@ TEST(ProbabilistTests, TestMaskingConditions) // generate dummy empty masks required to access next optional argument xt::xtensor<bool, 4> masks; - // conditions on streamflow ________________________________________________ + // conditions on streamflow values _________________________________________ // compute scores using masking conditions on streamflow to subset whole record xt::xtensor<std::array<char, 32>, 2> q_conditions = { @@ -226,6 +226,42 @@ TEST(ProbabilistTests, TestMaskingConditions) ) << "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 __________________________________________ // compute scores using masking conditions on time indices to subset whole record