From 7ad972236548f1b5cea777d18b6fcaefbd34523d Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 14:28:40 +0200 Subject: [PATCH 1/9] add q_lvl --- deps/evalhyd-cpp | 2 +- evalhyd/evalp.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/deps/evalhyd-cpp b/deps/evalhyd-cpp index 6f17c3e..4c7d7ce 160000 --- a/deps/evalhyd-cpp +++ b/deps/evalhyd-cpp @@ -1 +1 @@ -Subproject commit 6f17c3e0f32f935c0a4f34dc1d3c6a9ee780497b +Subproject commit 4c7d7cee97041a5966e19ea1daa9abf82d3d5ff0 diff --git a/evalhyd/evalp.py b/evalhyd/evalp.py index 4639bea..8c4dd1c 100644 --- a/evalhyd/evalp.py +++ b/evalhyd/evalp.py @@ -14,6 +14,7 @@ def evalp(q_obs: NDArray[dtype('float64')], q_thr: NDArray[dtype('float64')] = None, events: str = None, c_lvl: NDArray[dtype('float64')] = None, + q_lvl: NDArray[dtype('float64')] = None, t_msk: NDArray[dtype('bool')] = None, m_cdt: NDArray[dtype('|S32')] = None, bootstrap: Dict[str, int] = None, @@ -36,6 +37,8 @@ def evalp(q_obs: NDArray[dtype('float64')], kwargs['events'] = events if c_lvl is not None: kwargs['c_lvl'] = c_lvl + if q_lvl is not None: + kwargs['q_lvl'] = q_lvl if t_msk is not None: kwargs['t_msk'] = t_msk if m_cdt is not None: @@ -55,6 +58,7 @@ def evalp(q_obs: NDArray[dtype('float64')], 'q_prd': 4, 'q_thr': 2, 'c_lvl': 1, + 'q_lvl': 1, 't_msk': 4, 'm_cdt': 2, 'dts': 1 -- GitLab From 38577cd9f6f5fef3fc26d90d87f553def53ee86a Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 14:37:00 +0200 Subject: [PATCH 2/9] add q_lvl in cpp --- evalhyd/src/evalhyd.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/evalhyd/src/evalhyd.cpp b/evalhyd/src/evalhyd.cpp index 47c424d..2c2b16a 100644 --- a/evalhyd/src/evalhyd.cpp +++ b/evalhyd/src/evalhyd.cpp @@ -63,6 +63,7 @@ auto evalp( const xt::pytensor<double, 2>& q_thr, std::optional<std::string> events, const std::vector<double>& c_lvl, + const std::vector<double>& q_lvl, const xt::pytensor<bool, 4>& t_msk, const xt::pytensor<std::array<char, 32>, 2>& m_cdt, std::optional<std::unordered_map<std::string, int>> bootstrap, @@ -78,6 +79,7 @@ auto evalp( q_thr, (events.has_value()) ? events.value() : xtl::missing<std::string>(), c_lvl, + q_lvl, t_msk, m_cdt, (bootstrap.has_value()) @@ -130,6 +132,7 @@ PYBIND11_MODULE(_evalhyd, m) py::arg("q_thr") = xt::pytensor<double, 2>({0}), py::arg("events") = py::none(), py::arg("c_lvl") = py::list(), + py::arg("q_lvl") = py::list(), py::arg("t_msk") = xt::pytensor<bool, 4>({0}), py::arg("m_cdt") = xt::pytensor<std::array<char, 32>, 2>({0}), py::arg("bootstrap") = py::none(), -- GitLab From afd5ede5740a4bbf0e9c99c2ee9b31edac5b3932 Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 14:55:28 +0200 Subject: [PATCH 3/9] add a test for q_lvl --- tests/expected/evalp/CR_QLVL.csv | 1 + tests/test_probabilist.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/expected/evalp/CR_QLVL.csv diff --git a/tests/expected/evalp/CR_QLVL.csv b/tests/expected/evalp/CR_QLVL.csv new file mode 100644 index 0000000..dfefd7e --- /dev/null +++ b/tests/expected/evalp/CR_QLVL.csv @@ -0,0 +1 @@ +0.00643087,0.0514469 diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index 0c14b7a..6d2faa2 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -90,6 +90,13 @@ class TestMetrics(unittest.TestCase): ) for metric in ('CR', 'AW', 'AWN', 'WS') } + expected_itv_qlvl = { + metric: ( + numpy.genfromtxt(f"./expected/evalp/{metric}_QLVL.csv", delimiter=',') + [numpy.newaxis, numpy.newaxis, numpy.newaxis, numpy.newaxis, ...] + ) for metric in ('CR') + } + expected_mvr = { metric: ( numpy.genfromtxt(f"./expected/evalp/{metric}.csv", delimiter=',') @@ -153,6 +160,21 @@ class TestMetrics(unittest.TestCase): self.expected_itv[metric] ) + def test_intervals_qlvl_metrics(self): + lvl = numpy.array([50., 80.]) + qlvl = numpy.array(10., 25., 75., 90]) + for metric in expected_itv_qlvl.keys(): + + numpy.set_printoptions(precision=13) + m = evalhyd.evalp(_obs, _prd, [metric], c_lvl=lvl, q_lvl=qlvl)[0][0, 0, 0] + numpy.savetxt(f"./expected/evalp/{metric}_QLVL.csv", m, delimiter=',', fmt="%.13f") + + with self.subTest(metric=metric): + numpy.testing.assert_almost_equal( + evalhyd.evalp(_obs, _prd, [metric], c_lvl=lvl, q_lvl=qlvl)[0], + self.expected_itv_qlvl[metric] + ) + def test_multivariate_metrics(self): n_sit = 5 -- GitLab From 3ae3c99cca9fc2ad94656ba06362d4436e6ce34d Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 15:03:14 +0200 Subject: [PATCH 4/9] add a test for q_lvl --- tests/test_probabilist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index 6d2faa2..584c940 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -162,7 +162,7 @@ class TestMetrics(unittest.TestCase): def test_intervals_qlvl_metrics(self): lvl = numpy.array([50., 80.]) - qlvl = numpy.array(10., 25., 75., 90]) + qlvl = numpy.array([10., 25., 75., 90]) for metric in expected_itv_qlvl.keys(): numpy.set_printoptions(precision=13) -- GitLab From dd500e7d61243cad5f1aa835bf20cc65d5fc14ec Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 15:10:11 +0200 Subject: [PATCH 5/9] add a test for q_lvl --- tests/test_probabilist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index 584c940..aaa8e69 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -94,7 +94,7 @@ class TestMetrics(unittest.TestCase): metric: ( numpy.genfromtxt(f"./expected/evalp/{metric}_QLVL.csv", delimiter=',') [numpy.newaxis, numpy.newaxis, numpy.newaxis, numpy.newaxis, ...] - ) for metric in ('CR') + ) for metric in ('CR',) } expected_mvr = { -- GitLab From aca6def8c799a0524ed08f9c9b967123e475ea63 Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 15:16:19 +0200 Subject: [PATCH 6/9] add a test for q_lvl --- tests/test_probabilist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index aaa8e69..2181206 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -163,7 +163,7 @@ class TestMetrics(unittest.TestCase): def test_intervals_qlvl_metrics(self): lvl = numpy.array([50., 80.]) qlvl = numpy.array([10., 25., 75., 90]) - for metric in expected_itv_qlvl.keys(): + for metric in self.expected_itv_qlvl.keys(): numpy.set_printoptions(precision=13) m = evalhyd.evalp(_obs, _prd, [metric], c_lvl=lvl, q_lvl=qlvl)[0][0, 0, 0] -- GitLab From ce69e412bd42b6ed3dec0ff0e2ebf9dbf4d49c7c Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 15:31:11 +0200 Subject: [PATCH 7/9] add a test for q_lvl --- tests/test_probabilist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index 2181206..b8dd7c7 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -166,7 +166,7 @@ class TestMetrics(unittest.TestCase): for metric in self.expected_itv_qlvl.keys(): numpy.set_printoptions(precision=13) - m = evalhyd.evalp(_obs, _prd, [metric], c_lvl=lvl, q_lvl=qlvl)[0][0, 0, 0] + m = evalhyd.evalp(_obs, _prd[:, :, [0, 15, 30, 50], :], [metric], c_lvl=lvl, q_lvl=qlvl)[0][0, 0, 0] numpy.savetxt(f"./expected/evalp/{metric}_QLVL.csv", m, delimiter=',', fmt="%.13f") with self.subTest(metric=metric): -- GitLab From f3e667f8183d2f803764f5c8b862930e72e46b19 Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 15:38:24 +0200 Subject: [PATCH 8/9] add a test for q_lvl --- tests/test_probabilist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index b8dd7c7..a846984 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -171,7 +171,7 @@ class TestMetrics(unittest.TestCase): with self.subTest(metric=metric): numpy.testing.assert_almost_equal( - evalhyd.evalp(_obs, _prd, [metric], c_lvl=lvl, q_lvl=qlvl)[0], + evalhyd.evalp(_obs, _prd[:, :, [0, 15, 30, 50], :], [metric], c_lvl=lvl, q_lvl=qlvl)[0], self.expected_itv_qlvl[metric] ) -- GitLab From 5f2b5607e32fd2f5e676c08a9a66a0771e791349 Mon Sep 17 00:00:00 2001 From: fbourgin <francois.bourgin@inrae.fr> Date: Tue, 20 May 2025 16:03:13 +0200 Subject: [PATCH 9/9] update deps/evalhyd-cpp --- deps/evalhyd-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/evalhyd-cpp b/deps/evalhyd-cpp index 4c7d7ce..8e78a67 160000 --- a/deps/evalhyd-cpp +++ b/deps/evalhyd-cpp @@ -1 +1 @@ -Subproject commit 4c7d7cee97041a5966e19ea1daa9abf82d3d5ff0 +Subproject commit 8e78a67e961001b479f65879119f7abe752b87d1 -- GitLab