Commit 4fd4272b authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

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{:}")
No related merge requests found
Pipeline #46398 passed with stage
in 5 minutes and 2 seconds
Showing with 41 additions and 3 deletions
+41 -3
Subproject commit d86043f5a28b697a902cc52842ed439583f5f42d
Subproject commit 5fd5811b75a849351002569dc196ea55aab906e0
......@@ -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):
......
......@@ -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):
......
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