Skip to content

Commit

Permalink
add tests classification
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerkuou committed Oct 21, 2024
1 parent 40e03f2 commit e0248ce
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/test_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import xarray as xr

from pydepsi.classification import _nad_block, _nmad_block, ps_selection
from pydepsi.classification import _idx_within_distance, _nad_block, _nmad_block, ps_selection

# Create a random number generator
rng = np.random.default_rng(42)
Expand Down Expand Up @@ -121,3 +121,27 @@ def test_nmad_block_select_two():
res = ps_selection(slcs, 1e-10, method="nmad", output_chunks=5) # Select pixels with dispersion lower than 0.00001
assert res.sizes["time"] == 10
assert res.sizes["space"] == 2


def test__idx_within_distance():
coords_include = np.array([[1, 1]])
coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
idx_within = _idx_within_distance(coords_include, coords_remain, 1)
assert np.all(idx_within == np.array([1]))

coords_include = np.array([[1, 1], [2, 2]])
coords_remain = np.array([[0, 0], [1.1, 1], [2.2, 2], [3, 3]])
idx_within = _idx_within_distance(coords_include, coords_remain, 1)
assert np.all(idx_within == np.array([1, 2]))

coords_include = np.array([[1, 1]])
coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
idx_within = _idx_within_distance(coords_include, coords_remain, 2)
assert np.all(idx_within == np.array([0, 1, 2]))


def test__idx_within_distance_no_drop():
coords_include = np.array([[100, 100]])
coords_remain = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
idx_within = _idx_within_distance(coords_include, coords_remain, 1)
assert idx_within is None

0 comments on commit e0248ce

Please sign in to comment.