map_overlap(self, func, depth, boundary=None, trim=True, **kwargs)
We share neighboring zones between blocks of the array, then map a function, then trim away the neighboring strips.
Note that this function will attempt to automatically determine the output array type before computing it, please refer to the meta
keyword argument in map_blocks <dask.array.core.map_blocks>
if you expect that the function will not succeed when operating on 0-d arrays.
The function to apply to each extended block
The number of elements that each block should share with its neighbors If a tuple or dict then this can be different per axis
How to handle the boundaries. Values include 'reflect', 'periodic', 'nearest', 'none', or any constant value like 0 or np.nan
Whether or not to trim depth
elements from each block after calling the map function. Set this to False if your mapping function already does this for you
Other keyword arguments valid in map_blocks <dask.array.core.map_blocks>
.
Map a function over blocks of the array with some overlap
>>> import dask.array as daThis example is valid syntax, but we were not able to check execution
... x = np.array([1, 1, 2, 3, 3, 3, 2, 1, 1])
... x = da.from_array(x, chunks=5)
... def derivative(x):
... return x - np.roll(x, 1)
>>> y = x.map_overlap(derivative, depth=1, boundary=0)This example is valid syntax, but we were not able to check execution
... y.compute() array([ 1, 0, 1, 1, 0, 0, -1, -1, 0])
>>> import dask.array as daThis example is valid syntax, but we were not able to check execution
... x = np.arange(16).reshape((4, 4))
... d = da.from_array(x, chunks=(2, 2))
... d.map_overlap(lambda x: x + x.size, depth=1).compute() array([[16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27], [28, 29, 30, 31]])
>>> func = lambda x: x + x.sizeThis example is valid syntax, but we were not able to check execution
... depth = {0: 1, 1: 1}
... boundary = {0: 'reflect', 1: 'none'}
... d.map_overlap(func, depth, boundary).compute() # doctest: +NORMALIZE_WHITESPACE array([[12, 13, 14, 15], [16, 17, 18, 19], [20, 21, 22, 23], [24, 25, 26, 27]])
>>> x = np.arange(16).reshape((4, 4))This example is valid syntax, but we were not able to check execution
... d = da.from_array(x, chunks=(2, 2))
... y = d.map_overlap(lambda x: x + x[2], depth=1, meta=np.array(()))
... y dask.array<_trim, shape=(4, 4), dtype=float64, chunksize=(2, 2), chunktype=numpy.ndarray>
>>> y.compute() array([[ 4, 6, 8, 10], [ 8, 10, 12, 14], [20, 22, 24, 26], [24, 26, 28, 30]])This example is valid syntax, but we were not able to check execution
>>> import cupy # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... x = cupy.arange(16).reshape((5, 4)) # doctest: +SKIP
... d = da.from_array(x, chunks=(2, 2)) # doctest: +SKIP
... y = d.map_overlap(lambda x: x + x[2], depth=1, meta=cupy.array(())) # doctest: +SKIP
... y # doctest: +SKIP dask.array<_trim, shape=(4, 4), dtype=float64, chunksize=(2, 2), chunktype=cupy.ndarray>
>>> y.compute() # doctest: +SKIP array([[ 4, 6, 8, 10], [ 8, 10, 12, 14], [20, 22, 24, 26], [24, 26, 28, 30]])See :
The following pages refer to to this document either explicitly or contain code examples using this.
dask.array.overlap.map_overlap
dask.array.core.Array.map_overlap
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them