From 4fd4272b1ac073956c88bba4e8b73487229bb2c0 Mon Sep 17 00:00:00 2001 From: Thibault Hallouin <thibault.hallouin@inrae.fr> Date: Wed, 19 Apr 2023 14:12:31 +0200 Subject: [PATCH] use fix for regex on masking conditions with quantile bounds and add unit tests to cover these cases (which was not the case before), also add a unit test for special case with no subset (i.e. "t{:}") --- deps/evalhyd-cpp | 2 +- tests/test_determinist.py | 11 +++++++++++ tests/test_probabilist.py | 31 +++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/deps/evalhyd-cpp b/deps/evalhyd-cpp index d86043f..5fd5811 160000 --- a/deps/evalhyd-cpp +++ b/deps/evalhyd-cpp @@ -1 +1 @@ -Subproject commit d86043f5a28b697a902cc52842ed439583f5f42d +Subproject commit 5fd5811b75a849351002569dc196ea55aab906e0 diff --git a/tests/test_determinist.py b/tests/test_determinist.py index 7757d64..62a5b6e 100644 --- a/tests/test_determinist.py +++ b/tests/test_determinist.py @@ -181,6 +181,17 @@ class TestMasking(unittest.TestCase): q_thr=_thr, events=_events)[0] ) + with self.subTest(conditions="no subset"): + cdt = numpy.array([["t{:}"]] * _prd.shape[0], + dtype='|S32') + + numpy.testing.assert_almost_equal( + evalhyd.evald(obs, prd, ["NSE"], + q_thr=_thr, events=_events, m_cdt=cdt)[0], + evalhyd.evald(obs, prd, ["NSE"], + q_thr=_thr, events=_events)[0] + ) + class TestMissingData(unittest.TestCase): diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index 9c9b945..c3adb76 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -212,8 +212,8 @@ class TestMasking(unittest.TestCase): evalhyd.evalp(obs, prd, ["QS"])[0] ) - with self.subTest(conditions="predicted streamflow statistics"): - cdt = numpy.array([["q_prd_median{<=quantile0.7}"]], dtype='|S32') + with self.subTest(conditions="predicted streamflow statistics 1"): + cdt = numpy.array([["q_prd_median{<=qtl0.7}"]], dtype='|S32') median = numpy.squeeze(numpy.median(_prd, 2)) msk = median <= numpy.quantile(median, 0.7) @@ -227,6 +227,24 @@ class TestMasking(unittest.TestCase): evalhyd.evalp(obs, prd, ["QS"])[0] ) + with self.subTest(conditions="predicted streamflow statistics 2"): + cdt = numpy.array([["q_prd_median{>qtl0.3,<=qtl0.7}"]], dtype='|S32') + + median = numpy.squeeze(numpy.median(_prd, 2)) + msk = ( + (median > numpy.quantile(median, 0.3)) + & (median <= numpy.quantile(median, 0.7)) + ) + + # TODO: figure out why passing views would not work + obs = _obs[..., msk].copy() + prd = _prd[..., msk].copy() + + numpy.testing.assert_almost_equal( + evalhyd.evalp(_obs, _prd, ["QS"], m_cdt=cdt)[0], + evalhyd.evalp(obs, prd, ["QS"])[0] + ) + with self.subTest(conditions="time indices"): cdt = numpy.array([["t{20:80,80,81,82,83:311}"]], dtype='|S32') @@ -240,6 +258,15 @@ class TestMasking(unittest.TestCase): evalhyd.evalp(obs, prd, ["QS"])[0] ) + with self.subTest(conditions="no subset"): + cdt = numpy.array([["t{:}"]], + dtype='|S32') + + numpy.testing.assert_almost_equal( + evalhyd.evalp(obs, prd, ["QS"], m_cdt=cdt)[0], + evalhyd.evalp(obs, prd, ["QS"])[0] + ) + class TestMissingData(unittest.TestCase): -- GitLab