statistics — 2D Gaussian fitting

foregrounds_diffusion.statistics.gaussian(height, center_x, center_y, width_x, width_y)[source]

Return a 2D Gaussian function with the given parameters.

Parameters:
  • height (float) – Peak amplitude.

  • center_x, center_y (float) – Centre coordinates.

  • width_x, width_y (float) – Standard deviations along x and y.

Returns:

callable – Function f(x, y) evaluating the Gaussian at (x, y).

foregrounds_diffusion.statistics.moments(data)[source]

Estimate 2D Gaussian parameters from image moments.

Parameters:

data (ndarray, shape (ny, nx)) – 2D image.

Returns:

tuple(height, x, y, width_x, width_y)

foregrounds_diffusion.statistics.fitgaussian(data)[source]

Fit a 2D Gaussian to an image using least squares.

Parameters:

data (ndarray, shape (ny, nx)) – 2D image.

Returns:

tuple(height, x, y, width_x, width_y) — best-fit parameters.

foregrounds_diffusion.statistics.fitting_func(p, p0, xgrid, ygrid, tmap, lbounds=None, ubounds=None, fixed=None, return_fit=0)[source]

Evaluate or fit a 2D Gaussian model on a pixel grid.

Used internally by get_mask_using_gaussian_fitting().

Parameters:
  • p (array_like) – Current parameter vector [baseline, amp, x_cen, y_cen, width, ...].

  • p0 (array_like) – Reference parameter vector (used to restore fixed parameters).

  • xgrid, ygrid (ndarray) – Pixel coordinate grids.

  • tmap (ndarray) – Target map (used as fall-back return on bound violations).

  • lbounds, ubounds (array_like, optional) – Lower and upper parameter bounds.

  • fixed (array_like of int, optional) – Indices of parameters to hold fixed at p0.

  • return_fit (int) – If 1, return the model image; if 0, return the residual vector.

Returns:

ndarray – Residual vector (when return_fit=0) or model image (when return_fit=1).

foregrounds_diffusion.statistics.stats(maps)[source]

Return (min, max, mean, std) of an array.

Parameters:

maps (ndarray) – Input array.

Returns:

tuple of float(min, max, mean, std)