xarray-spatial
xarray-spatial copied to clipboard
add enhanced focal stats
Add new kernels:
- [ ] add custom (allow user to supply 2d array representing convolution kernel)
- [ ] add circle
- [ ] add wedge
- [ ] add cone
import numba
@numba.stencil
def _smooth(x):
return (x[-1, -1] + x[-1, 0] + x[-1, 1] +
x[ 0, -1] + x[ 0, 0] + x[ 0, 1] +
x[ 1, -1] + x[ 1, 0] + x[ 1, 1]) // 9
I'm not too familiar with the stencil notation in Numba. I see the utility in it but the example above is the same as below which could also be used as a convolution kernel with other methods.
kernel = np.ones((3, 3))
kernel /= kernel.sum()
What is your opinion on allowing convolution with the GPU? It's relatively easy to do, though some overhead accounting needs to be done to account for hardware and library versions.
I've tried this example with my data and it works well, especially for larger kernel and image sizes.
I believe the max kernel size is (32, 32)
, which will work well for most kernels, but causes some issues with the annulus kernel (#125) depending on the radius.
I haven't tried to use Dask yet, so perhaps that takes care of some of these issues or could help with large convolution kernels on large arrays.
@chase-dwelle hey hey. Numba has support for CUDA GPUs. I really want to make a push to make these run on GPU, but we haven't quite got there yet. @thuydotm is helping to review your PR and we'll get it merged ASAP. Datashader has some really interesting implementation examples for numba on gpus.
@brendancol, will this issue be worked on?
This look great
Closing as we now allow custom kernel, kernels of any shape can be accepted as input of focal_stats()