make_kernel

astropy.nddata.convolution.make_kernel.make_kernel(kernelshape, kernelwidth=3, kerneltype='gaussian', trapslope=None, normalize_kernel=<function sum at 0x321d7d0>, force_odd=False) [edit on github][source]

Create a smoothing kernel for use with convolve or convolve_fft.

Parameters :

kernelshape : n-tuple

A tuple (or list or array) defining the shape of the kernel. The length of kernelshape determines the dimensionality of the resulting kernel

kernelwidth : float

Width of kernel in pixels (see definitions under kerneltype)

kerneltype : {‘gaussian’, ‘boxcar’, ‘tophat’, ‘brickwall’, ‘airy’, ‘trapezoid’}

Defines the type of kernel to be generated. The following types are available:

  • ‘gaussian’

    Uses a gaussian kernel with sigma = kernelwidth (in pixels), i.e. kernel = exp(-r**2 / (2*sigma**2)) where r is the radius.

  • ‘boxcar’

    A kernelwidth x kernelwidth square kernel, i.e., kernel = (x < kernelwidth) * (y < kernelwidth)

  • ‘tophat’

    A flat circle with radius = kernelwidth, i.e., kernel = (r < kernelwidth)

  • ‘brickwall’ or ‘airy’

    A kernel using the airy function from optics. It requires scipy.special for the bessel function. See e.g., http://en.wikipedia.org/wiki/Airy_disk.

  • ‘trapezoid’

    A kernel like ‘tophat’ but with sloped edges. It is effectively a cone chopped off at the kernelwidth radius.

trapslope : float

Slope of the trapezoid kernel. Only used if kerneltype == ‘trapezoid’

normalize_kernel : function

Function to use for kernel normalization

force_odd : boolean

If set, forces the kernel to have odd dimensions (needed for convolve w/o ffts)

Returns :

kernel : ndarray

An N-dimensional float array

Examples

>>> make_kernel([3,3],1,'boxcar')
array([[ 0.  0.  0.]
       [ 0.  1.  0.]
       [ 0.  0.  0.]])
>>> make_kernel([9],1) # Gaussian by default
array([  1.33830625e-04   4.43186162e-03   5.39911274e-02   2.41971446e-01
         3.98943469e-01   2.41971446e-01   5.39911274e-02   4.43186162e-03
         1.33830625e-04])
>>> make_kernel([3,3],3,'boxcar')
array([[ 0.11111111,  0.11111111,  0.11111111],
       [ 0.11111111,  0.11111111,  0.11111111],
       [ 0.11111111,  0.11111111,  0.11111111]])
>>> make_kernel([3,3],1.4,'tophat')
array([[ 0. ,  0.2,  0. ],
       [ 0.2,  0.2,  0.2],
       [ 0. ,  0.2,  0. ]])

Page Contents