Filter 2D list Python

Filter2D 2-dimensional spectral filtering.¶

This module defines the 2D filter methods.

class admit.util.filter.Filter2D.Filter2D[data, method, **keyval][source]

This class defines and runs 2D spectral filters. The currently available filters are Gaussian, Hanning, Triangle, Welch, Boxcar, and Savitzky Golay. The output spectrum will be of the same length as the input spectrum, however some edge channels may be zeroed by some methods, depending on the input parameters.

Parameters:

spec : numpy array

2D numpy array of the input spectrum [just the amplitudes].

method : str

The smoothing filter to apply: boxcar, gaussian, welch, hanning, triangle, or savgol. No default. Minimum matching is enabled with a minimum of 3 characters, i.e. box = boxcar.

keyval : various

Any keyword value pairs for the specific method chosen, see the notes for specific keywords.

Notes

Details of the different filter keywords and defaults:

FilterKeywordDef.Description
boxcarwidth3Number of channels to average together
gaussianwidth7Number of channels to span with the gaussian
hanningwidth5Number of channels to include in the cos
trianglewidth5Number of channels to span with the triangle
welchwidth5Number of channels to use in the function
savgolwindow_size7Number of channels to use in the calculation
order3Order of the poynomial fit [must be odd]
deriv0The number of the derivative to compute [0 = just smooth]

Attributes

spec[numpy array] The spectrum.
len[int] The length of the spectrum.
methods[list] A list of the available filters.
[method]_args[dict] A dictionary for each method giving its keywords and defaults [e.g. boxcar_args].
method[str] The method being used.

Methods

boxcar[width]Method to apply a boxcar filter to a spectrum.
checkmethod[method]Method to interpret the input method and determine the full method
gaussian[width]Method to apply a Gaussian filter to a spectrum.
hanning[width]Method to apply a Hanning filter to a spectrum.
radius[x,y,width]Method to calculate the radius of a point in the kernel
run[]Method to run the selected filter on the data
savgol[window_size,order[,deriv]]Method to apply a Savitzky-Golay filter to a 2D image.
triangle[width]Method to apply a Triangular filter to a spectrum.
welch[width]Method to apply a Welch filter to a spectrum.
boxcar[width][source]

Method to apply a boxcar filter to a spectrum. The filter for point x[i] is defined as:

\[x[i] = \frac{1}{N} \sum_{n=0}^{N} x[i + n - \frac{N - 1}{2}]\]

where N is the width of the filter.

Parameters:Returns:

width : int

The width of the box to use in channels, must be odd

numpy array

The smoothed image, [width - 1]/2 edge channels will be zeroed

checkmethod[method][source]

Method to interpret the input method and determine the full method name

Parameters:Returns:

method : str

The method to use, minimal matching is possible, with a minimum of 3 characters [e.g. box will be interpreted to be boxcar]

None

gaussian[width][source]

Method to apply a Gaussian filter to a spectrum. The filter for point x[i] is defined as:

\[x[i] = \frac{3}{N} \sum_{n=0}^{N} x[i + n - \frac{N - 1}{2}] e^{-\frac{1}{2}\left[\frac{n-[N-1]/2}{\sigma[N-1]/2}\right]^2}\]

where N is the width of the filter.

Parameters:Returns:

width : int

The number of channels to span with the gaussian for each iteration, must be odd

numpy array

The smoothed image, [width - 1]/2 edge channels will be zeroed

hanning[width][source]

Method to apply a Hanning filter to a spectrum. The filter for point x[i] is defined as:

\[x[i] = \frac{2}{N-1} \sum_{n=0}^{N} x[i + n - \frac{N - 1}{2}] 0.5 \left[1 - \cos\left[\frac{2\pi n}{N-1}\right]\right]\]

where N is the width of the filter.

Parameters:Returns:

width : int

The number of channels to span with the function for each iteration, must be odd

numpy array

The smoothed image, [width - 1]/2 edge channels will be zeroed

radius[x, y, width][source]

Method to calculate the radius of a point in the kernel

Parameters:Returns:

x : float

The x coordinate

y : float

The y coordinate

width : int

The width of the Gaussian being used

Float containing the radius to the point

run[][source]

Method to run the selected filter on the data

Parameters:Returns:
None
The smoothed image
savgol[window_size, order, deriv=None][source]

Method to apply a Savitzky-Golay filter to a 2D image.

Parameters:Returns:

window_size : int

the size of the window. Must be an odd integer number.

order : int

the order of the polynomial used in the filtering. Must be less then window_size - 1.

deriv: int

the order of the derivative to compute [default = None means only smoothing]

numpy array

The smoothed image, [width - 1]/2 edge channels will be zeroed

triangle[width][source]

Method to apply a Triangular filter to a spectrum. The filter for point x[i] is defined as:

\[x[i] = \sum_{n=0}^{N} x[i + n - \frac{N - 1}{2}] \left[1 - \left|\frac{n-\frac{N-1}{2}}{\frac{N}{2}}\right|\right]\]

where N is the width of the filter.

Parameters:Returns:

width : int

The number of channels to span with the function for each iteration, must be odd

numpy array

The smoothed image, [width - 1]/2 edge channels will be zeroed

welch[width][source]

Method to apply a Welch filter to a spectrum. The filter for point x[i] is defined as:

\[x[i] = \frac{3}{2[N-1]} \sum_{n=0}^{N} x[i + n - \frac{N - 1}{2}] \left[1 - \left[\frac{n - \frac{N-1}{2}}{\frac{N-1}{2}}\right]^2\right]\]

where N is the width of the filter.

Parameters:Returns:

width : int

The number of channels to span with the function for each iteration, must be odd

numpy array

The smoothed image, [width - 1]/2 edge channels will be zeroed

Video liên quan

Chủ Đề