fit module

Function and approximation.

gauss(x, *p)

Gauss distribution function.

\[f(x)=ae^{-(x-b)^{2}/(2c^{2})}\]
Parameters
  • x (int or float or list or numpy.ndarray) – positions where the gauss function will be calculated

  • p (list) –

    gauss parameters [a, b, c, d]:

    • a – amplitude (\(\int y \,\mathrm{d}x=1 \Leftrightarrow a=1/(c\sqrt{2\pi})\) )

    • b – expected value \(\mu\) (position of maximum, default = 0)

    • c – standard deviation \(\sigma\) (variance \(\sigma^2=c^2\))

    • d – vertical offset (default = 0)

Returns

gauss values at given positions x

Return type

numpy.ndarray

gauss_fit(x, y, e=None, x_fit=None, verbose=False)

Fit Gauss distribution function to data.

Parameters
  • x (int or float or list or numpy.ndarray) – positions

  • y (int or float or list or numpy.ndarray) – values

  • e (int or float or list or numpy.ndarray) – error values (default = None)

  • x_fit (int or float or list or numpy.ndarray) – positions of fitted function (default = None, if None then x is used)

  • verbose (bool) – verbose information (default = False)

Returns

  • numpy.ndarray – fitted values (y_fit)

  • numpy.ndarray – parameters of gauss distribution function (popt: amplitude a, expected value \(\mu\), standard deviation \(\sigma\), vertical offset d)

  • numpy.float64 – full width at half maximum (FWHM)

Return type

tuple

See also

gauss()

main()

test function