Skip to content

Commit

Permalink
Added ensemble unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tnipen committed Dec 30, 2024
1 parent b03210f commit 0fdc7e4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
19 changes: 19 additions & 0 deletions verif/tests/files/file1_ens.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
date leadtime location lat lon altitude obs fcst e0 e1 e2
20120101 0 3 50 10 12 3 6 3 4 5
20120101 6 3 50 10 12 5 7 4 4 4
20120101 12 3 50 10 12 6 7 4 6 11
20120102 0 3 50 10 12 5 6 2 2 2
20120102 6 3 50 10 12 9 8 1 -1 12
20120102 12 3 50 10 12 12 11 11 10 12
20120103 0 3 50 10 12 -2 -4 -2 -10 10
20120103 6 3 50 10 12 0 3 2 2 4
20120103 12 3 50 10 12 3 9 8 7 2
20120101 0 41 42 23 341 -1 5 4 4 5
20120101 6 41 42 23 341 -1 4 3 1 2
20120101 12 41 42 23 341 2 7 2 3 1
20120102 0 41 42 23 341 1 6 6 2 -999
20120102 6 41 42 23 341 4 11 11 1 2
20120102 12 41 42 23 341 -999 14 12 13 14
20120103 0 41 42 23 341 8 -999 12 12 13
20120103 6 41 42 23 341 10 12 12 14 15
20120103 12 41 42 23 341 14 16 16 15 16
19 changes: 19 additions & 0 deletions verif/tests/files/file1_quantiles.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
date leadtime location lat lon altitude obs fcst q0.1 q0.9
20120101 0 3 50 10 12 3 6 3 4
20120101 6 3 50 10 12 5 7 4 4
20120101 12 3 50 10 12 6 7 4 6
20120102 0 3 50 10 12 5 6 2 2
20120102 6 3 50 10 12 9 8 -1 1
20120102 12 3 50 10 12 12 11 10 11
20120103 0 3 50 10 12 -2 -4 -10 -2
20120103 6 3 50 10 12 0 3 2 4
20120103 12 3 50 10 12 3 9 8 9
20120101 0 41 42 23 341 -1 5 4 5
20120101 6 41 42 23 341 -1 4 1 2
20120101 12 41 42 23 341 2 7 2 3
20120102 0 41 42 23 341 1 6 2 -999
20120102 6 41 42 23 341 4 11 1 2
20120102 12 41 42 23 341 -999 14 13 14
20120103 0 41 42 23 341 8 -999 12 13
20120103 6 41 42 23 341 10 12 14 15
20120103 12 41 42 23 341 14 16 16 17
13 changes: 13 additions & 0 deletions verif/tests/test_input_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,18 @@ def test_missing_values(self):
self.assertTrue(np.isnan(obs[0, 4, 0]))
self.assertTrue(np.isnan(fcst[0, 4, 0]))

def test_ensemble(self):
input = verif.input.Text("verif/tests/files/file1_ens.txt")

self.assertEqual(input.ensemble.shape, (3, 3, 2, 3))
Iloc = [l.id for l in input.locations].index(3)
np.testing.assert_array_almost_equal(input.ensemble[0, 0, Iloc, :], [3, 4, 5])

data = verif.data.Data([input])
ens = data.get_scores(verif.field.Ensemble(0), 0)

self.assertEqual(ens.shape, (3, 3, 2))
self.assertEqual(ens[0, 0, 0], 3)

if __name__ == '__main__':
unittest.main()
29 changes: 27 additions & 2 deletions verif/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,20 @@ def test_autocorr(self):
self.run_with_image("verif examples/raw.txt -m autocorr -r 0:100:1000")
self.run_with_image("verif examples/raw.txt -m autocorr -r 0:100:1000 -xlim 0,100")

def test_cond(self):
self.run_with_image("verif examples/raw.txt -m cond -r 1:10")

def test_qq(self):
self.run_with_image("verif examples/raw.txt -m qq -sp")
self.run_with_image("verif examples/raw.txt -m qq -x location")

def test_spreadskill(self):
self.run_with_image("verif verif/tests/files/file1_quantiles.txt -m spreadskill -sp -q 0.1,0.9")

def test_timeseries(self):
self.run_with_image("verif examples/raw.txt -m timeseries")
self.run_with_image("verif examples/raw.txt -m meteo")

def test_murphy(self):
self.run_with_image("verif examples/raw.txt -m murphy -r 0")

Expand All @@ -287,14 +301,25 @@ def test_map_type(self):
pass

def test_type(self):
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -type text")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -type csv")
self.run_with_image("verif examples/raw.txt examples/kf.txt -m mae -type rank")
# These cause a FutureWarning in mpl, but not much we can do about that
self.run_with_image("verif examples/raw.txt examples/kf.txt -m mae -type map -clim 0,11")
self.run_with_image("verif examples/raw.txt examples/kf.txt -m mae -type map -cmap RdBu")
self.run_with_image("verif examples/raw.txt examples/kf.txt -m mae -type map")
self.run_with_image("verif examples/raw.txt examples/kf.txt -m mae -type maprank")

def test_text(self):
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -type text")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m ets -r 0,1,2 -x threshold -type text")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -x fcst -type text")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -x obs -type text")

def test_csv(self):
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -type csv")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m ets -r 0,1,2 -x threshold -type csv")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -x fcst -type csv")
self.run_with_text("verif examples/raw.txt examples/kf.txt -m mae -x obs -type csv")

def test_freq(self):
self.run_with_image("verif verif/tests/files/file1.txt -m freq")
# Check that no error occurs, even though fcst or obs is not available
Expand Down

0 comments on commit 0fdc7e4

Please sign in to comment.