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

EnggFitPeaks v1

../_images/ImageNotFound.png

Enable screenshots using DOCS_SCREENSHOTS in CMake

Summary

The algorithm fits an expected diffraction pattern to a spectrum from a workspace by fitting one peak at a time (single peak fits).

See Also

EnggFitTOFFromPeaks, GSASIIRefineFitPeaks, Fit

Properties

Name

Direction

Type

Default

Description

InputWorkspace

Input

MatrixWorkspace

Mandatory

Workspace to fit peaks in. The X units must be time of flight (TOF).

WorkspaceIndex

Input

long

0

Index of the spectra to fit peaks in

ExpectedPeaks

Input

dbl list

1.1046,1.35285,1.6316,1.91322,2.7057

A list of peak centre values to be translated into TOF (if required) to find expected peaks.

ExpectedPeaksFromFile

Input

string

Load from file a list of peak centre values to be translated into TOF (if required) to find expected peaks. This takes precedence over ‘ExpectedPeaks’ if both options are given. Allowed extensions: [‘.csv’]

OutFittedPeaksTable

Input

string

Name for a table workspace with the parameters of the peaks found and fitted. If not given, the table workspace is not created.

FittedPeaks

Output

TableWorkspace

Mandatory

Information on fitted peaks. The table contains, for every peak fitted the expected peak value (in d-spacing), and the parameters fitted. The expected values are given in the column labelled ‘dSpacing’. When fitting back-to-back exponential functions, the ‘X0’ column has the fitted peak center.

Description

Warning

This algorithm is being developed for a specific instrument. It might get changed or even removed without a notification, should instrument scientists decide to do so.

Fits a series of single peaks to a spectrum with an expected diffraction pattern. The pattern is specified by providing a list of peak centres where Bragg peaks are expected. These expected values are used as initial peak positions when fitting the peaks. The expected dSpacing values can be given as an input string or in a file with values separated by commas. These values can be in units of either TOF or dSpacing, but not a mixture of the two. At least one of the peaks in the list must lie inside the x limits of the input workspace.

The peaks are fitted one at a time. The peak centres given in the property ExpectedPeaks are initially assumed to be in units of TOF. If none lie inside the x limits of the input workspace, EnggFitPeaks tries converting them to dSpacing, and if they still don’t fit the data then the algorithm fails.

After the conversion of units, the algorithm tries to fit (in time-of-flight) a peak in the neighborhood of every expected peak using a peak shape or function. The conversion is done as in the Mantid algorithm AlignDetectors (following GSAS equations) if the workspace is focused (single spectrum) and has a log entry named “difc”, where the GSAS DIFC parameter is expected. Otherwise the conversion of units is done as in the Mantid ConvertUnits.

This algorithm currently fits (single) peaks of type Back2BackExponential. Other alternatives might be added as optional in the future (for example the simpler Gaussian or the more complex Bk2BkExpConvPV or IkedaCarpenterPV). To produce an initial guess for the peak function parameters this algorithm uses the FindPeaks algorithm starting from the expected peaks list given in the inputs.

The algorithm produces an output table workspace with information about the peaks fitted. The table has one row per peak and several columns for the different fitted parameters (and the errors of these parameters). If a name is given in the input OutFittedPeaksTable, the table will be available in the “analysis data service” (workspaces window) with that name.

Usage

Example - Fitting two peaks:

# Two BackB2Back exponential peaks
peak1 = "name=BackToBackExponential,I=6000,A=0.05,B=0.025,X0=15000,S=100"
peak2 = "name=BackToBackExponential,I=5000,A=0.05,B=0.025,X0=35000,S=100"
bg = "name=FlatBackground,A0=20"

# Create workpsace with the above peaks and a single detector pixel
ws = CreateSampleWorkspace(Function="User Defined",
                           UserDefinedFunction=";".join([peak1, peak2, bg]),
                           NumBanks=1,
                           BankPixelWidth=1,
                           XMin=6000,
                           XMax=45000,
                           BinWidth=10)

# Update instrument geometry to something that would allow converting to some sane dSpacing values
EditInstrumentGeometry(Workspace = ws, L2 = [1.5], Polar = [90], PrimaryFlightPath = 50)

# Run the algorithm. Defaults are shown below. Files entered must be in .csv format and if both ExpectedPeaks and ExpectedPeaksFromFile are entered, the latter will be used.

peaks_tbl = EnggFitPeaks(ws, 0, [0.8, 1.9])


# Print the results
print("Number of peaks fitted: {0}".format(peaks_tbl.rowCount()))

Output:

Number of peaks fitted: 2

Categories: AlgorithmIndex | Diffraction\Engineering | Diffraction\Fitting

Source

Python: EnggFitPeaks.py