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

MatchSpectra v1

../_images/MatchSpectra-v1_dlg.png

MatchSpectra dialog.

Summary

Calculate factors to most closely match all spectra to reference spectrum

Properties

Name Direction Type Default Description
InputWorkspace Input MatrixWorkspace Mandatory Workspace to match the spectra between
OutputWorkspace Output MatrixWorkspace Mandatory Workspace with the spectra matched
ReferenceSpectrum Input number 1 Spectrum to match other spectra to
CalculateOffset Input boolean True Calculate vertical shift
CalculateScale Input boolean True Calculate scale factor
Offset Output dbl list   Additive factor from matching
Scale Output dbl list   Multiplicitive factor from matching
ChiSq Output dbl list   Unweighted ChiSq between the spectrum and the reference. NaN means that the spectrum was not matched

Description

Calculate the factor(s) that best match the individual spectra to a reference spectrum using Gauss-Markov process. This is the same algorithm used by the “blend” step of PDFgetN. The data undergoes the linear transformation

\[scale * y_{spectrum} + offset\]

such that the distance between \(y_{reference}\) and the transformed spectrum is minimized. Only the portions of the spectra where the spectra overlap with the same x-values and the uncertainties are greater than zero are considered.

Note

Gauss-Markov does not take into account varying uncertainties when calculating the scale and offset.

Usage

import numpy as np
x = np.arange(100, dtype=np.float)
x = np.tile(x, 2)
y = np.arange(100, dtype=np.float)
y = np.tile(y, 2)
y[100:200] += 10
dy = np.zeros(y.size, dtype=np.float) + 1.
CreateWorkspace(OutputWorkspace='MatchSpectra_input',
                DataX=x,
                DataY=y,
                DataE=dy,
                NSpec=2)
_, offset, scale, chisq = MatchSpectra(InputWorkspace='MatchSpectra_input',
                                       OutputWorkspace='MatchSpectra_output',
                                       ReferenceSpectrum=2,
                                       CalculateOffset=True,
                                       CalculateScale=False)
for i in range(2):
    print('spectra {}: {:.1f} * y + {:.1f}, chisq={:.1f}'.format(i+1, scale[i], offset[i], chisq[i]))

Output:

spectra 1: 1.0 * y + 10.0, chisq=0.0
spectra 2: 1.0 * y + 0.0, chisq=0.0

Categories: AlgorithmIndex | Diffraction\Reduction

Source

Python: MatchSpectra.py (last modified: 2020-03-27)