Normalize module¶
The normalize
module offers the following functions to normalize a scan:
Function |
Description |
---|---|
Calculates the absorption threshold energy of a scan. |
|
Estimates the nearest absorption edge for a scan. |
|
Pre-edge substaction and normalization of a scan. |
- araucaria.xas.normalize.find_e0(group, method='maxder', tol=0.0001, pre_edge_kws=None, use_mu_ref=False, update=False)[source]¶
Calculates the absorption threshold energy of a XAFS scan.
- Parameters
group (
Group
) – Group containing the spectrum to calculate e0.method (
str
) – Name of the method to find e0. Valid names are ‘maxder’ and ‘halfedge’. See Notes for details. The default is ‘maxder’.tol (
float
) – Tolerance value for convergence of e0 calculation. Only used ifmethod='halfedge'
. The defailt is 1e-4.pre_edge_kws (
Optional
[dict
]) – Dictionary with arguments forpre_edge()
. Only used ifmethod='halfedge'
. The defailt is None, which considers default values for normalization.use_mu_ref (
bool
) – Indicates if e0 should be calculated with the reference scan. The default is False.update (
bool
) – Indicates if the group should be updated with the value of e0. The default is False.
- Return type
- Returns
Value of e0.
- Raises
TypeError – If
group
is not a valid Group instance.AttributeError – If attribute
energy
does not exist ingroup
.AttributeError – If attribute
mu_ref
does not exist ingroup
whenuse_mu_ref = True
.ValueError – If
method
is not recocgnized.
Notes
If
method=maxder
the absorption threshold will be calculated as the maximum derivative in absorption.If
method=halfedge
the absorption threshold will be calculated iteratively as half the edge step. This method callspre_edge()
to compute the edge step at each iteration. Parameters for the pre-edge calculation can be passed with thepre_edge_kws
parameter. A tolerance for the error between iterations can be set with thetol
parameter.If
use_mu_ref=False
the absorption threshold will be calculated for the scan attribute ofgroup
, as determined by theget_mode()
method. This is the default behavior.If
use_mu_ref=True
the absorption threshold will be calculated for thegroup.mu_ref
attribute.If
update=True
the following attribute will be created ingroup
:group.e0
: absorption threshold energy \(E_0\).
Important
Computing e0 with
method=halfedge
is sensitive to the parameters used to compute the edge step bypre_edge()
. Therefore, different parameters for calculation of the edge step will yield different values of e0 by this method.Currently
method=halfedge
considers a maximum of 10 iterations to compute e0.Examples
>>> # computing e0 as the maximum derivative >>> from araucaria.testdata import get_testpath >>> from araucaria.io import read_dnd >>> from araucaria.xas import find_e0 >>> fpath = get_testpath('dnd_testfile1.dat') >>> # extracting mu and mu_ref scans >>> group = read_dnd(fpath, scan='mu') >>> # find e0 of reference scan >>> find_e0(group, use_mu_ref=True) 29203.249
>>> # computing e0 as half the edge step >>> find_e0(group, method='halfedge', use_mu_ref=True) 29200.62
- araucaria.xas.normalize.guess_edge(group, e0=None, update=False)[source]¶
Estimates the nearest absorption edge for a XAFS scan.
- Parameters
group (
Group
) – Group containing the spectrum for pre-edge substraction and normalization.e0 (
Optional
[float
]) – Absorption threshold energy. If None it will seach for the value stored ingroup.e0
. Otherwise it will be calculated usingfind_e0()
. with default parameters.update (
bool
) – Indicates if the group should be updated with the normalization attributes. The default is False.
- Return type
- Returns
Dictionary with the following arguments:
atsym
: atomic symbol for the absorption edge.edge
: absorption edge in Siegbanh notation.
- Raises
TypeError – If
group
is not a valid Group instance.AttributeError – If attribute
energy
does not exist ingroup
.IndexError – If
e0
is outside the range ofgroup.energy
.
See also
nearest_edge()
Returns the nearest x-ray edge for a given energy.
Example
>>> from araucaria.testdata import get_testpath >>> from araucaria import Group >>> from araucaria.io import read_dnd >>> from araucaria.xas import find_e0 >>> from araucaria.utils import check_objattrs >>> fpath = get_testpath('dnd_testfile1.dat') >>> group = read_dnd(fpath, scan='mu') # extracting mu and mu_ref scans >>> attrs = ['atsym', 'edge'] >>> e0 = find_e0(group) >>> edge = guess_edge(group, e0, update=True) >>> check_objattrs(group, Group, attrs) [True, True] >>> print(edge) {'atsym': 'Sn', 'edge': 'K'}
- araucaria.xas.normalize.pre_edge(group, e0=None, nvict=0, nnorm=2, pre_range=[- inf, - 50], post_range=[100, inf], update=False)[source]¶
Pre-edge substaction and normalization of a XAFS scan.
- Parameters
group (
Group
) – Group containing the spectrum for pre-edge substraction and normalization.e0 (
Optional
[float
]) – Absorption threshold energy. If None it will seach for the value stored ingroup.e0
. Otherwise it will be calculated usingfind_e0()
. with default parameters.nvict (
int
) – Energy exponent for pre-edge fit with a Victoreen polynomial. The default is 0. See Notes for details.nnorm (
int
) – Degree of polynomial for post-edge fit. The default is 2.pre_range (
list
) – Energy range with respect to e0 for the pre-edge fit. The default is [-inf
, -50].post_range (
list
) – Energy range with respect to e0 for the post-edge fit. The default is [100,inf
].update (
bool
) – Indicates if the group should be updated with the normalization attributes. The default is False.
- Return type
- Returns
Dictionary with the following arguments:
e0
: absorption threshold energy \(E_0\).edge_step
: absorption edge step \(\Delta \mu(E_0)\).norm
: array with normalized \(\mu(E)\).flat
: array with flattened \(\mu(E)\).pre_edge
: fitted pre-edge polynomial.post_edge
: fitted post-edge polynomial.pre_coefs
: coefficients for the pre-edge Victoreen polynomial.post_coefs
: coefficients for the post-edge polynomial.pre_edge_pars
: dictionary with pre-edge parameters.
- Raises
TypeError – If
group
is not a valid Group instance.AttributeError – If attribute
energy
does not exist ingroup
.IndexError – If
e0
is outside the range ofgroup.energy
.ValueError – If
pre_range
contains less than two energy points.ValueError – If
post_range
contains less than two energy points.
Warning
A warning will be raised if the degree of the post-edge polynomial is larger than 3.
See also
fig_pre_edge()
Plot the results of pre-edge substraction and normalization.
Notes
Pre-edge substraction and normalization is performed as follows:
The absorption threshold is determined (if
e0
orgroup.e0
is not supplied).A Victoreen polymonial with energy exponent
nvict
is fitted to the region below the edge, as specified bypre_range
(2 coefficients are fitted):\(\mu(E) \cdot E^{nvict} = m \cdot E + b\)
A polymonial of degree
nnorm
is fitted to the region above the edge, as specified bypost_range
(nnorm
+ 1 coefficients are fitted).The edge step is deterimned by extrapolating both curves to e0.
A flattetned spectrum is calculated by removing the polynomial above the edge from the normalized spectrum, while maintaining the offset of the polynomial at
e0
.
If
update=True
the contents of the returned dictionary will be included as attributes ofgroup
.Example
>>> from araucaria.testdata import get_testpath >>> from araucaria import Group >>> from araucaria.io import read_dnd >>> from araucaria.xas import pre_edge >>> from araucaria.utils import check_objattrs >>> fpath = get_testpath('dnd_testfile1.dat') >>> group = read_dnd(fpath, scan='mu') # extracting mu and mu_ref scans >>> attrs = ['e0', 'edge_step', 'pre_edge', 'post_edge', 'norm', 'flat'] >>> pre = pre_edge(group, update=True) >>> check_objattrs(group, Group, attrs) [True, True, True, True, True, True]