Commit 3950066f authored by Thibault Hallouin's avatar Thibault Hallouin
Browse files

update to latest evalhyd version

which includes handling of `numpy.nan` for missing data in observations
and predictions. This is documented in the `evalp` docstring and new
unit tests are added to check this new functionality.
No related merge requests found
Pipeline #38531 passed with stage
in 1 minute and 42 seconds
Showing with 42 additions and 3 deletions
+42 -3
Subproject commit a2957cb3f6e674df6cf5e148870f74c9d53251b4 Subproject commit 25ca41bdfcb85cbbef072b635727077df0326f01
...@@ -166,11 +166,19 @@ PYBIND11_MODULE(evalhyd, m) ...@@ -166,11 +166,19 @@ PYBIND11_MODULE(evalhyd, m)
:Parameters: :Parameters:
q_obs: `numpy.ndarray` q_obs: `numpy.ndarray`
2D array of streamflow observations. 2D array of streamflow observations. Time steps with
missing observation must be assigned `numpy.nan`
values. Those time steps will be pairwise ignored in
the observations and the predictions before the
*metrics* are computed.
shape: (sites, time) shape: (sites, time)
q_prd: `numpy.ndarray` q_prd: `numpy.ndarray`
4D array of streamflow predictions. 4D array of streamflow predictions. Time steps with
missing prediction must be assigned `numpy.nan`
values. Those time steps will be pairwise ignored in
the observations and the predictions before the
*metrics* are computed.
shape: (sites, lead times, members, time) shape: (sites, lead times, members, time)
metrics: `List[str]` metrics: `List[str]`
......
...@@ -87,6 +87,34 @@ class TestMasking(unittest.TestCase): ...@@ -87,6 +87,34 @@ class TestMasking(unittest.TestCase):
) )
class TestMissingData(unittest.TestCase):
def test_nan(self):
thr = numpy.array([[690, 534, 445, numpy.nan]])
for metric in ("BS", "BSS", "BS_CRD", "BS_LBD", "QS", "CRPS"):
with self.subTest(metric=metric):
numpy.testing.assert_almost_equal(
# missing data flagged as NaN
evalhyd.evalp(
[[4.7, numpy.nan, 5.5, 2.7, 4.1]],
[[[[5.3, 4.2, 5.7, 2.3, numpy.nan],
[4.3, 4.2, 4.7, 4.3, numpy.nan],
[5.3, 5.2, 5.7, 2.3, numpy.nan]]]],
[metric],
thr
)[0],
# missing data pairwise deleted from series
evalhyd.evalp(
[[4.7, 5.5, 2.7]],
[[[[5.3, 5.7, 2.3],
[4.3, 4.7, 4.3],
[5.3, 5.7, 2.3]]]],
[metric],
thr
)[0]
)
if __name__ == '__main__': if __name__ == '__main__':
test_loader = unittest.TestLoader() test_loader = unittest.TestLoader()
test_suite = unittest.TestSuite() test_suite = unittest.TestSuite()
...@@ -100,6 +128,9 @@ if __name__ == '__main__': ...@@ -100,6 +128,9 @@ if __name__ == '__main__':
test_suite.addTests( test_suite.addTests(
test_loader.loadTestsFromTestCase(TestMasking) test_loader.loadTestsFromTestCase(TestMasking)
) )
test_suite.addTests(
test_loader.loadTestsFromTestCase(TestMissingData)
)
runner = unittest.TextTestRunner(verbosity=2) runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(test_suite) result = runner.run(test_suite)
......
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