Navigation

The convolution module provides several built-in kernels to cover the most
common applications in astronomy. It is also possible to define custom kernels
from arrays or combine existing kernels to match specific applications.

Every filter kernel is characterized by its response function. For time series
we speak of an “impulse response function” or for images we call it “point
spread function”. This response function is given for every kernel by a
FittableModel, which is evaluated on a grid with
discretize_model() to obtain a kernel
array, which can be used for discrete convolution with the binned data.

Beside the astropy convolution functions
convolve and
convolve_fft, it is also possible to use
the kernels with Numpy or Scipy convolution by passing the array attribute.
This will be faster in most cases than the astropy convolution, but will not
work properly if NaN values are present in the data.

As all 2D kernels are symmetric it is sufficient to specify the width in one
direction. Therefore the use of 2D kernels is basically the same as for 1D
kernels. We consider a small Gaussian shaped source of amplitude one in the
middle of the image and add 10% noise:

The Gaussian kernel has better smoothing properties compared to the Box and the
Tophat. The Box filter is not isotropic and can produce artifact (the source
appears rectangular). The Mexican-Hat filter removes noise and slowly varying
structures (i.e. background) , but produces a negative ring around the source.
The best choice for the filter strongly depends on the application.

As convolution is a linear operation, kernels can be added or subtracted from each other.
They can also be multiplied with some number. One basic example would be the definition
of a Difference of Gaussian filter:

Mode 'linear_interp' takes the values at the corners of the bin and linearly
interpolates the value at the center:

>>> gauss_interp=Gaussian1DKernel(3,mode='linear_interp')

Mode 'oversample' evaluates the response function by taking the mean on an
oversampled grid. The oversample factor can be specified with the factor
argument. If the oversample factor is too large, the evaluation becomes slow.

>>> gauss_oversample=Gaussian1DKernel(3,mode='oversample',factor=10)

Mode 'integrate' integrates the function over the pixel using
scipy.integrate.quad and scipy.integrate.dblquad. This mode is very
slow and only recommended when highest accuracy is required.

>>> gauss_integrate=Gaussian1DKernel(3,mode='integrate')

Especially in the range where the kernel width is in order of only a few pixels
it can be advantageous to use the mode oversample or integrate to
conserve the integral on a subpixel scale.

The kernel models are normalized per default, i.e.
\(\int_{-\infty}^{\infty} f(x) dx = 1\). But because of the limited kernel
array size the normalization for kernels with an infinite response can differ
from one. The value of this deviation is stored in the kernel’s truncation
attribute.

The normalization can also differ from one, especially for small kernels, due
to the discretization step. This can be partly controlled by the mode
argument, when initializing the kernel (See also
discretize_model()). Setting the
mode to 'oversample' allows to conserve the normalization even on the
subpixel scale.

The kernel arrays can be renormalized explicitly by calling either the
normalize() method or by setting the normalize_kernel argument in the
convolve() and
convolve_fft() functions. The latter
method leaves the kernel itself unchanged but works with an internal normalized
version of the kernel.

Note that for MexicanHat1DKernel
and MexicanHat2DKernel there is
\(\int_{-\infty}^{\infty} f(x) dx = 0\). To define a proper normalization
both filters are derived from a normalized Gaussian function.