From 9098210184cfef557dbc93086b8ce31302dd8f34 Mon Sep 17 00:00:00 2001
From: Thibault Hallouin <thibault.hallouin@inrae.fr>
Date: Thu, 1 Sep 2022 09:36:45 +0200
Subject: [PATCH] update to latest evalhyd version

which includes a temporal masking functionality for deterministic
evaluation
---
 deps/evalhyd              |  2 +-
 src/evalhyd-python.cpp    | 10 ++++++----
 tests/test_determinist.py | 14 ++++++++++++++
 tests/test_probabilist.py |  2 +-
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/deps/evalhyd b/deps/evalhyd
index c0ed155..5edca4b 160000
--- a/deps/evalhyd
+++ b/deps/evalhyd
@@ -1 +1 @@
-Subproject commit c0ed1559bb5c35ca883984a2952d6fce80d58b49
+Subproject commit 5edca4b512d4258dd44414f3aa5c7a81db7b6cef
diff --git a/src/evalhyd-python.cpp b/src/evalhyd-python.cpp
index 942e72b..3a778cd 100644
--- a/src/evalhyd-python.cpp
+++ b/src/evalhyd-python.cpp
@@ -23,7 +23,7 @@ PYBIND11_MODULE(evalhyd, m)
 
     // deterministic evaluation
     m.def(
-        "evald", evalhyd::evald<xt::pytensor<double, 1>>,
+        "evald", evalhyd::evald<1>,
         R"pbdoc(
             Function to evaluate deterministic streamflow predictions.
 
@@ -95,10 +95,11 @@ PYBIND11_MODULE(evalhyd, m)
         )pbdoc",
         py::arg("q_obs"), py::arg("q_prd"), py::arg("metrics"),
         py::arg("transform")="none", py::arg("exponent")=1,
-        py::arg("epsilon")=-9
+        py::arg("epsilon")=-9,
+        py::arg("t_msk") = xt::pytensor<bool, 1>({})
     );
     m.def(
-        "evald", evalhyd::evald<xt::pytensor<double, 2>>,
+        "evald", evalhyd::evald<2>,
         R"pbdoc(
             Function to evaluate deterministic streamflow predictions.
 
@@ -170,7 +171,8 @@ PYBIND11_MODULE(evalhyd, m)
         )pbdoc",
         py::arg("q_obs"), py::arg("q_prd"), py::arg("metrics"),
         py::arg("transform")="none", py::arg("exponent")=1,
-        py::arg("epsilon")=-9
+        py::arg("epsilon")=-9,
+        py::arg("t_msk") = xt::pytensor<bool, 2>({0})
     );
 
     // probabilistic evaluation
diff --git a/tests/test_determinist.py b/tests/test_determinist.py
index 3cc4a11..06444e7 100644
--- a/tests/test_determinist.py
+++ b/tests/test_determinist.py
@@ -85,6 +85,17 @@ class TestTransform(unittest.TestCase):
         )
 
 
+class TestMasking(unittest.TestCase):
+
+    def test_masks(self):
+        msk = numpy.ones(_obs.shape, dtype=bool)
+        msk[..., :99] = False
+        numpy.testing.assert_almost_equal(
+            evalhyd.evald(_obs, _prd, ["NSE"], t_msk=msk)[0],
+            evalhyd.evald(_obs[..., 99:], _prd[..., 99:], ["NSE"])[0]
+        )
+
+
 class TestMissingData(unittest.TestCase):
 
     def test_nan(self):
@@ -122,6 +133,9 @@ if __name__ == '__main__':
     test_suite.addTests(
         test_loader.loadTestsFromTestCase(TestTransform)
     )
+    test_suite.addTests(
+        test_loader.loadTestsFromTestCase(TestMasking)
+    )
     test_suite.addTests(
         test_loader.loadTestsFromTestCase(TestMissingData)
     )
diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py
index a59c9b8..a081c9b 100644
--- a/tests/test_probabilist.py
+++ b/tests/test_probabilist.py
@@ -79,7 +79,7 @@ class TestDecomposition(unittest.TestCase):
 class TestMasking(unittest.TestCase):
 
     def test_masks(self):
-        msk = numpy.ones((1, *_obs.shape), dtype=bool)
+        msk = numpy.ones((_obs.shape[0], 1, _obs.shape[1]), dtype=bool)
         msk[..., :99] = False
         numpy.testing.assert_almost_equal(
             evalhyd.evalp(_obs, _prd, ["QS"], t_msk=msk)[0],
-- 
GitLab