88)
99import wkw
1010from wkcuber .utils import WkwDatasetInfo , open_wkw
11- from wkcuber .downsampling import _mode
11+ from wkcuber .downsampling import _mode , non_linear_filter_3d
1212import shutil
1313
1414WKW_CUBE_SIZE = 1024
@@ -34,18 +34,43 @@ def test_downsample_cube():
3434 assert buffer [0 , 0 , 1 ] == 1
3535 assert np .all (output [:, :, :] == np .arange (0 , CUBE_EDGE_LEN , 2 ))
3636
37+
3738def test_downsample_mode ():
3839
39- a = np .array ([[1 , 3 , 4 , 2 , 2 , 7 ],
40- [5 , 2 , 2 , 1 , 4 , 1 ],
41- [3 , 3 , 2 , 2 , 1 , 1 ]])
40+ a = np .array ([[1 , 3 , 4 , 2 , 2 , 7 ], [5 , 2 , 2 , 1 , 4 , 1 ], [3 , 3 , 2 , 2 , 1 , 1 ]])
4241
4342 result = _mode (a )
4443 expected_result = np .array ([1 , 3 , 2 , 2 , 1 , 1 ])
4544
4645 assert np .all (result == expected_result )
4746
4847
48+ def test_downsample_median ():
49+
50+ a = np .array ([[1 , 3 , 4 , 2 , 2 , 7 ], [5 , 2 , 2 , 1 , 4 , 1 ], [3 , 3 , 2 , 2 , 1 , 1 ]])
51+
52+ result = np .median (a , axis = 0 )
53+ expected_result = np .array ([3 , 3 , 2 , 2 , 2 , 1 ])
54+
55+ assert np .all (result == expected_result )
56+
57+
58+ def test_non_linear_filter_reshape ():
59+ a = np .array ([[[1 , 3 ], [1 , 4 ]], [[4 , 2 ], [3 , 1 ]]], dtype = np .uint8 )
60+
61+ a_filtered = non_linear_filter_3d (a , [2 , 2 , 2 ], _mode )
62+ assert a_filtered .dtype == np .uint8
63+ expected_result = [1 ]
64+ assert np .all (expected_result == a_filtered )
65+
66+ a = np .array ([[[1 , 3 ], [1 , 4 ]], [[4 , 3 ], [3 , 1 ]]], np .uint32 )
67+
68+ a_filtered = non_linear_filter_3d (a , [2 , 2 , 1 ], _mode )
69+ assert a_filtered .dtype == np .uint32
70+ expected_result = [1 , 3 ]
71+ assert np .all (expected_result == a_filtered )
72+
73+
4974def test_cube_addresses ():
5075 addresses = cube_addresses (source_info )
5176 assert len (addresses ) == 5 * 5 * 1
0 commit comments