Autobk module¶
- araucaria.xas.autobk.autobk(group, rbkg=1.0, k_range=[0, inf], kweight=2, win='hanning', dk=0.1, nfft=2048, kstep=0.05, k_std=None, chi_std=None, nclamp=2, clamp_lo=1, clamp_hi=1, update=False)[source]¶
Autobk algorithm to remove background of a XAFS scan.
- Parameters
group (
Group
) – Group containing the spectrum for background removal.rbkg (
float
) – Distance (Å) for \(\chi(R)\) above which the signal is ignored. The default is 1.0.k_range (
list
) – Wavenumber range (\(Å^{-1}\)).The default is [0,inf
].kweight (
int
) – Exponent for weighting chi(k) by k**kweight. The default is 2.win (
str
) – Name of the the FT window type. The default is ‘hanning’.dk (
float
) – Tapering parameter for the FT window. The default is 0.1.nfft (
int
) – Array size for the FT. The default is 2048.kstep (
float
) – Wavenumber step size for the FT (\(Å^{-1}\)). The default is 0.05.k_std (
Optional
[ndarray
]) – Optional k array for standard \(\chi(k)\).chi_std (
Optional
[ndarray
]) – Optional array for standard \(\chi(k)\).nclamp (
int
) – Number of energy end-points for clamp. The default is 2.clamp_lo (
int
) – Weight of low-energy clamp. The default is 1.clamp_hi (
int
) – Weight of high-energy clamp. The default is 1.update (
bool
) – Indicates if the group should be updated with the autobk attributes. The default is False.
- Return type
- Returns
Dictionary with the following arguments:
bkg
: array with background signal \(\mu_0(E)\).chie
: array with \(\chi(E)\).chi
: array with \(\chi(k)\).k
: array with wavenumbers.autobk_pars
: dictionary with autobk parameters.
- Raises
TypeError – If
group
is not a valid Group instance.AttributeError – If attribute
e0
oredge_step
does not exist ingroup
.
Warning
rbkg
cannot be lower than 2 x \(\pi\)/(kstep x nfft), which corresponds to the grid resolution of \(\chi(R)\).See also
fig_autobk()
Plot the results of background removal.
Notes
The Autobk algorithm 1 approximates an EXAFS bakground signal by fitting a cubic B-spline to the \(\chi(R)\) signal below a
rbkg
value.The background removal is performed as follows:
The B-spline is constructed considering approximately equally distant knots in
krange
. The number of knots is calculated as the integer value of 2 *rbkg
*krange
/\(\pi\) + 2, with a minimum value of 5 and a maximum value of 64.The initial coefficients (\(c_i\)) for the B-spline at each knot are calculated with a weighted average window:
\[c_i = \frac{\mu_{i-5} + 2 \cdot \mu_i + \mu_{i+5}}{4}\]The coefficients of the B-spline are then optimized in order to fit \(\chi(R)\) below the
rbkg
value.If
nclamp
is provided, the given number of points at the extremes of the weighted \(\chi(k)\) signal are also included in the minimize function, in order to fit such points considering theclamp_lo
andclamp_hi
weights.The fitted B-spline is removed from \(\mu(E)\) in order to compute \(\chi(k)\).
If
update=True
the contents of the returned dictionary will be included as attributes ofgroup
.References
- 1
Newville, M., Livins, P., Yacoby, Y., Rehr, J. J., & Stern, E. A. (1993) “Near-edge x-ray-absorption fine structure of Pb: A comparison of theory and experiment”. Physical Review B, 47(21), pp. 14126–14131.
Example
>>> from araucaria.testdata import get_testpath >>> from araucaria import Group >>> from araucaria.io import read_dnd >>> from araucaria.xas import pre_edge, autobk >>> from araucaria.utils import check_objattrs >>> fpath = get_testpath('dnd_testfile1.dat') >>> group = read_dnd(fpath, scan='mu') # extracting mu and mu_ref scans >>> pre = pre_edge(group, update=True) >>> attrs = ['bkg', 'chie', 'chi', 'k', 'autobk_pars'] >>> autbk = autobk(group, update=True) >>> check_objattrs(group, Group, attrs) [True, True, True, True, True]