|
5 | 5 | import pytest
|
6 | 6 | import xarray as xr
|
7 | 7 |
|
8 |
| -from pydepsi.classification import _nad_block, _nmad_block, ps_selection |
| 8 | +from pydepsi.classification import _idx_within_distance, _nad_block, _nmad_block, ps_selection |
9 | 9 |
|
10 | 10 | # Create a random number generator
|
11 | 11 | rng = np.random.default_rng(42)
|
@@ -121,3 +121,27 @@ def test_nmad_block_select_two():
|
121 | 121 | res = ps_selection(slcs, 1e-10, method="nmad", output_chunks=5) # Select pixels with dispersion lower than 0.00001
|
122 | 122 | assert res.sizes["time"] == 10
|
123 | 123 | assert res.sizes["space"] == 2
|
| 124 | + |
| 125 | + |
| 126 | +def test__idx_within_distance(): |
| 127 | + coords_include = np.array([[1, 1]]) |
| 128 | + coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]]) |
| 129 | + idx_within = _idx_within_distance(coords_include, coords_remain, 1) |
| 130 | + assert np.all(idx_within == np.array([1])) |
| 131 | + |
| 132 | + coords_include = np.array([[1, 1], [2, 2]]) |
| 133 | + coords_remain = np.array([[0, 0], [1.1, 1], [2.2, 2], [3, 3]]) |
| 134 | + idx_within = _idx_within_distance(coords_include, coords_remain, 1) |
| 135 | + assert np.all(idx_within == np.array([1, 2])) |
| 136 | + |
| 137 | + coords_include = np.array([[1, 1]]) |
| 138 | + coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]]) |
| 139 | + idx_within = _idx_within_distance(coords_include, coords_remain, 2) |
| 140 | + assert np.all(idx_within == np.array([0, 1, 2])) |
| 141 | + |
| 142 | + |
| 143 | +def test__idx_within_distance_no_drop(): |
| 144 | + coords_include = np.array([[100, 100]]) |
| 145 | + coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]]) |
| 146 | + idx_within = _idx_within_distance(coords_include, coords_remain, 1) |
| 147 | + assert idx_within is None |
0 commit comments