Gaussian

class giant.point_spread_functions.gaussians.Gaussian(sigma_x=1, sigma_y=0, size=None, amplitude=None, centroid_x=0, centroid_y=0, **kwargs)[source]

Bases: _GaussianSkeleton

A class for representing and fitting a standard (non-rotated) 2D gaussian point spread function.

This class represents a 2D Gaussian function of the form

\[f(x, y) = A e^{\left(-\left[\frac{(x-x_0)^2}{2\sigma_x^2}+\frac{(y-y_0)^2}{2\sigma_y^2}\right]\right)}\]

where \(A\) is the amplitude of the PSF, \(\sigma_x\) is the Gaussian RMS width in the x direction, \(\sigma_y\) is the Gaussian RMS width in the y direction, and \((x_0,y_0)\) is the centroid of the Gaussian (location of the peak response).

This class can be used for both estimating a Gaussian fit to an observed PSF (using the fit() class method to create an instance) as well as for applying the represented PSF to 1D scan lines (using apply_1d()) and 2D images (using the call capabilities of an instance of this class). In addition, if generated from a fit to data, this class will store the residuals and statistics about the residuals of the fit if the class attribute save_residuals is set to True before calling fit().

This class can be used anywhere GIANT expects a point spread function.

Parameters:
  • sigma_x (Real | None) – The Gaussian RMS width in the x direction in pixels

  • sigma_y (Real | None) – The Gaussian RMS Width in the y direction in pixels. If set to 0 or None this is set to be the same as sigma_x

  • size (int) – The size of the kernel to use when applying this PSF in pixels. If set to 0 or None will be computed based on the Gaussian RSM widths.

  • amplitude (Real | None) – The amplitude of the gaussian kernel to use when applying this PSF. If set to 0 or None this will be computed so that the kernel does not increase/decrease the total signal.

  • centroid_x (Real | None) – The x location of the peak of the Gaussian PSF in pixels. This is not used when applying the PSF, but it is used when fitting the PSF. Typically this is not specified by the user.

  • centroid_y (Real | None) – The y location of the peak of the Gaussian PSF in pixels. This is not used when applying the PSF, but it is used when fitting the PSF. Typically this is not specified by the user.

property covariance: ndarray | None

The formal covariance of the PSF parameters after fitting this PSF model to data.

If this instance is not the result of a fit (fit()) of if save_residuals is False then this will return None.

The order of the state vector (and thus the covariance matrix) is \([x_0, y_0, \sigma_x, \sigma_y, A]\).

sigma_x: float

The Gaussian RMS width in the x direction in pixels.

sigma_y

The Gaussian RMS width in the y direction in pixels.

amplitude: float

The amplitude of the Gaussian.

This specifies how much energy the Gaussian function increases or decreases the signal by.

Typically this is set so that the kernel does not increase or decrease the signal, which can be achieved by using the normalize_amplitude() method.

centroid_x: float

The x location of the peak of the Gaussian kernel

When applying the gaussian kernel, the centroid doesn’t matter as it will always be applied as if it was centered on a pixel. In general this is just used when estimating a kernel to locate the peak of the PSF in the image.

centroid_y: float

The y location of the peak of the Gaussian kernel

When applying the gaussian kernel, the centroid doesn’t matter as it will always be applied as if it was centered on a pixel. In general this is just used when estimating a kernel to locate the peak of the PSF in the image.

save_residuals: bool = False

This class attribute specifies whether to save the residuals when fitting the specified PSF to data.

Saving the residuals can be important for in depth analysis but can use a lot of space when many fits are being performed and stored so this defaults to off. To store the residuals simply set this to True before initialization.

property residuals: ndarray

A 1D array containing residuals of the fit of this Gaussian Model to data.

These are only populated when initialized by fit() and when the class attribute save_residuals is set to true.

size: int

The size of the kernel to return on a call to generate_kernel().

Typically this should be an odd number to ensure that the kernel is square and centered.

property residual_mean: float | None

The mean of the post-fit residuals after fitting this PSF model to data.

If this instance is not the result of a fit (fit()) or if save_residuals is False then this will return None

property residual_std: float | None

The standard deviation of the post-fit residuals after fitting this PSF model to data.

If this instance is not the result of a fit (fit()) or if save_residuals is False then this will return None

property residual_rss: float | None

The sum of squares of the post-fit residuals after fitting this PSF model to data.

If this instance is not the result of a fit (fit()) or if save_residuals is False then this will return None

Summary of Methods

fit

This fits a 2d gaussian function to a surface using least squares estimation.

__call__

Applies the represented Gaussian PSF to a 2D array.

apply_1d

Applies the defined PSF using the stored parameters to the 1D image scans provided.

apply_1d_sized

Applies the defined PSF using the stored parameters to the 1D image scans provided with a given kernel size.

compute_jacobian

This method computes the Jacobian of the PSF with respect to a change in the state.

determine_size

Sets the size for the kernel based on the width of the PSF.

evaluate

This method evaluates the PSF at the given x and y.

generate_kernel

Generates a square kernel centered at the centroid of the PSF normalized to have a volume (sum) of 1 for the size input or specified in the size attribute.

normalize_amplitude

Calculate and store the amplitude that makes the volume under the gaussian surface equal to 1

update_state

Updates the current values based on the provided update vector.