Merge module¶
The merge
module offers the following functions to pre-process
and merge scans:
Function |
Description |
---|---|
Calibrates the absorption threshold energy of a scan. |
|
Aligns a scan with respect to a reference. |
|
Merge groups in a collection. |
- araucaria.xas.merge.calibrate(group, e0, update=True)[source]¶
Calibrates the absorption threshold energy of the reference scan.
- Parameters
- Return type
- Returns
Energy difference between
e0
and the initial energy threshold.- 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
.
Notes
Calibration is performed by offsetting the
group.energy
attribute in order to match the absorption threshold energy ofgroup.mu_ref
with the givene0
value.If
update=True
the following attributes ofgroup
will be modified or created:group.energy
: modified by thee_offset
value.group.e_offset
: difference betweene0
and the initial| threshold energy.
If
update=False
thee_offset
value will be returned but not stored ingroup
.Warning
If
e_offset
already exists in the providedgroup
, thegroup.energy
array will be reverted to its original values before performing calibration with the newe0
value.See also
find_e0
Finds the absorption threshold value.
Example
>>> from araucaria.testdata import get_testpath >>> from araucaria.io import read_dnd >>> from araucaria.xas import calibrate >>> fpath = get_testpath('dnd_testfile1.dat') >>> group_mu = read_dnd(fpath, scan='mu') # extracting mu and mu_ref scans >>> e0 = 29200 # threshold energy for calibration >>> e_offset = calibrate(group_mu, e0, update=False) # energy offset >>> print('%1.3f' % e_offset) -3.249
- araucaria.xas.merge.align(group, refgroup, offset=0.0, window=[- 50, 50], use_mu_ref=True, update=True)[source]¶
Aligns the scan of a data group with respect to a reference.
- Parameters
group (
Group
) – Group containing the spectrum to align.refgroup (
Group
) – Reference group for alignment.offset (
float
) – Initial energy offset for alignment. The default is 0.window (
list
) – Energy window with respect to e0 to perform the alignent. The detaulf is [-50, 50].use_mu_ref (
bool
) – Indicates if the reference scan of each group should be used for alignment. The default is True.update (
bool
) – Indicates if the group should be updated following alignment. The default is True.
- Return type
- Returns
Energy offset for the group after alignment.
- Raises
TypeError – If either
group
orrefgroup
is not a valid Group instance.AttributeError – If attribute
energy
does not exist in eithergroup
orrefgroup
.AttributeError – If attribute
mu_ref
does not exist in eithergroup
orrefgroup
whenuse_mu_ref = True
.
Notes
The energy alignment is performed by minimizing the squared residuals between the derivative scans of
group
andrefgroup
, considering an energy window computed with respect to the absorption threshold e0 ofrefgroup
.If
use_mu_ref=True
thegroup.mu_ref
array will be aligned with respect to therefgroup.mu_ref
array. This is the default behavior.If
use_mu_ref=False
the scan attributes ofgroup
andrefgroup
will be used for alignment, as determined by theget_mode()
method.If
update=True
the following attributes ofgroup
will be modified or created:group.energy
: modified by thee_offset
value.group.e_offset
: energy offset following the alignment.
If
update=False
thee_offset
will be returned but not stored ingroup
.Important
The energy alignment performs a local optimization that depends on the initial
offset
parameter. Therefore a judicious selection ofoffset
is required in order to obtain meaningful results.Warning
If
e_offset
already exists in the providedgroup
, thegroup.energy
array will be reverted to its original values before performing alignment.See also
find_e0
Finds the absorption threshold value.
Examples
>>> from numpy import allclose >>> from araucaria import Group >>> from araucaria.testdata import get_testpath >>> from araucaria.io import read_dnd >>> from araucaria.xas import align >>> fpath = get_testpath('dnd_testfile1.dat') >>> # extracting mu and mu_ref scans >>> group_mu = read_dnd(fpath, scan='mu') >>> # creating a reference group with an offset >>> offset = 3.125 >>> ref = Group(**{'energy': group_mu.energy + offset, ... 'mu': group_mu.mu, ... 'mu_ref': group_mu.mu_ref}) >>> # aligning with respect to 'mu_ref' >>> e_offset = align(group_mu, ref, update=False) >>> allclose(offset, e_offset) True
>>> # aligning with respect to 'mu' >>> offset = 4.233 >>> ref = Group(**{'energy': group_mu.energy + offset, ... 'mu': group_mu.mu}) >>> e_offset = align(group_mu, ref, use_mu_ref=False, update=False) >>> allclose(offset, e_offset) True
- araucaria.xas.merge.merge(collection, taglist=['all'], name='merge', only_mu_ref=False)[source]¶
Merge groups in a collection.
- Parameters
collection (
Collection
) – Collection with the groups to be merged.taglist (
List
[str
]) – List with keys to filter groups to be merged based on theirtags
attributes in the Collection. The default is [‘all’].name (
str
) – Name for the merged group. The default is ‘merge’.only_mu_ref (
bool
) – Indicates if only the reference scans should be merged. The default is False.
- Return type
- Returns
report – Report for the merged scan.
group – Group containing the merged scan.
- Raises
TypeError – If
collection
is not a valid Collection instance.AttributeError – If
collection
has notags
attribute.AttributeError – If attribute
mu_ref
does not exist in the selected groups.ValueError – If any item in
taglist
is not a key of thetags
attribute.
Warning
If only one group in
collection
is selected for merge, a None report and the single group will be returned.If different scan types are being merged, the scan attribute of the merge group will be labeled
mu
.Notes
If
only_mu_ref=False
the scan arrays of the selected groups will be merged, as determined by theget_mode()
method. Themu_ref
arrays of the selected groups will also be merged separately. This is the detault behavior.If
only_mu_ref=True
only themu_ref
arrays of the selected groups will be merged.The following attribute will be created for the returned group:
group.merged_scans
: list with the merged scan files.
See also
fig_merge()
Plots merged scans.
Example
>>> from araucaria import Collection >>> from araucaria.testdata import get_testpath >>> from araucaria.io import read_dnd >>> from araucaria.xas import merge >>> collection = Collection() >>> files = ['dnd_testfile1.dat' , 'dnd_testfile2.dat', 'dnd_testfile3.dat'] >>> for file in files: ... fpath = get_testpath(file) ... group_mu = read_dnd(fpath, scan='mu') # extracting mu and mu_ref scans ... collection.add_group(group_mu) # adding group to collection >>> report, mgroup = merge(collection) >>> report.show() =================================================== id filename mode e_offset[eV] e0[eV] =================================================== 1 dnd_testfile1.dat mu 0 29203 2 dnd_testfile2.dat mu 0 29203 3 dnd_testfile3.dat mu 0 29203 --------------------------------------------------- merge mu 0 29203 ===================================================