Gaussian.fit

giant.point_spread_functions.gaussians:

classmethod Gaussian.fit(x, y, z)[source]

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

The fit assumes that z = f(x, y) where f is the gaussian function (and thus z is the “height” of the gaussian function).

The fit performed is for a 2D gaussian function of the form

\[z = 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)}\]

The estimation in this function is performed by transforming the gaussian function into the logspace, which allows us to perform a true linear least squares fit without iteration but overweights the tails of the function. Therefore, it is best to constrain the data you are fitting to be near the peak of the PSF to ensure that too much noise is not being given extra weight in the fit.

If the fit is unsuccessful due to a rank deficient matrix or a fit of a hyperbolic surface the resulting data will be set to np.nan.

Parameters:
  • x (Sequence | ndarray) – The x values underlying the surface the PSF is to be fit to

  • y (Sequence | ndarray) – The y values underlying the surface the PSF is to be fit to

  • z (Sequence | ndarray) – The z or “height” values of the surface the PSF is to be fit to

Returns:

The initialized PSF with values according to the fit

Return type:

Gaussian