\(\renewcommand\AA{\unicode{x212B}}\)

FitGaussian v1

Summary

See Also

Fit

Properties

Name

Direction

Type

Default

Description

Workspace

Input

MatrixWorkspace

Mandatory

input workspace

Index

Input

number

0

workspace index - which spectrum to fit

PeakCentre

Output

number

the centre of the fitted peak

Sigma

Output

number

the sigma of the fitted peak; 0. if fitting was not successful

Description

This algorithm fits a single peak with a Gaussian function.

It assumes that the peak centre is at or near the point with the highest value and the peak is at least three samples wide above the half maximum. It estimates the peak height, sigma, and range; then calls the Fit v1 algorithm to fit the peak curve.

Input and Output

The input parameters are a histogram workspace and the index of the histogram. The output parameters are the fitted peak centre and sigma. If the data could not be fitted, 0.0 is returned as both the peak centre and sigma values and a warning message is logged. Errors in parameters raise RuntimeError.

ChildAlgorithms used

Uses the Fit v1 algorithm to fit the peak curve with a Gaussian function.

Usage

Example: fit a peak

# create a workspace with a single peak
wspace = CreateSampleWorkspace(
   Function="User Defined",
   UserDefinedFunction="name=Gaussian,PeakCentre=2,Height=10,Sigma=.7",
   NumBanks=1, BankPixelWidth=1, XMin=0, XMax=10, BinWidth=0.1)

# attempt the fit
fitResult = FitGaussian(wspace,0)
if (0.0,0.0) == fitResult:
   print("the fit was not successful")
else:
   print("the fitted peak: centre={:.2f}, sigma={:.2f}".format(fitResult[0], fitResult[1]))

Output:

the fitted peak: centre=..., sigma=...

Categories: AlgorithmIndex | Optimization

Source

Python: FitGaussian.py