Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
Input | Input | string | Mandatory | A list of sources of data to fit. Sources can be either workspace names or file names followed optionally by a list of spectra/workspace-indices or values using the notation described in the description section of the help page. |
Spectrum | Input | number | 1 | Set a spectrum to fit. However, if spectra lists (or workspace-indices/values lists) are specified in the Input parameter string these take precedence. |
WorkspaceIndex | Input | number | 0 | Set a workspace-index to fit (alternative option to Spectrum). However, if spectra lists (or workspace-indices/values lists) are specified in the Input parameter string, or the Spectrum parameter integer, these take precedence. |
OutputWorkspace | Output | TableWorkspace | Mandatory | The output TableWorkspace |
Function | Input | string | Mandatory | The fitting function, common for all workspaces in the input WorkspaceGroup |
LogValue | Input | string | Name of the log value to plot the parameters against. Default: use spectra numbers. | |
StartX | Input | number | Optional | A value of x in, or on the low x boundary of, the first bin to include in the fit (default lowest value of x) |
EndX | Input | number | Optional | A value in, or on the high x boundary of, the last bin the fitting range (default the highest value of x) |
FitType | Input | string | Sequential | Defines the way of setting initial values. If set to ‘Sequential’ every next fit starts with parameters returned by the previous fit. If set to ‘Individual’ each fit starts with the same initial values defined in the Function property. Allowed values: [‘Sequential’, ‘Individual’] |
PassWSIndexToFunction | Input | boolean | False | For each spectrum in Input pass its workspace index to all functions thathave attribute WorkspaceIndex. |
Minimizer | Input | string | Levenberg-Marquardt | Minimizer to use for fitting. Minimizers available are ‘Levenberg-Marquardt’, ‘Simplex’, ‘FABADA’, ‘Conjugate gradient (Fletcher-Reeves imp.)’, ‘Conjugate gradient (Polak-Ribiere imp.)’ and ‘BFGS’ |
CostFunction | InOut | string | Least squares | Cost functions to use for fitting. Cost functions available are ‘Least squares’ and ‘Ignore positive peaks’. Allowed values: [‘Least squares’, ‘Rwp’, ‘Unweighted least squares’] |
MaxIterations | Input | number | 500 | Stop after this number of iterations if a good fit is not found |
CreateOutput | Input | boolean | False | Set to true to create output workspaces with the results of the fit(default is false). |
OutputCompositeMembers | Input | boolean | False | If true and CreateOutput is true then the value of each member of a Composite Function is also output. |
ConvolveMembers | Input | boolean | False | If true and OutputCompositeMembers is true members of any Convolution are output convolved with corresponding resolution |
EvaluationType | Input | string | CentrePoint | The way the function is evaluated: CentrePoint or Histogram. Allowed values: [‘CentrePoint’, ‘Histogram’] |
This algorithm fits a series of spectra with the same function. Each spectrum is fit independently and the result is a table of fitting parameters unique for each spectrum. The sources for the spectra are defined in the Input property. The Input property expects a list of spectra identifiers separated by semicolons (;). An identifier is itself a comma-separated list of values. The first value is the name of the source. It can be either a workspace name or a name of a file (RAW or Nexus). If it is a name of a WorkspaceGroup all its members will be included in the fit. The second value selects a spectrum within the workspace or file. It is an integer number with a prefix defining the meaning of the number: “sp” for a spectrum number, “i” for a workspace index, or “v” for a range of values on the numeric axis associated with the workspace index. For example, sp12, i125, v0.5:2.3. If the data source is a file only the spectrum number option is accepted. The third value of the spectrum identifier is optional period number. It is used if the input file contains multiperiod data. In case of workspaces this third parameter is ignored. This are examples of Input property
Internally PlotPeakByLogValue uses Fit v1 algorithm to perform fitting and the following properties have the same meaning as in Fit v1: Function, StartX, EndX, Minimizer, CostFunction. Property FitType defines the way of setting initial values. If it is set to “Sequential” every next fit starts with parameters returned by the previous fit. If set to “Individual” each fit starts with the same initial values defined in the Function property.
LogValue property specifies a log value to be included into the output. If this property is empty the values of axis 1 will be used instead. Setting this property to “SourceName” makes the first column of the output table contain the names of the data sources (files or workspaces).
In this example a group of three Matrix workspaces were fitted with a Gaussian on a linear background.
The output workspace is a table in which rows correspond to the spectra in the order they (spectra) appear in the Input property. The first column of the table has the log values. It is followed by pairs of columns with parameter values and fitting errors. If a parameter was fixed or tied the error will be zero. Here is an example of the output workspace:
It is possible to supply a fully configured minimizer via the Minimizer property, this can also include several flags that are used to indicate the workspace name and workspace index that has been fitted (useful for fitting using a minimizer that output workspaces (i.e. FABADA)).
The possible flags are:
Example - fitting a single spectrum of in a workspace:
ws = CreateSampleWorkspace()
function = "name=Gaussian,Height=10.0041,PeakCentre=10098.6,Sigma=48.8581;name=FlatBackground,A0=0.3"
peaks = PlotPeakByLogValue(ws, function, Spectrum=1)
Example - sequentially fitting a workspace:
import numpy as np
ws = CreateSampleWorkspace()
function = "name=Gaussian,Height=10.0041,PeakCentre=10098.6,Sigma=48.8581;name=FlatBackground,A0=0.3"
#create string of workspaces to fit (ws,i0; ws,i1, ws,i2 ...)
workspaces = [ws.name() + ',i%d' % i for i in range(ws.getNumberHistograms())]
workspaces = ';'.join(workspaces)
peaks = PlotPeakByLogValue(workspaces, function, Spectrum=1)
#get peak centres for comparison
peak_centres = peaks.column('f0.PeakCentre')
ref = np.empty(len(peak_centres))
ref.fill(10098.6)
print np.allclose(ref, peak_centres, 1e-3)
Output:
True
Categories: Algorithms | Optimization