Skip to content

Commit

Permalink
Test find_objects with some input data
Browse files Browse the repository at this point in the history
Try testing `find_objects` with some input data that includes labels
within a chunk, labels that span across chunks, and labels that are not
present. Compare the results of the dask-image function to that of the
SciPy function to ensure they match.
  • Loading branch information
jakirkham committed Feb 4, 2019
1 parent 6786d6f commit 2eb9d34
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_dask_image/test_ndmeasure/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,31 @@ def test_extrema(shape, chunks, has_lbls, ind):
assert np.allclose(a_r_i, np.array(d_r[i]), equal_nan=True)


@pytest.mark.parametrize(
"max_labels", [0, 1, 2, 12, 13]
)
def test_find_objects(max_labels):
np.random.seed(128)

shape = (10, 11)
thrd = 0.5
a = (np.random.random(shape) < thrd)
l = spnd.label(a)[0] # noqa: E741
d_l = da.from_array(l, chunks=(5, 5))

if max_labels == 0:
with pytest.raises(NotImplementedError):
dask_image.ndmeasure.find_objects(d_l, max_labels)
else:
r = spnd.find_objects(l, max_labels)
d_r = dask_image.ndmeasure.find_objects(d_l, max_labels)

assert len(r) == len(d_r)

for i in irange(len(r)):
assert r[i] == d_r[i].compute()


@pytest.mark.parametrize(
"shape, chunks, has_lbls, ind", [
((15, 16), (4, 5), False, None),
Expand Down

0 comments on commit 2eb9d34

Please sign in to comment.