hcipy
hcipy copied to clipboard
Add support for geometric operations
Often I am trying to post-process my simulations and I need to use things like Gaussian filters or maybe a correlation function. Scipy.ndimage has a lot of useful functions for this. However, it does not work with the hcipy style Fields out of the box. I propose to add some simple wrapper decorators or wrapping functions to smooth out the interface between hcipy and scipy.
For example I was thinking about something like this for the convolution-like operators. I have similar style wrappers for the shift, zoom and rotate functions.
def ndimage_kernel_wrapper(func):
def new_func(field, weights, **kwargs):
return Field(func(field.shaped, weights.shaped, **kwargs).reshape(field.shape), field.grid)
return new_func
convolve = ndimage_kernel_wrapper(ndimage.convolve)
convolve1d = ndimage_kernel_wrapper(ndimage.convolve1d)
correlate = ndimage_kernel_wrapper(ndimage.correlate)
correlate1d = ndimage_kernel_wrapper(ndimage.correlate1d)
Thoughts or comments?