skimage2.util.apply_parallel#
- skimage2.util.apply_parallel(function, array, chunks=None, depth=0, mode=None, extra_arguments=(), extra_keywords=None, *, dtype=None, compute=None, channel_axis=None)[source]#
Map a function in parallel across an array.
Split an array into possibly overlapping chunks of a given depth and boundary type, call the given function in parallel on the chunks, combine the chunks and return the resulting array.
- Parameters:
- functionfunction
Function to be mapped which takes an array as an argument.
- arrayndarray or dask.array.Array
Array which the function will be applied to.
- chunksint, tuple, or tuple of tuples, optional
A single integer is interpreted as the length of one side of a square chunk that should be tiled across the array. One tuple of length
array.ndimrepresents the shape of a chunk, and it is tiled across the array. A list of tuples of lengthndim, where each sub-tuple is a sequence of chunk sizes along the corresponding dimension. If None, the array is broken up into chunks based on the number of available cpus. More information about chunks is in the documentation here. Whenchannel_axisis not None, the tuples can be lengthndim - 1and a single chunk will be used along the channel axis.- depthint or sequence of int, optional
The depth of the added boundary cells. A tuple can be used to specify a different depth per array axis. Defaults to zero. When
channel_axisis not None, and a tuple of lengthndim - 1is provided, a depth of 0 will be used along the channel axis.- mode{‘reflect’, ‘symmetric’, ‘periodic’, ‘wrap’, ‘nearest’, ‘edge’}, optional
Type of external boundary padding.
- extra_argumentstuple, optional
Tuple of arguments to be passed to the function.
- extra_keywordsdictionary, optional
Dictionary of keyword arguments to be passed to the function.
- dtypedtype-like, optional
The data type of the
functionoutput. If None, Dask will attempt to infer this by calling the function on data of shape(1,) * ndim. For functions expecting RGB or multichannel data this may be problematic. In such cases, the user should manually specify this dtype argument instead.Added in version 0.18:
dtypewas added in 0.18.- computebool, optional
If
True, compute eagerly returning a NumPy Array. IfFalse, compute lazily returning a Dask Array. IfNone(default), compute based on array type provided (eagerly for NumPy Arrays and lazily for Dask Arrays).- channel_axisint or None, optional
If None, the image is assumed to be a grayscale (single channel) image. Otherwise, this parameter indicates which axis of the array corresponds to channels.
- Returns:
- outndarray or dask.array.Array
Returns the result of the applying the operation. Type is dependent on the
computeargument.
Notes
Numpy edge modes ‘symmetric’, ‘wrap’, and ‘edge’ are converted to the equivalent
daskboundary modes ‘reflect’, ‘periodic’ and ‘nearest’, respectively. Settingcompute=Falsecan be useful for chaining later operations. For example region selection to preview a result or storing large data to disk instead of loading in memory.