diff --git a/deps/evalhyd b/deps/evalhyd index 5edca4b512d4258dd44414f3aa5c7a81db7b6cef..bb555aee25de67b568390f4d76ae9b9a1678a065 160000 --- a/deps/evalhyd +++ b/deps/evalhyd @@ -1 +1 @@ -Subproject commit 5edca4b512d4258dd44414f3aa5c7a81db7b6cef +Subproject commit bb555aee25de67b568390f4d76ae9b9a1678a065 diff --git a/src/evalhyd-python.cpp b/src/evalhyd-python.cpp index 3a778cdf3eb9381dd5f1b6a5a9918293cd5c6b7f..17fe30c28d5e07970cdfa67b956bcf1452baa284 100644 --- a/src/evalhyd-python.cpp +++ b/src/evalhyd-python.cpp @@ -1,5 +1,6 @@ #include <pybind11/pybind11.h> #include <pybind11/stl.h> +#include <array> #define STRINGIFY(x) #x #define MACRO_STRINGIFY(x) STRINGIFY(x) @@ -47,7 +48,7 @@ PYBIND11_MODULE(evalhyd, m) metrics: `List[str]` The sequence of evaluation metrics to be computed. - + transform: `str`, optional The transformation to apply to both streamflow observations and predictions prior to the calculation of the *metrics*. @@ -94,9 +95,10 @@ PYBIND11_MODULE(evalhyd, m) shape: [(components,)+] )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("t_msk") = xt::pytensor<bool, 1>({}) + py::arg("transform") = "none", py::arg("exponent") = 1, + py::arg("epsilon") = -9, + py::arg("t_msk") = xt::pytensor<bool, 1>({}), + py::arg("m_cdt") = xt::pytensor<std::array<char, 32>, 1>({}) ); m.def( "evald", evalhyd::evald<2>, @@ -170,9 +172,10 @@ PYBIND11_MODULE(evalhyd, m) shape: [(1+, components), ...] )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("t_msk") = xt::pytensor<bool, 2>({0}) + py::arg("transform") = "none", py::arg("exponent") = 1, + py::arg("epsilon") = -9, + py::arg("t_msk") = xt::pytensor<bool, 2>({0}), + py::arg("m_cdt") = xt::pytensor<std::array<char, 32>, 2>({0}) ); // probabilistic evaluation @@ -227,7 +230,8 @@ PYBIND11_MODULE(evalhyd, m) )pbdoc", py::arg("q_obs"), py::arg("q_prd"), py::arg("metrics"), py::arg("q_thr") = xt::pytensor<double, 2>({0}), - py::arg("t_msk") = xt::pytensor<bool, 3>({0}) + py::arg("t_msk") = xt::pytensor<bool, 3>({0}), + py::arg("m_cdt") = xt::pytensor<std::array<char, 32>, 2>({0}) ); #ifdef VERSION_INFO diff --git a/tests/test_determinist.py b/tests/test_determinist.py index 06444e7088c7dcfdbc147a223a9541c31ec0433b..10d54c093cce31da48f40a15cd16e85d0fb4016e 100644 --- a/tests/test_determinist.py +++ b/tests/test_determinist.py @@ -95,6 +95,17 @@ class TestMasking(unittest.TestCase): evalhyd.evald(_obs[..., 99:], _prd[..., 99:], ["NSE"])[0] ) + def test_conditions(self): + cdt = numpy.array([["q{<2000,>3000}"]], dtype='|S32') + + obs = _obs[..., (_obs[0] < 2000) | (_obs[0] > 3000)] + prd = _prd[..., (_obs[0] < 2000) | (_obs[0] > 3000)] + + numpy.testing.assert_almost_equal( + evalhyd.evald(_obs, _prd, ["NSE"], m_cdt=cdt)[0], + evalhyd.evald(obs, prd, ["NSE"])[0] + ) + class TestMissingData(unittest.TestCase): diff --git a/tests/test_probabilist.py b/tests/test_probabilist.py index a081c9b834e0c55708b50f6c5763ba3d9a4e829b..ac11c096239f9e9097a4bba6f7e07deb005691f3 100644 --- a/tests/test_probabilist.py +++ b/tests/test_probabilist.py @@ -86,6 +86,17 @@ class TestMasking(unittest.TestCase): evalhyd.evalp(_obs[..., 99:], _prd[..., 99:], ["QS"])[0] ) + def test_conditions(self): + cdt = numpy.array([["q{<2000,>3000}"]], dtype='|S32') + + obs = _obs[..., (_obs[0] < 2000) | (_obs[0] > 3000)] + prd = _prd[..., (_obs[0] < 2000) | (_obs[0] > 3000)] + + numpy.testing.assert_almost_equal( + evalhyd.evalp(_obs, _prd, ["QS"], m_cdt=cdt)[0], + evalhyd.evalp(obs, prd, ["QS"])[0] + ) + class TestMissingData(unittest.TestCase):