Table of Contents
ProcessBackground provides some tools to process powder diffraction pattern’s background in order to help Le Bail Fit.
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | Workspace2D | Mandatory | Name of the output workspace containing the processed background. |
WorkspaceIndex | Input | number | 0 | Workspace index for the input workspaces. |
OutputWorkspace | Output | Workspace2D | Output workspace containing processed background | |
Options | Input | string | RemovePeaks | Name of the functionality realized by this algorithm. Allowed values: [‘SelectBackgroundPoints’, ‘RemovePeaks’, ‘DeleteRegion’, ‘AddRegion’] |
LowerBound | Input | number | Optional | Lower boundary of the data to have background processed. |
UpperBound | Input | number | Optional | Upper boundary of the data to have background processed. |
ReferenceWorkspace | Input | Workspace2D | Name of the workspace containing the data required by function AddRegion. | |
BackgroundType | Input | string | Polynomial | Type of the background. Options include Polynomial and Chebyshev. Allowed values: [‘Polynomial’, ‘Chebyshev’] |
SelectionMode | Input | string | N/A | If choise is UserFunction, background will be selected by an input background function. Otherwise, background function will be fitted from user’s input data points. Allowed values: [‘N/A’, ‘FitGivenDataPoints’, ‘UserFunction’] |
BackgroundOrder | Input | number | 0 | Order of polynomial or chebyshev background. |
BackgroundPoints | Input | dbl list | Vector of doubles, each of which is the X-axis value of the background point selected by user. | |
BackgroundTableWorkspace | Input | TableWorkspace | Name of the table workspace containing background parameters for mode SelectBackgroundPoints. | |
BackgroundPointSelectMode | Input | string | All Background Points | Mode to select background points. Allowed values: [‘All Background Points’, ‘Input Background Points Only’] |
NoiseTolerance | Input | number | 1 | Tolerance of noise range. |
NegativeNoiseTolerance | Input | number | Optional | Tolerance of noise range for negative number. |
UserBackgroundWorkspace | Output | Workspace2D | Output workspace containing fitted background from points specified by users. | |
OutputBackgroundParameterWorkspace | Output | TableWorkspace | Output parameter table workspace containing the background fitting result. | |
OutputBackgroundType | Input | string | Polynomial | Type of background to fit with selected background points. Allowed values: [‘Polynomial’, ‘Chebyshev’] |
OutputBackgroundOrder | Input | number | 6 | Order of background to fit with selected background points. |
BraggPeakTableWorkspace | Input | TableWorkspace | Name of table workspace containing peaks’ parameters. | |
NumberOfFWHM | Input | number | 1 | Number of FWHM to as the peak region to have peak removed. |
The algorithm ProcessBackground() provides several functions for user to process background to prepare Le Bail Fit.
There are a few functional options for user to choose.
This feature is designed to select many background points with user’s simple input. User is required to select only a few background points in the middle of two adjacent peaks. Algorithm will fit these few points (BackgroundPoints) to a background function of specified type.
The purpose of this option is to select as many background data points as possible for future background function fitting.
Prior information can be given by two modes. Property ‘SelectionMode’ determines which modes to use. One (1)is from a list of X-values specified by users via property “BackgroundPoints”. The other (2) is through a (background) function, whose type is specified by property “BackgroundType” and values are given via input table workspace “BackgroundTableWorkspace”.
Here is how it works. Assume that the is the list of x values specified by users.
In this approach, the difference from the other apporach is to use the user given background function to select data points within a range other than fitting the background function from given data points in the other approach. Thus, it is just the last step of previous approach.
Besides the common algorithm properties, below is the list of properties specific to this function option.
Here is a good example to select background points from a powder diffraction pattern by calling ProcessBackground() in a self-consistent manner.
This algorithm is to remove peaks and output the backgrounds, which can be used to fit an artibrary background function after calling this algorithm.
It is assumed that the all peaks have been fitted reasonably well.
Then by removing the peaks within range ,
and save the rest data points, which are very likely backgrounds, to an output workspace.
Besides the common algorithm properties, below is the list of properties specific to this function option.
Replace a region, which is defined by ‘LowerBoundary’ and ‘UpperBoundary’, in a workspace from another reference workspace.
Removed a specified region, which is defined by ‘LowerBoundary’ and ‘UpperBoundary’, from the input workspace.
Example - Select background from a powgen data:
LoadAscii(Filename=r'PG3_15035-3.dat', OutputWorkspace='PG3_15035-3',Unit='TOF')
outputs = ProcessBackground(InputWorkspace='PG3_15035-3', WorkspaceIndex = 0, Options='SelectBackgroundPoints',
LowerBound='9726',UpperBound='119000', BackgroundType = 'Polynomial', BackgroundOrder = 6,
SelectionMode='FitGivenDataPoints', BackgroundPointSelectMode = "All Background Points",
BackgroundPoints='10082,10591,11154,12615,13690,13715,15073,16893,17764,19628,21318,24192,35350,44212,50900,60000,69900,79000',
NoiseTolerance = 0.10,
OutputWorkspace='PG3_15035-3_BkgdPts', OutputBackgroundType = "Polynomial", OutputBackgroundOrder = 6,
OutputBackgroundParameterWorkspace = "OutBackgroundParameters", UserBackgroundWorkspace="UserTheory")
tbws = outputs[2]
print("Number of output workspace = {}, Number of selected background points = {}".format(len(outputs), len(outputs[0].readX(0))))
print("Fitted background function: A0 = {:.5e}, A1 = {:.5e}, A2 = {:.5e} ...".format(tbws.cell(1, 1), tbws.cell(2, 1), tbws.cell(3,1)))
Output:
Number of output workspace = 3, Number of selected background points = 4944
Fitted background function: A0 = 5.43859e-01, A1 = -5.20674e-05, A2 = 2.84119e-09 ...
Example - Add Region:
import math
import random
vecx = []
vecy1 = []
vecy2 = []
vece = []
x0 = 0.0
dx = 0.01
random.seed(1)
for i in range(1000):
x = x0 + float(i) * dx
vecx.append(x)
y = (random.random() - 0.5) * 2.0 + 2.0 + math.exp(-(x-4.0)**2/0.1)
e = math.sqrt(y)
vecy1.append(y)
vecy2.append(-y)
vece.append(e)
ws1 = CreateWorkspace(DataX = vecx, DataY = vecy1, DataE = vece, NSpec = 1)
ws2 = CreateWorkspace(DataX = vecx, DataY = vecy2, DataE = vece, NSpec = 1)
outputs = ProcessBackground(InputWorkspace=ws1, WorkspaceIndex=0, OutputWorkspace="ws12", Options="AddRegion",
LowerBound = 3.0, UpperBound = 5.0, ReferenceWorkspace = ws2)
for i in [200, 400, 450, 500, 700]:
print("X = {0:.5f}, Input Y[{1}] = {2:.5f}, Reference Y[{1}] = {3:.5f}, Output Y[{1}] = {4:.5f}".format(
vecx[i], i, ws1.readY(0)[i], ws2.readY(0)[i], outputs[0].readY(0)[i]))
Output:
X = 2.00000, Input Y[200] = 1.65069, Reference Y[200] = -1.65069, Output Y[200] = 1.65069
X = 4.00000, Input Y[400] = 3.81388, Reference Y[400] = -3.81388, Output Y[400] = -3.81388
X = 4.50000, Input Y[450] = 2.68751, Reference Y[450] = -2.68751, Output Y[450] = -2.68751
X = 5.00000, Input Y[500] = 2.00611, Reference Y[500] = -2.00611, Output Y[500] = 1.71367
X = 7.00000, Input Y[700] = 1.12037, Reference Y[700] = -1.12037, Output Y[700] = 2.87033
Example - Delete Region:
import math
import random
vecx = []
vecy = []
vece = []
x0 = 0.0
dx = 0.01
random.seed(1)
for i in range(1000):
x = x0 + float(i) * dx
vecx.append(x)
y = (random.random() - 0.5) * 2.0 + 2.0 + math.exp(-(x-4.0)**2/0.1)
e = math.sqrt(y)
vecy.append(y)
vece.append(e)
ws1 = CreateWorkspace(DataX = vecx, DataY = vecy, DataE = vece, NSpec = 1)
outputs = ProcessBackground(InputWorkspace=ws1, WorkspaceIndex=0, OutputWorkspace="ws2", Options="DeleteRegion",
LowerBound = 3.0, UpperBound = 5.0)
print("Input has {} data points; Output has {} data points.".format(len(ws1.readX(0)), len(outputs[0].readX(0))))
Output:
Input has 1000 data points; Output has 799 data points.
Example - Remove peaks:
import math
import random
vecx = []
vecy = []
vece = []
numpts = 1000
x0 = 0
dx = 0.01
random.seed(1)
for i in range(1000):
x = float(i)*dx
y = 5 + (random.random() - 1)*2. + 10*math.exp( -(x-2.0)**2/0.1**2 ) + 20*math.exp( -(x-7.5)**2/0.05**2 )
e = math.sqrt(y)
vecx.append(x)
vecy.append(y)
vece.append(e)
ws = CreateWorkspace(DataX = vecx, DataY = vecy, DataE = vece, NSpec = 1)
peaktb = CreateEmptyTableWorkspace()
peaktb.addColumn("double", "TOF_h")
peaktb.addColumn("double", "FWHM")
peaktb.addRow([2.0, 0.3])
peaktb.addRow([7.40, 0.13])
outputs = ProcessBackground(InputWorkspace=ws, WorkspaceIndex=0, OutputWorkspace="background",
Options="RemovePeaks", BraggPeakTableWorkspace=peaktb, NumberOfFWHM=3)
Fit(Function='name=Polynomial,n=1,A0=0.0,A1=0.0', InputWorkspace='background', CreateOutput=True, StartX=0, EndX=9.9900000000000002,
OutputNormalisedCovarianceMatrix='background_NormalisedCovarianceMatrix', OutputParameters='background_Parameters', OutputWorkspace='background_Workspace')
outparws = mtd["background_Parameters"]
print("Input workspace has {} data points; Output workspace has {} data points.".format(len(ws.readX(0)), len(outputs[0].readX(0))))
print("Fitted background parameters: A0 = {:.5e}, A1 = {:.5e}, Chi-square = {:.5f}".format(outparws.cell(0, 1), outparws.cell(1,1), outparws.cell(2,1)))
Output:
Input workspace has 1000 data points; Output workspace has 741 data points.
Fitted background parameters: A0 = 3.90254e+00, A1 = 1.09284e-02, Chi-square = 0.08237
Categories: Algorithm Index | Diffraction\Utility
C++ source: ProcessBackground.cpp (last modified: 2018-10-05)
C++ header: ProcessBackground.h (last modified: 2018-10-05)