mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-28 01:46:21 +08:00
2df22d2fc5
Dask is not yet packaged on all platforms, so make it optional for now.
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
from __future__ import absolute_import
|
|
|
|
import numpy as np
|
|
from numpy.testing import assert_array_almost_equal
|
|
from numpy.testing.decorators import skipif
|
|
|
|
from skimage.filters import threshold_adaptive, gaussian
|
|
from skimage.util.apply_parallel import apply_parallel, dask_available
|
|
|
|
|
|
@skipif(not dask_available)
|
|
def test_apply_parallel():
|
|
# data
|
|
a = np.arange(144).reshape(12, 12).astype(float)
|
|
|
|
# apply the filter
|
|
expected1 = threshold_adaptive(a, 3)
|
|
result1 = apply_parallel(threshold_adaptive, a, chunks=(6, 6), depth=5,
|
|
extra_arguments=(3,),
|
|
extra_keywords={'mode': 'reflect'})
|
|
|
|
assert_array_almost_equal(result1, expected1)
|
|
|
|
def wrapped_gauss(arr):
|
|
return gaussian(arr, 1, mode='reflect')
|
|
|
|
expected2 = gaussian(a, 1, mode='reflect')
|
|
result2 = apply_parallel(wrapped_gauss, a, chunks=(6, 6), depth=5)
|
|
|
|
assert_array_almost_equal(result2, expected2)
|
|
|
|
|
|
@skipif(not dask_available)
|
|
def test_no_chunks():
|
|
a = np.ones(1 * 4 * 8 * 9).reshape(1, 4, 8, 9)
|
|
|
|
def add_42(arr):
|
|
return arr + 42
|
|
|
|
expected = add_42(a)
|
|
result = apply_parallel(add_42, a)
|
|
|
|
assert_array_almost_equal(result, expected)
|
|
|
|
|
|
@skipif(not dask_available)
|
|
def test_apply_parallel_wrap():
|
|
def wrapped(arr):
|
|
return gaussian(arr, 1, mode='wrap')
|
|
a = np.arange(144).reshape(12, 12).astype(float)
|
|
expected = gaussian(a, 1, mode='wrap')
|
|
result = apply_parallel(wrapped, a, chunks=(6, 6), depth=5, mode='wrap')
|
|
|
|
assert_array_almost_equal(result, expected)
|
|
|
|
|
|
@skipif(not dask_available)
|
|
def test_apply_parallel_nearest():
|
|
def wrapped(arr):
|
|
return gaussian(arr, 1, mode='nearest')
|
|
a = np.arange(144).reshape(12, 12).astype(float)
|
|
expected = gaussian(a, 1, mode='nearest')
|
|
result = apply_parallel(wrapped, a, chunks=(6, 6), depth={0: 5, 1: 5},
|
|
mode='nearest')
|
|
|
|
assert_array_almost_equal(result, expected)
|