GeneralizedGaussian¶
- class giant.point_spread_functions.gaussians.GeneralizedGaussian(a_coef=None, b_coef=None, c_coef=None, sigma_x=None, sigma_y=None, theta=None, amplitude=None, centroid_x=0, centroid_y=0, size=None, **kwargs)[source]¶
Bases:
KernelBasedCallPSF
,_GaussianSkeleton
A class for representing and fitting a generalized (rotated) 2D gaussian point spread function.
This class represents a 2D Gaussian function of the form
\[f(x, y) = A e^{\left(-\left[a(x-x_0)^2 + 2b (x-x_0)(y-y_0) + c (y-y_0)^2\right]\right)}\]where \(A\) is the
amplitude
of the PSF, \(a\) is the coefficient for \((x-x_0)^2\), \(c\) is the coefficient for \((y-y_0)^2\), \(b\) is the coefficient for \((x-x_0)(y-y_0)\), and \((x_0,y_0)\) is the centroid of the Gaussian (location of the peak response).This is equivalent to a function of the form
\[\begin{split}f(x, y) = A e^{-\left[\begin{array}{cc} (x-x_0) & (y-y_0)\end{array}\right]\mathbf{B}\mathbf{S}\mathbf{B}^T \left[\begin{array}{c}(x-x_0) \\ (y-y_0)\end{array}\right]}\end{split}\]where
\[\begin{split}\mathbf{B} = \left[\begin{array}{cc} \text{cos}(\theta) & -\text{sin}(\theta) \\ \text{sin}(\theta) & \text{cos}(\theta)\end{array}\right] \\ \mathbf{S} = \left[\begin{array}{cc} \frac{1}{\sigma_x^2} & 0 \\ 0 & \frac{1}{\sigma_y^2}\end{array}\right]\end{split}\]\(\theta\) is the angle between the x-axis and the principal axis of the Gaussian, \(sigma_x\) is the Gaussian RMS width in the semi-major axis direction, and \(\sigma_x\) is the RMS width in the semi-minor axis direction.
When creating an instance of this class you can specify either
a, b, c
orsigma_x, sigma_y, theta
and the class will convert and store appropriately. This class also allows you to retrieve eithera, b, c
orsigma_x, sigma_y, theta
.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 (usingapply_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 :attr:`save_residuals()
is set to True before callingfit()
.This class can be used anywhere GIANT expects a point spread function.
- Parameters:
a_coef (float) – The a coefficient of the Gaussian polynomial
b_coef (float) – The b coefficient of the Gaussian polynomial
c_coef (float) – The c coefficient of the Gaussian polynomial
sigma_x (float) – The Gaussian RMS width in the x direction in pixels
sigma_y (float) – The Gaussian RMS Width in the y direction in pixels. If set to 0 or
None
this is set to be the same assigma_x
sigma_x – The angle between the x-axis and the principal axis of the Gaussian in radians.
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 (float) – 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 (float) – 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 (float) – 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.
theta (float) –
- save_residuals = 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
either before or after initialization.
- 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.
- 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 attributesave_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 ifsave_residuals
isFalse
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 ifsave_residuals
isFalse
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 ifsave_residuals
isFalse
then this will return None
- a_coef: float¶
The \((x-x_0)^2\) coefficient from the exponential component of the generalized 2D Gaussian.
- b_coef: float¶
The \((x-x_0)(y-y_0)\) coefficient from the exponential component of the generalized 2D Gaussian.
- c_coef: float¶
The \((y-y_0)^2\) coefficient from the exponential component of the generalized 2D Gaussian.
- sigma_x: float¶
The RMS width in the semi-major axis direction.
- sigma_y: float¶
The RMS width in the semi-minor axis direction.
- theta: float¶
The angle between the semi-major axis and the x axis
- 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 ifsave_residuals
isFalse
then this will return None.The order of the state vector (and thus the covariance matrix) is \([x_0, y_0, a, b, c, A]\).
Summary of Methods
This fits a generalized (rotated) 2d gaussian function to a surface using least squares estimation. |
|
This method generates a kernel and then convolves it with the input image. |
|
Applies the defined PSF using the stored parameters to the 1D image scans provided. |
|
Applies the defined PSF using the stored parameters to the 1D image scans provided with a given kernel size. |
|
This method computes the Jacobian of the PSF with respect to a change in the state. |
|
Sets the size for the kernel based on the width of the PSF. |
|
This method evaluates the PSF at the given x and y. |
|
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 |
|
Calculate and store the amplitude that makes the volume under the gaussian surface equal to 1 |
|
Updates the current values based on the provided update vector. |