autowisp.image_smoothing module
Class Inheritance Diagram

Define classes for smoothing images.
- class autowisp.image_smoothing.ChainSmoother(*smoothers, **kwargs)[source]
Bases:
ImageSmoother
Combine more than one smoothers, each is applied sequentially.
Works much like a list of smoothers, except it adds smooth and detrend methods.
- smoothing_chain
The current list of smoothers and the order in which they are applied. The first will be applied to the input image, the second will be applied to the result of the first etc.
- class autowisp.image_smoothing.ImageSmoother(**kwargs)[source]
Bases:
ABC
Define the interface for applying smoothing algorithms to images.
- __init__(**kwargs)[source]
Set default pre-shrink/post-zoom bin factor and interpolation order.
- Parameters:
kwargs – All arguments except bin_factor, interp_order and padding mode(see
smooth()
) are ignored.- Returns:
None
- abstractmethod _apply_smoothing(image, **kwargs)[source]
Return a smooth version of the given image (no pre-shrinking).
- Parameters:
image – The image to smooth.
kwargs – Any arguments configuring how smoothing is to be performed.
- Returns:
The smoothed version of the image per the currently defined smoothing.
- Return type:
2-D array
- smooth(image, *, bin_factor=None, zoom_interp_order=None, padding_mode='reflect', **kwargs)[source]
Sandwich smoothing between initial binning and final zoom.
- Parameters:
image – The image to smooth.
bin_factor – The factor to pre-bin the image by (see
autowisp.image_utilities.bin_image()
for details). After smoothing the image is zoomed by the same factor to recover the original size. If None, the value defined at construction is used, otherwise this value appliesfor this image only.interp_order – The interpolation order to use when zooming the image at the end. If None, the interpolation order defined at construction is used, otherwise this value applies for this image only.
padding_mode – How to pad the image to have an integer number of bins, if pre-binning and post-zooming is used.
kwargs – Any arguments configuring how smoothing is to be performed.
- Returns:
The smoothed version of the image.
- Return type:
2-D array
- class autowisp.image_smoothing.PolynomialImageSmoother(*, num_x_terms=None, num_y_terms=None, outlier_threshold=None, max_iterations=None, **kwargs)[source]
Bases:
SeparableLinearImageSmoother
Smooth image is modeled as a polynomial in x times another polynomial in y.
- static _get_powerlaw_pixel_integrals(power, resolution)[source]
Return the integrals over one pixel dimension of x^power for each pixel.
- Parameters:
power – The power of the corresponding coordinate of the term we are integrating.
resolution – The resolution of the image in the dimension in which to calculate the pixel integrlas.
- Returns:
An array with the i-th entry being the integral of the scaled x coordinate to the given power over each pixel.
- Return type:
1-D array
- static get_x_pixel_integrals(power, resolution)
Return the integrals over one pixel dimension of x^power for each pixel.
- Parameters:
power – The power of the corresponding coordinate of the term we are integrating.
resolution – The resolution of the image in the dimension in which to calculate the pixel integrlas.
- Returns:
An array with the i-th entry being the integral of the scaled x coordinate to the given power over each pixel.
- Return type:
1-D array
- static get_y_pixel_integrals(power, resolution)
Return the integrals over one pixel dimension of x^power for each pixel.
- Parameters:
power – The power of the corresponding coordinate of the term we are integrating.
resolution – The resolution of the image in the dimension in which to calculate the pixel integrlas.
- Returns:
An array with the i-th entry being the integral of the scaled x coordinate to the given power over each pixel.
- Return type:
1-D array
- class autowisp.image_smoothing.SeparableLinearImageSmoother(*, num_x_terms=None, num_y_terms=None, outlier_threshold=None, max_iterations=None, **kwargs)[source]
Bases:
ImageSmoother
Handle smoothing function = product of linear functions in each dimension.
In more detail this is a base class that perform smoothing with a smoothing function consisting of the product of separate smoothing functions in x and y, each of which predicts pixel values as a linear combination of some parameters.
- num_x_terms
The number of terms in the smoothing function in the x direction.
- num_y_terms
The number of terms in the smoothing function in the y direction.
- __init__(*, num_x_terms=None, num_y_terms=None, outlier_threshold=None, max_iterations=None, **kwargs)[source]
Define the default smoothing configuration (overwritable on use).
- Parameters:
num_x_terms – See same name argument to
_apply_smoothing()
.num_y_terms – See same name argument to
_apply_smoothing()
.outlier_threshold – See same name argument to
_apply_smoothing()
.max_iterations – See same name argument to
_apply_smoothing()
.kwargs – Any arguments to pass to parent’s
__init__
.
- Returns:
None
- _apply_smoothing(image, *, num_x_terms=None, num_y_terms=None, outlier_threshold=None, max_iterations=None)[source]
Return a smooth version of the given image.
- Parameters:
image – The image to smooth.
num_x_terms – The number of parameters of the x smoothing function.
num_y_terms – The number of parameters of the y smoothing function.
outlier_threshold – The threshold for discarding pixel values as being outliers. See same name argument to
autowisp.iterative_rejection_util.iterative_rej_linear_leastsq()
.max_iterations – The maximum number of reject/re-fit iterations allowed. See same name argument to
autowisp.iterative_rejection_util.iterative_rej_linear_leastsq()
.
- Returns:
- 2-D array:
The best approximation of the input image possible with the smoothing function.
- float:
The root mean square residual returned by
autowisp.iterative_rejection_util.iterative_rej_linear_leastsq()
.
- Return type:
(tuple)
- _get_smoothing_matrix(num_x_terms, num_y_terms, y_resolution, x_resolution)[source]
Return matrix giving flattened smooth image when applied to fit params.
- Parameters:
num_x_terms – See same name argument to
_apply_smoothing()
.num_y_terms – See same name argument to
_apply_smoothing()
.x_resolution – The number of image columns.
y_resolution – The number of image rows.
- Returns:
An (x_res * y_res) by (num_x_terms * num_y_terms) matrix which when applied to a set of parameters returns the value of each image pixel per the smoothing function.
- Return type:
2-D array
- abstractmethod get_x_pixel_integrals(param_ind, x_resolution)[source]
Return the x smoothing func. integral over pixels for 1 nonzero param.
- Parameters:
param_ind – The index of the input parameter which is non-zero.
x_resolution – The resolution of the input image in the x direction.
- Returns:
Array with length equal to the x-resolution of the image with the i-th entry being the integral of the x part of the smoothing function over the i-th pixel.
- Return type:
1-D array
- class autowisp.image_smoothing.SplineImageSmoother(*, num_x_nodes=None, num_y_nodes=None, spline_degree=3, **kwargs)[source]
Bases:
SeparableLinearImageSmoother
Smooth image is modeled as a product of cubic splines in x and y.
- __init__(*, num_x_nodes=None, num_y_nodes=None, spline_degree=3, **kwargs)[source]
Set-up spline interpolation with the given number of nodes.
- Parameters:
num_x_nodes – The number of spline nodes for the x spline.
num_y_nodes – The number of spline nodes for the y spline.
kwargs – Forwarded directly to
SeparableLinearImageSmoother.__init__()
, along with num_x_terms = num_x_nodes and num_y_terms = num_y_nodes.
- Returns:
None
- _apply_smoothing(image, *, num_x_nodes=None, num_y_nodes=None, **kwargs)[source]
Handle change in interpolation nodes needed by integrals functions.
- Parameters:
() – See
SeparableLinearImageSmoother._apply_smoothing()
except the names of num_x_terms and num_y_terms have been changed to num_x_nodes and num_y_nodes respectively.- Returns:
None
- static get_spline_pixel_integrals(node_index, resolution, num_nodes, spline_degree)[source]
Return the integrals over one pixel dimension of a basis spline.
The spline basis functions are defined as an interpolating spline (i.e. no smoothing) over y values that are one for the node_index-th node and zero everywhere else.
- Parameters:
node_index – The node at which the spline should evaluate to one. All other nodes get a value of zero.
resolution – The resolution of the image in the dimension in which to calculate the pixel integrlas.
num_nodes – The number of nodes in the spline. The image is scaled to have a dimension of (num_nodes - 1) and nodes are set at integer values.
spline_degree – The degree of the spline to use.
- Returns:
An array with the i-th entry being the integral of the spline over the i-th pixel.
- Return type:
1-D array
- get_x_pixel_integrals(param_ind, x_resolution)[source]
Return integrals of the param_ind-th x direction spline basis function.
- Parameters:
() – See
SeparableLinearImageSmoother.get_x_pixel_integrals()
.- Returns:
- get_y_pixel_integrals(param_ind, y_resolution)[source]
Return integrals of the param_ind-th y direction spline basis function.
- Parameters:
() – See
SeparableLinearImageSmoother.get_y_pixel_integrals()
.- Returns:
- class autowisp.image_smoothing.WrapFilterAsSmoother(smoothing_filter, *, bin_factor=None, zoom_interp_order=None, **filter_config)[source]
Bases:
ImageSmoother
Wrap one of the numpy or astropy image filters in a smoother.
- __init__(smoothing_filter, *, bin_factor=None, zoom_interp_order=None, **filter_config)[source]
Apply the given filter through the ImageSmoother interface.
- Parameters:
smoothing_filter – The filter to apply to smooth images.
bin_factor – See
ImageSmoother.smooth()
.zoom_interp_order – See
ImageSmoother.smooth()
.filter_config – Any arguments to pass to the filter when applying, unless overwritten by arguments to
smooth()
ordetrend()
.
- Returns:
None