How do I apply a smoothing filter with dask
<p>I have a 2 dimensional array, I would like to do a 2 dimensional convolution with a kernel, for example a simple flat square matrix.</p>

<p>See for example: <a href="http://nbviewer.jupyter.org/gist/zonca/f0d819048ef7318eff944396b71af1c4" rel="nofollow">http://nbviewer.jupyter.org/gist/zonca/f0d819048ef7318eff944396b71af1c4</a></p>

<p>Is there a way to run this multithreaded with <code>dask</code>?</p>

<p>The <a href="http://dask.pydata.org/en/latest/array-api.html#dask.array.Array.map_overlap" rel="nofollow">map_overlap</a> method may do what you want.  It allows you to map a function over chunks of your array where those chunks have been pre-buffered with an overlapping region from nearby chunks.  </p>

<p>Something like the following might be a good start:</p>

<pre><code>In [1]: import numpy as np
In [2]: x = np.random.normal(10, 1, size=(1000, 1000))

In [3]: from scipy.signal import convolve2d

In [4]: import dask.array as da
In [5]: d = da.from_array(x, chunks=(500, 500))

In [6]: filt = np.ones((8, 8))

In [7]: d.map_overlap(convolve2d, in2=filt, depth=8)
Out[7]: dask.array&lt;trim-de..., shape=(1000, 1000), dtype=None, chunksize=(500, 500)&gt;
</code></pre>

<p>Although beware that the filter you've provided both smooths and amplifies.  You might also need to play with the trimming in convolve2d.</p>

python dask