upsp.target_localization.gaussian_fitting_methods

gauss_fitter_func(fit, get_rms=False, curve_fit_kwds=None, debug=False)[source]

Returns a function that acts as a wrapper around a 2D Gaussian function to act as a target center localizer

Parameters
  • fit ({'super', 'normal'}) – Specifies fitting function to use, super or standard 2D Gaussian

  • get_rms (bool, optional) – If True, adds rms to output. If False does not

  • curve_fit_kwds (dict, optional) – Keyword arguments for scipy curve fit optimizer. If None, the following keywords are used: {'maxfev' : 25000, 'ftol' : 1e-4, 'xtol' : 1e-4}

  • debug (bool, optional) – If True, adds full optimization parameters and covariance matrix to output. If False does not

Returns

2D Gaussian Fitting Function - returns center of target given an image

Wrapper around optimizer of 2D Gaussian functions to act as target localization function.

Arguments:

  • img (numpy.ndarray, 2 dimensional (grayscale), unint8) : Image with one target. Typically small

  • center (tuple of length 2, float): Initialization for target localization

  • target_type ({'dot', 'kulite', None}): Type of target in image. Used to initialize target finding parameters

  • img_offset (tuple or None): Since the center location is from the whole image, and the localizer is a local function, the offset tells where the center location is in the local image. Additionally, output is offset by img_offset to give the target’s location in the whole image. If None, do none of that.

Returns:

If debug input is False, return tuple contains center as first item. Center is a tuple of 2 floats denoting the target x and y position.

If get_rms is True, return tuple contains rms error as second item. If get_rms is False, return tuple has no second item.

If debug input is True, return tuple contains an inner tuple as the first item. The inner tuple contains the full set of optimizer parameters as the first item, and the covariance matrix as the second item.

If there is an error in the optimization, all None’s will be returned for the center, optimizer parameters, covatiance matrix, and rms as needed.

Return type

callable

super_twoD_Gaussian(pt, amplitude, xo, yo, sx, sy, theta, offset, p)[source]

Returns the value of a super 2D Gaussian function at the given point

See https://en.wikipedia.org/wiki/Gaussian_function#Higher-order_Gaussian_or_super-Gaussian_function

Parameters
  • pt (numpy.ndarray, shape (N, 2), float) – 2D Gaussian function point input. Length of output is equal to length of pt

  • amplitude (float) – Amplitude of super 2D Gaussian

  • xo (float) – mean position of super 2D Gaussian (center of target)

  • yo (float) – mean position of super 2D Gaussian (center of target)

  • sx (float) – standard deviations of super 2D Gaussian

  • sy (float) – standard deviations of super 2D Gaussian

  • theta (float) – Angle of super 2D Gaussian ellipse

  • offset (float) – Floor of super 2D Gaussian

  • p (float) – Power of super 2D Gaussian. Higher power is more platykurtic

Returns

Value of super 2D Gaussian function with given parameters at given point(s). Length of return is equal to length of the pt input

Return type

float or numpy.ndarray, shape (N, 1)

super_twoD_Gaussian_nobounds(pt, ln_amplitude, xo, yo, ln_sx, ln_sy, theta, offset, ln_p)[source]

Wrapper to call super_twoD_Gaussian() with no bounds on inputs

For super_twoD_Gaussian(), the function does not make physical sense if amplitude, the standard deviations, or power are non-positive. (power must be > 1 for the function to be platykurtic)

super_twoD_Gaussian_nobounds() is for optimizers that require no bounds. The natural logarithm of those values are passed to this function, and those values are passed through exp() before being passed to super_twoD_Gaussian. Those parameters can then vary from -inf to +inf, and will be mapped to (0, np.inf]

Parameters
  • pt (numpy.ndarray, shape (N, 2), float) – 2D Gaussian function point input. Length of output is equal to length of pt

  • ln_amplitude (float) – Natural log of the amplitude of super 2D Gaussian

  • xo (float) – mean position of super 2D Gaussian (center of target)

  • yo (float) – mean position of super 2D Gaussian (center of target)

  • ln_sx (float) – Natural log of standard deviations of super 2D Gaussian

  • ln_sy (float) – Natural log of standard deviations of super 2D Gaussian

  • theta (float) – Angle of super 2D Gaussian ellipse

  • offset (float) – Floor of super 2D Gaussian

  • ln_p (float) – Natural log of the power of super 2D Gaussian minus 1. p = exp(ln_p) + 1 Higher power is more platykurtic.

Returns

Value of super 2D Gaussian function with given parameters at given point(s). Length of return is equal to length of the pt input

Return type

float or numpy.ndarray, shape (N, 1)

See also

super_twoD_Gaussian

Returns the value of a super 2D Gaussian function at the given point

twoD_Gaussian(pt, amplitude, xo, yo, sx, sy, theta, offset)[source]

Wrapper to call super_twoD_Gaussian() with a power of 1

See also

super_twoD_Gaussian

Returns the value of a super 2D Gaussian function at the given point