Fit functions

This module provides fit functions.

List of fit functions:

  • sum_gauss()
  • sum_agauss()
  • sum_splitgauss()
  • sum_fastagauss()
  • sum_apvoigt()
  • sum_pvoigt()
  • sum_splitpvoigt()
  • sum_lorentz()
  • sum_alorentz()
  • sum_splitlorentz()
  • sum_stepdown()
  • sum_stepup()
  • sum_slit()
  • sum_ahypermet()
  • sum_fastahypermet()

Full documentation:

silx.math.fit.atan_stepup(x, a, b, c)

Step up function using an inverse tangent.

Parameters:
  • x (numpy array) – Independent variable where the function is calculated
  • a – Height of the step up
  • b – Center of the step up
  • c – Parameter related to the slope of the step. A lower c value yields a sharper step.
Returns:

a * (0.5 + (arctan((x - b) / c) / pi))

Return type:

numpy array

silx.math.fit.periodic_gauss(x, *pars)

Return a sum of gaussian functions defined by (npeaks, delta, height, centroid, fwhm), where:

  • npeaks is the number of gaussians peaks
  • delta is the constant distance between 2 peaks
  • height is the peak amplitude of all the gaussians
  • centroid is the peak x-coordinate of the first gaussian
  • fwhm is the full-width at half maximum for all the gaussians
Parameters:
  • x – Independent variable where the function is calculated
  • pars(npeaks, delta, height, centroid, fwhm)
Returns:

Sum of npeaks gaussians

silx.math.fit.sum_agauss(x, *params)

Return a sum of gaussian functions defined by (area, centroid, fwhm), where:

  • area is the area underneath the peak
  • centroid is the peak x-coordinate
  • fwhm is the full-width at half maximum
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of gaussian parameters (length must be a multiple of 3): (area1, centroid1, fwhm1, area2, centroid2, fwhm2,...)
Returns:

Array of sum of gaussian functions at each x coordinate.

silx.math.fit.sum_ahypermet(x, *params, gaussian_term=True, st_term=True, lt_term=True, step_term=True)

Return a sum of ahypermet functions. defined by (area, position, fwhm, st_area_r, st_slope_r, lt_area_r, lt_slope_r, step_height_r).

  • area is the area underneath the gaussian peak
  • position is the center of the various peaks and the position of the step down
  • fwhm is the full-width at half maximum of the terms
  • st_area_r is factor between the gaussian area and the area of the short tail term
  • st_slope_r is a ratio related to the slope of the short tail in the low x values (the lower, the steeper)
  • lt_area_r is ratio between the gaussian area and the area of the long tail term
  • lt_slope_r is a ratio related to the slope of the long tail in the low x values (the lower, the steeper)
  • step_height_r is the ratio between the height of the step down and the gaussian height

A hypermet function is a sum of four functions (terms):

  • a gaussian term
  • a long tail term
  • a short tail term
  • a step down term
Parameters:
  • x (numpy.ndarray) – Independent variable where the hypermets are calculated
  • params – Array of hypermet parameters (length must be a multiple of 8): (area1, position1, fwhm1, st_area_r1, st_slope_r1, lt_area_r1, lt_slope_r1, step_height_r1...)
  • gaussian_term – If True, enable gaussian term. Default True
  • st_term – If True, enable gaussian term. Default True
  • lt_term – If True, enable gaussian term. Default True
  • step_term – If True, enable gaussian term. Default True
Returns:

Array of sum of hypermet functions at each x coordinate

silx.math.fit.sum_alorentz(x, *params)

Return a sum of Lorentz distributions, also known as Cauchy distribution, defined by (area, centroid, fwhm).

  • area is the area underneath the peak
  • centroid is the peak x-coordinate for both functions
  • fwhm is the full-width at half maximum
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of Lorentz parameters (length must be a multiple of 3): (area1, centroid1, fwhm1,...)
Returns:

Array of sum of Lorentz functions at each x coordinate

silx.math.fit.sum_apvoigt(x, *params)

Return a sum of pseudo-Voigt functions, defined by (area, centroid, fwhm, eta).

The pseudo-Voigt profile PV(x) is an approximation of the Voigt profile using a linear combination of a Gaussian curve G(x) and a Lorentzian curve L(x) instead of their convolution.

  • area is the area underneath both G(x) and L(x)
  • centroid is the peak x-coordinate for both functions
  • fwhm is the full-width at half maximum of both functions
  • eta is the Lorentz factor: PV(x) = eta * L(x) + (1 - eta) * G(x)
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of pseudo-Voigt parameters (length must be a multiple of 4): (area1, centroid1, fwhm1, eta1, area2, centroid2, fwhm2, eta2,...)
Returns:

Array of sum of pseudo-Voigt functions at each x coordinate

silx.math.fit.sum_fastagauss(x, *params)

Return a sum of gaussian functions defined by (area, centroid, fwhm), where:

  • area is the area underneath the peak
  • centroid is the peak x-coordinate
  • fwhm is the full-width at half maximum

This implementation differs from sum_agauss() by the usage of a lookup table with precalculated exponential values. This might speed up the computation for large numbers of individual gaussian functions.

Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of gaussian parameters (length must be a multiple of 3): (area1, centroid1, fwhm1, area2, centroid2, fwhm2,...)
Returns:

Array of sum of gaussian functions at each x coordinate.

silx.math.fit.sum_fastahypermet(x, *params, gaussian_term=True, st_term=True, lt_term=True, step_term=True)

Return a sum of hypermet functions defined by (area, position, fwhm, st_area_r, st_slope_r, lt_area_r, lt_slope_r, step_height_r).

  • area is the area underneath the gaussian peak
  • position is the center of the various peaks and the position of the step down
  • fwhm is the full-width at half maximum of the terms
  • st_area_r is factor between the gaussian area and the area of the short tail term
  • st_slope_r is a parameter related to the slope of the short tail in the low x values (the lower, the steeper)
  • lt_area_r is factor between the gaussian area and the area of the long tail term
  • lt_slope_r is a parameter related to the slope of the long tail in the low x values (the lower, the steeper)
  • step_height_r is the factor between the height of the step down and the gaussian height

A hypermet function is a sum of four functions (terms):

  • a gaussian term
  • a long tail term
  • a short tail term
  • a step down term

This function differs from sum_ahypermet() by the use of a lookup table for calculating exponentials. This offers better performance when calculating many functions for large x arrays.

Parameters:
  • x (numpy.ndarray) – Independent variable where the hypermets are calculated
  • params – Array of hypermet parameters (length must be a multiple of 8): (area1, position1, fwhm1, st_area_r1, st_slope_r1, lt_area_r1, lt_slope_r1, step_height_r1...)
  • gaussian_term – If True, enable gaussian term. Default True
  • st_term – If True, enable gaussian term. Default True
  • lt_term – If True, enable gaussian term. Default True
  • step_term – If True, enable gaussian term. Default True
Returns:

Array of sum of hypermet functions at each x coordinate

silx.math.fit.sum_gauss(x, *params)

Return a sum of gaussian functions defined by (height, centroid, fwhm), where:

  • height is the peak amplitude
  • centroid is the peak x-coordinate
  • fwhm is the full-width at half maximum
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of gaussian parameters (length must be a multiple of 3): (height1, centroid1, fwhm1, height2, centroid2, fwhm2,...)
Returns:

Array of sum of gaussian functions at each x coordinate.

silx.math.fit.sum_lorentz(x, *params)

Return a sum of Lorentz distributions, also known as Cauchy distribution, defined by (height, centroid, fwhm).

  • height is the peak amplitude
  • centroid is the peak x-coordinate
  • fwhm is the full-width at half maximum
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of Lorentz parameters (length must be a multiple of 3): (height1, centroid1, fwhm1,...)
Returns:

Array of sum Lorentz functions at each x coordinate

silx.math.fit.sum_pvoigt(x, *params)

Return a sum of pseudo-Voigt functions, defined by (height, centroid, fwhm, eta).

The pseudo-Voigt profile PV(x) is an approximation of the Voigt profile using a linear combination of a Gaussian curve G(x) and a Lorentzian curve L(x) instead of their convolution.

  • height is the peak amplitude of G(x) and L(x)
  • centroid is the peak x-coordinate for both functions
  • fwhm is the full-width at half maximum of both functions
  • eta is the Lorentz factor: PV(x) = eta * L(x) + (1 - eta) * G(x)
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of pseudo-Voigt parameters (length must be a multiple of 4): (height1, centroid1, fwhm1, eta1, height2, centroid2, fwhm2, eta2,...)
Returns:

Array of sum of pseudo-Voigt functions at each x coordinate

silx.math.fit.sum_slit(x, *params)

Return a sum of slit functions. defined by (height, position, fwhm, beamfwhm).

  • height is the slit’s amplitude
  • position is the center of the slit’s x-coordinate
  • fwhm is the full-width at half maximum of the slit
  • beamfwhm is the full-width at half maximum of the derivative, which is a measure of the sharpness of the edges of the slit
Parameters:
  • x (numpy.ndarray) – Independent variable where the slits are calculated
  • params – Array of slit parameters (length must be a multiple of 4): (height1, centroid1, fwhm1, beamfwhm1,...)
Returns:

Array of sum of slit functions at each x coordinate

silx.math.fit.sum_splitgauss(x, *params)

Return a sum of gaussian functions defined by (area, centroid, fwhm1, fwhm2), where:

  • height is the peak amplitude
  • centroid is the peak x-coordinate
  • fwhm1 is the full-width at half maximum for the distribution when x < centroid
  • fwhm2 is the full-width at half maximum for the distribution when x > centroid
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of gaussian parameters (length must be a multiple of 4): (height1, centroid1, fwhm11, fwhm21, height2, centroid2, fwhm12, fwhm22,...)
Returns:

Array of sum of split gaussian functions at each x coordinate

silx.math.fit.sum_splitlorentz(x, *params)

Return a sum of split Lorentz distributions, defined by (height, centroid, fwhm1, fwhm2).

  • height is the peak amplitude
  • centroid is the peak x-coordinate for both functions
  • fwhm1 is the full-width at half maximum for x < centroid
  • fwhm2 is the full-width at half maximum for x > centroid
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of Lorentz parameters (length must be a multiple of 4): (height1, centroid1, fwhm11, fwhm21...)
Returns:

Array of sum of Lorentz functions at each x coordinate

silx.math.fit.sum_splitpvoigt(x, *params)

Return a sum of split pseudo-Voigt functions, defined by (height, centroid, fwhm1, fwhm2, eta).

The pseudo-Voigt profile PV(x) is an approximation of the Voigt profile using a linear combination of a Gaussian curve G(x) and a Lorentzian curve L(x) instead of their convolution.

  • height is the peak amplitudefor G(x) and L(x)
  • centroid is the peak x-coordinate for both functions
  • fwhm1 is the full-width at half maximum of both functions when x < centroid
  • fwhm2 is the full-width at half maximum of both functions when x > centroid
  • eta is the Lorentz factor: PV(x) = eta * L(x) + (1 - eta) * G(x)
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of pseudo-Voigt parameters (length must be a multiple of 5): (height1, centroid1, fwhm11, fwhm21, eta1,...)
Returns:

Array of sum of split pseudo-Voigt functions at each x coordinate

silx.math.fit.sum_stepdown(x, *params)

Return a sum of stepdown functions. defined by (height, centroid, fwhm).

  • height is the step’s amplitude
  • centroid is the step’s x-coordinate
  • fwhm is the full-width at half maximum for the derivative, which is a measure of the sharpness of the step-down’s edge
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of stepdown parameters (length must be a multiple of 3): (height1, centroid1, fwhm1,...)
Returns:

Array of sum of stepdown functions at each x coordinate

silx.math.fit.sum_stepup(x, *params)

Return a sum of stepup functions. defined by (height, centroid, fwhm).

  • height is the step’s amplitude
  • centroid is the step’s x-coordinate
  • fwhm is the full-width at half maximum for the derivative, which is a measure of the sharpness of the step-up’s edge
Parameters:
  • x (numpy.ndarray) – Independent variable where the gaussians are calculated
  • params – Array of stepup parameters (length must be a multiple of 3): (height1, centroid1, fwhm1,...)
Returns:

Array of sum of stepup functions at each x coordinate