superphot_pipeline.image_smoothing module

Class Inheritance Diagram

Inheritance diagram of ABC, ChainSmoother, ImageSmoother, PolynomialImageSmoother, SeparableLinearImageSmoother, SplineImageSmoother, WrapFilterAsSmoother

Define classes for smoothing images.

class superphot_pipeline.image_smoothing.ChainSmoother(*smoothers, **kwargs)[source]

Bases: superphot_pipeline.image_smoothing.ImageSmoother

Inheritance diagram of superphot_pipeline.image_smoothing.ChainSmoother

Combine more than one smoothers, each is applied sequentially.

Works much like a list of smoothers, except it adds smooth and detrend methods.

Attrs:
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.
__delitem__(position)[source]

Delete smoothe at position.

__init__(*smoothers, **kwargs)[source]

Create a chain combining the given smoothers in the given order.

Parameters:
  • smoothers – A list of the image smoothers to combine.
  • kwargs – Any arguments to pass to parent constructor.
__setitem__(position, smoother)[source]

Replace the smoother at position.

_apply_smoothing(image)[source]

Smooth the given image using the current chain of smoothers.

append(smoother)[source]

Add a new smoother to the end of the sequence.

clear()[source]

Like list clear.

extend(smoothers)[source]

Add multiple smoothers to the end of the chain.

insert(position, smoother)[source]

Like list insert.

pop(position=-1)[source]

Like list pop.

remove(smoother)[source]

Like list remove.

class superphot_pipeline.image_smoothing.ImageSmoother(**kwargs)[source]

Bases: abc.ABC

Inheritance diagram of superphot_pipeline.image_smoothing.ImageSmoother

Define the interface for applying smoothing algorithms to images.

Attrs:

bin_factor: See same name argument to smooth().

zoom_interp_order: See same name argument to smooth().

__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
_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:

smooth_image

detrend(image, **kwargs)[source]

De-trend the input image by its smooth version (see smooth).

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 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 applies for 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:

smooth_image

class superphot_pipeline.image_smoothing.PolynomialImageSmoother(*, num_x_terms=None, num_y_terms=None, outlier_threshold=None, max_iterations=None, **kwargs)[source]

Bases: superphot_pipeline.image_smoothing.SeparableLinearImageSmoother

Inheritance diagram of superphot_pipeline.image_smoothing.PolynomialImageSmoother

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:

A 1-D scipy array with the i-th entry being the

integral of the scaled x coordinate to the given power over each pixel.

Return type:

integrals

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:

A 1-D scipy array with the i-th entry being the

integral of the scaled x coordinate to the given power over each pixel.

Return type:

integrals

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:

A 1-D scipy array with the i-th entry being the

integral of the scaled x coordinate to the given power over each pixel.

Return type:

integrals

class superphot_pipeline.image_smoothing.SeparableLinearImageSmoother(*, num_x_terms=None, num_y_terms=None, outlier_threshold=None, max_iterations=None, **kwargs)[source]

Bases: superphot_pipeline.image_smoothing.ImageSmoother

Inheritance diagram of superphot_pipeline.image_smoothing.SeparableLinearImageSmoother

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.

Attrs:
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 iterative_rej_linear_leastsq().
  • max_iterations – The maximum number of reject/re-fit iterations allowed. See same name argument to iterative_rej_linear_leastsq().
Returns:

The best approximation of the input image possible

with the smoothing function.

residual: The root mean square residual returned

by iterative_rej_linear_leastsq()

Return type:

smooth_image

_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:

matrix

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:

A 1-D scipy 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 the i-th pixel.

Return type:

integrals

get_y_pixel_integrals(param_ind, y_resolution)[source]

See get_x_pixel_integrals.

class superphot_pipeline.image_smoothing.SplineImageSmoother(*, num_x_nodes=None, num_y_nodes=None, spline_degree=3, **kwargs)[source]

Bases: superphot_pipeline.image_smoothing.SeparableLinearImageSmoother

Inheritance diagram of superphot_pipeline.image_smoothing.SplineImageSmoother

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__() after 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.

Args: 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:

A 1-D scipy array with the i-th entry being the

integral of the spline over the i-th pixel.

Return type:

integrals

get_x_pixel_integrals(param_ind, x_resolution)[source]

Return integrals of the param_ind-th x direction spline basis function.

Args: See SeparableLinearImageSmoother.get_x_pixel_integrals()

Returns:See SeparableLinearImageSmoother.get_x_pixel_integrals()
get_y_pixel_integrals(param_ind, y_resolution)[source]

Return integrals of the param_ind-th y direction spline basis function.

Args: See SeparableLinearImageSmoother.get_y_pixel_integrals()

Returns:See SeparableLinearImageSmoother.get_y_pixel_integrals()
class superphot_pipeline.image_smoothing.WrapFilterAsSmoother(smoothing_filter, *, bin_factor=None, zoom_interp_order=None, **filter_config)[source]

Bases: superphot_pipeline.image_smoothing.ImageSmoother

Inheritance diagram of superphot_pipeline.image_smoothing.WrapFilterAsSmoother

Wrap one of the scipy 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() or detrend().
Returns:

None

_apply_smoothing(image, **kwargs)[source]

Smooth the given image with the filter supplied on construction.

Parameters:
  • image – The image to smooth.
  • kwargs – Additional or replacement arguments to pass to the filter when applying.