Skip to content

Commit

Permalink
fix scikit-image version skipping in the test suite (rapidsai#14)
Browse files Browse the repository at this point in the history
Due to a typo in test skip conditions (using `skimage>=1.18`) rather than the intended case of `scikit-image>=0.18` a handful of test-cases were always being skipped even when new enough scikit-image was available.

Fixing the test skip condition so that these cases get run revealed a couple of errors in the test cases themselves, but fortunately did not reveal any underlying errors in the functions being tested.

Authors:
  - Gregory R. Lee (https://github.com/grlee77)

Approvers:
  - Benjamin Zaitlen (https://github.com/quasiben)

URL: rapidsai#14
  • Loading branch information
grlee77 authored Apr 19, 2021
1 parent d93f65c commit 600d6ab
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion python/cucim/src/cucim/skimage/feature/tests/test_canny.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_mask_none(self):
result2 = feature.canny(cp.zeros((20, 20)), 4, 0, 0)
self.assertTrue(cp.all(result1 == result2))

@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_use_quantiles(self):
image = img_as_float(cp.asarray(data.camera()[::100, ::100]))

Expand Down
32 changes: 16 additions & 16 deletions python/cucim/src/cucim/skimage/filters/tests/test_thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,20 @@ def test_threshold_sauvola_iterable_window_size(self):
assert_array_equal(ref, out)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_otsu_camera_image():
camera = util.img_as_ubyte(camerad)
assert 101 < threshold_otsu(camera) < 103


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_otsu_camera_image_histogram():
camera = util.img_as_ubyte(camerad)
hist = histogram(camera.ravel(), 256, source_range="image")
assert 101 < threshold_otsu(hist=hist) < 103


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_otsu_camera_image_counts():
camera = util.img_as_ubyte(camerad)
counts, bin_centers = histogram(camera.ravel(), 256, source_range="image")
Expand Down Expand Up @@ -291,7 +291,7 @@ def test_otsu_one_color_image_3d():
assert threshold_otsu(img) == 1


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_li_camera_image():
image = util.img_as_ubyte(camerad)
threshold = threshold_li(image)
Expand Down Expand Up @@ -381,20 +381,20 @@ def test_li_pathological_arrays():
assert cp.all(cp.isfinite(thresholds))


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_yen_camera_image():
camera = util.img_as_ubyte(camerad)
assert 145 < threshold_yen(camera) < 147


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_yen_camera_image_histogram():
camera = util.img_as_ubyte(camerad)
hist = histogram(camera.ravel(), 256, source_range="image")
assert 145 < threshold_yen(hist=hist) < 147


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_yen_camera_image_counts():
camera = util.img_as_ubyte(camerad)
counts, bin_centers = histogram(camera.ravel(), 256, source_range='image')
Expand All @@ -417,7 +417,7 @@ def test_local_even_block_size_error():
threshold_local(img, block_size=4)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_isodata_camera_image():
camera = util.img_as_ubyte(camerad)

Expand All @@ -429,17 +429,17 @@ def test_isodata_camera_image():
assert_array_equal(threshold_isodata(camera, return_all=True), [102, 103])


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_isodata_camera_image_histogram():
camera = util.img_as_ubyte(data.camera())
camera = util.img_as_ubyte(camerad)
hist = histogram(camera.ravel(), 256, source_range='image')
threshold = threshold_isodata(hist=hist)
assert threshold == 102


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_isodata_camera_image_counts():
camera = util.img_as_ubyte(data.camera())
camera = util.img_as_ubyte(camerad)
counts, bin_centers = histogram(camera.ravel(), 256, source_range='image')
threshold = threshold_isodata(hist=counts)
assert threshold == 102
Expand Down Expand Up @@ -501,7 +501,7 @@ def test_isodata_moon_image_negative_float():
# fmt: on


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_threshold_minimum():
camera = util.img_as_ubyte(camerad)

Expand All @@ -513,15 +513,15 @@ def test_threshold_minimum():
assert_array_equal(threshold, 114)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_threshold_minimum_histogram():
camera = util.img_as_ubyte(camerad)
hist = histogram(camera.ravel(), 256, source_range='image')
threshold = threshold_minimum(hist=hist)
assert_array_equal(threshold, 85)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_threshold_minimum_counts():
camera = util.img_as_ubyte(camerad)
counts, bin_centers = histogram(camera.ravel(), 256, source_range='image')
Expand Down Expand Up @@ -695,7 +695,7 @@ def test_multiotsu_more_classes_then_values():
threshold_multiotsu(img, classes=4)


# @testing.with_requires("skimage>=0.18")
# @testing.with_requires("scikit-image>=0.18")
# @pytest.mark.parametrize(
# "thresholding, lower, upper",
# [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@pytest.mark.parametrize('dtype', [cp.uint8, cp.float32, cp.float64])
@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_PSNR_vs_IPOL(dtype):
"""Tests vs. imdiff result from the following IPOL article and code:
https://www.ipol.im/pub/art/2011/g_lmii/.
Expand All @@ -41,11 +41,10 @@ def test_PSNR_vs_IPOL(dtype):
https://github.com/scikit-image/scikit-image/pull/4913#issuecomment-700653165
"""
p_IPOL = 22.409353363576034
p = peak_signal_noise_ratio(cam.astype(dtype), cam_noisy.astype(dtype))
if np.dtype.kind(dtype) == 'f':
assert p.dtype == dtype
else:
assert p.dtype == cp.float64
p = peak_signal_noise_ratio(cam.astype(dtype), cam_noisy.astype(dtype),
data_range=255)
# internally, mean_square_error always sets dtype=cp.float64 for accuracy
assert p.dtype == cp.float64
assert_almost_equal(p, p_IPOL, decimal=4)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_structural_similarity_multichannel_chelsea():
assert_equal(structural_similarity(Xc, Xc, multichannel=True), 1.0)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_gaussian_structural_similarity_vs_IPOL():
"""Tests vs. imdiff result from the following IPOL article and code:
https://www.ipol.im/pub/art/2011/g_lmii/.
Expand All @@ -200,7 +200,7 @@ def test_gaussian_structural_similarity_vs_IPOL():
assert_almost_equal(mssim, mssim_IPOL, decimal=3)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_mssim_vs_legacy():
# check that ssim with default options matches skimage 0.11 result
mssim_skimage_0pt17 = 0.3674518327910367
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_unsupervised_wiener(dtype):
# cp.testing.assert_allclose(cp.real(deconvolved), np.load(path), rtol=1e-3)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_image_shape():
"""Test that shape of output image in deconvolution is same as input.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_clip_poisson():
assert (cam_poisson2.max() > 1.3) and (cam_poisson2.min() == -1.0)


@cp.testing.with_requires("skimage>=1.18")
@cp.testing.with_requires("scikit-image>=0.18")
def test_clip_gaussian():
seed = 42
data = camerad # 512x512 grayscale uint8
Expand Down

0 comments on commit 600d6ab

Please sign in to comment.