From 54efcfeac2ccba66aa1ad98b72d92b0765f2d14b Mon Sep 17 00:00:00 2001 From: Thibault Hallouin <thibault.hallouin@inrae.fr> Date: Thu, 15 Sep 2022 11:26:42 +0200 Subject: [PATCH] add another unittest for new mean/median/quantile# masking conditions there was none for the determinist side --- tests/test_determinist.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/test_determinist.cpp b/tests/test_determinist.cpp index 703dd7a..7b89ddb 100644 --- a/tests/test_determinist.cpp +++ b/tests/test_determinist.cpp @@ -217,7 +217,7 @@ TEST(DeterministTests, TestMaskingConditions) // generate dummy empty masks required to access next optional argument xt::xtensor<bool, 2> 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 ={ @@ -248,6 +248,39 @@ TEST(DeterministTests, 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_obs{>=mean}"}} + }; + + double mean = xt::mean(observed, {1})(); + + std::vector<xt::xarray<double>> metrics_q_conditioned_ = + evalhyd::evald<2>( + observed, predicted, metrics, + "none", 1, -9, masks, q_conditions_ + ); + + // compute scores using "NaN-ed" time indices where conditions on streamflow met + std::vector<xt::xarray<double>> metrics_q_preconditioned_ = + evalhyd::evald<2>( + xt::where(observed >= mean, observed, NAN), + predicted, + metrics + ); + + // 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 -- GitLab