diff --git a/DEPENDS.txt b/DEPENDS.txt index edfe2dfaba3..1dfd318d914 100644 --- a/DEPENDS.txt +++ b/DEPENDS.txt @@ -16,19 +16,19 @@ Runtime requirements * `Six >=1.4 `__ * `Pillow >= 1.7.8 `__ (or `PIL `__) -* `dask[array] >= 0.5.0 `__ - You can use pip to automatically install the runtime dependencies as follows:: $ pip install -r requirements.txt - Optional Requirements --------------------- You can use this scikit with the basic requirements listed above, but some functionality is only available with the following installed: +* `dask[array] >= 0.5.0 `__. + For parallel computation using `skimage.util.apply_parallel`. + * `PyQt4 `__ The ``qt`` plugin that provides ``imshow(x, fancy=True)`` and `skivi`. diff --git a/skimage/util/apply_parallel.py b/skimage/util/apply_parallel.py index 0f58621657a..5323428c741 100644 --- a/skimage/util/apply_parallel.py +++ b/skimage/util/apply_parallel.py @@ -4,6 +4,13 @@ __all__ = ['apply_parallel'] +try: + import dask.array as da + dask_available = True +except ImportError: + dask_available = False + + def _get_chunks(shape, ncpu): """Split the array into equal sized chunks based on the number of available processors. The last chunk in each dimension absorbs the @@ -82,7 +89,9 @@ def apply_parallel(function, array, chunks=None, depth=0, mode=None, equivalent `dask` boundary modes 'reflect', 'periodic' and 'nearest', respectively. """ - import dask.array as da + if not dask_available: + raise RuntimeError("Could not import 'dask'. Please install " + "using 'pip install dask'") if chunks is None: shape = array.shape diff --git a/skimage/util/tests/test_apply_parallel.py b/skimage/util/tests/test_apply_parallel.py index 47dd0de849a..caa7cfa8ce0 100644 --- a/skimage/util/tests/test_apply_parallel.py +++ b/skimage/util/tests/test_apply_parallel.py @@ -2,11 +2,13 @@ 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 +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) @@ -28,6 +30,7 @@ def wrapped_gauss(arr): 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) @@ -40,6 +43,7 @@ def add_42(arr): assert_array_almost_equal(result, expected) +@skipif(not dask_available) def test_apply_parallel_wrap(): def wrapped(arr): return gaussian(arr, 1, mode='wrap') @@ -50,6 +54,7 @@ def wrapped(arr): assert_array_almost_equal(result, expected) +@skipif(not dask_available) def test_apply_parallel_nearest(): def wrapped(arr): return gaussian(arr, 1, mode='nearest')