Skip to content

Commit

Permalink
Merge pull request #2013 from stefanv/dask_optional
Browse files Browse the repository at this point in the history
Turn `dask` into an optional dependency
  • Loading branch information
blink1073 committed Mar 17, 2016
2 parents b9b5fde + 2df22d2 commit 74a8061
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions DEPENDS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ Runtime requirements
* `Six >=1.4 <https://pypi.python.org/pypi/six>`__
* `Pillow >= 1.7.8 <https://pypi.python.org/pypi/Pillow>`__
(or `PIL <http://www.pythonware.com/products/pil/>`__)
* `dask[array] >= 0.5.0 <http://dask.pydata.org/en/latest/>`__


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 <http://dask.pydata.org/en/latest/>`__.
For parallel computation using `skimage.util.apply_parallel`.

* `PyQt4 <http://wiki.python.org/moin/PyQt>`__
The ``qt`` plugin that provides ``imshow(x, fancy=True)`` and `skivi`.

Expand Down
11 changes: 10 additions & 1 deletion skimage/util/apply_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion skimage/util/tests/test_apply_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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')
Expand All @@ -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')
Expand Down

0 comments on commit 74a8061

Please sign in to comment.