slmsuite.misc.fitfunctions.gaussian2d

gaussian2d(xy, x0, y0, a, c, wx, wy, wxy=0)[source]

For fitting a 2D Gaussian.

When the shear variance wxy (equivalent to \(M_{11}\); see image_moment()) is zero,

\[z(x,y) = c + a \exp \left[ \frac{(x-x_0)^2}{2w_x^2} + \frac{(y-y_0)^2}{2w_y^2} \right].\]

When wxy is nonzero, we want to find the Gaussian which will have second order central moments (equivalent to variance; see image_variances()) satisfying:

\[\begin{split}M = \begin{bmatrix} M_{20} & M_{11} \\ M_{11} & M_{02} \end{bmatrix} = \begin{bmatrix} w_x^2 & w_{xy} \\ w_{xy} & w_y^2 \end{bmatrix}.\end{split}\]

The equation satisfying this condition is:

\[z(x,y) = c + a \exp \left[ -\frac{1}{2}\left( K_{00}(x-x_0)^2 + 2*K_{10}(x-x_0)(y-y_0) + K_{11}(y-y_0)^2 \right) \right].\]

Where

\[\begin{split}K = \begin{bmatrix} K_{00} & K_{10} \\ K_{10} & K_{11} \end{bmatrix} = M^{-1}.\end{split}\]

Caution

The shear variance \(w_{xy}\) does not have the same units as the widths \(w_x\) and \(w_y\).

Note

The shear variance wxy is currently bounded to magnitudes below wx*wy. Higher values lead to solutions which cannot be normalized. When wxy = wx*wy, this distribution is a line (an ellipse with zeroed minor axis).

Parameters
  • xy (numpy.ndarray) – Points to fit upon. (x, y) form.

  • x0 (float) – Vector offset.

  • y0 (float) – Vector offset.

  • a (float) – Amplitude.

  • c (float) – constant offset.

  • wx (float) – The standard deviation of the normal distribution. Equivalent to the \(1/e\) radius. This is related to the full width at half maximum (FWHM) by a factor of \(2\sqrt{2\ln{2}}\).

  • wy (float) – The standard deviation of the normal distribution. Equivalent to the \(1/e\) radius. This is related to the full width at half maximum (FWHM) by a factor of \(2\sqrt{2\ln{2}}\).

  • wxy (float) – Shear variance. See above.

Returns

z – Gaussian fit evaluated at all (x,y) in xy.

Return type

numpy.ndarray