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
e0and the initial energy threshold.- Raises
TypeError – If
groupis not a valid Group instance.AttributeError – If attribute
energydoes not exist ingroup.AttributeError – If attribute
mu_refdoes not exist ingroup.
Notes
Calibration is performed by offsetting the
group.energyattribute in order to match the absorption threshold energy ofgroup.mu_refwith the givene0value.If
update=Truethe following attributes ofgroupwill be modified or created:group.energy: modified by thee_offsetvalue.group.e_offset: difference betweene0and the initial| threshold energy.
If
update=Falsethee_offsetvalue will be returned but not stored ingroup.Warning
If
e_offsetalready exists in the providedgroup, thegroup.energyarray will be reverted to its original values before performing calibration with the newe0value.See also
find_e0Finds 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
grouporrefgroupis not a valid Group instance.AttributeError – If attribute
energydoes not exist in eithergrouporrefgroup.AttributeError – If attribute
mu_refdoes not exist in eithergrouporrefgroupwhenuse_mu_ref = True.
Notes
The energy alignment is performed by minimizing the squared residuals between the derivative scans of
groupandrefgroup, considering an energy window computed with respect to the absorption threshold e0 ofrefgroup.If
use_mu_ref=Truethegroup.mu_refarray will be aligned with respect to therefgroup.mu_refarray. This is the default behavior.If
use_mu_ref=Falsethe scan attributes ofgroupandrefgroupwill be used for alignment, as determined by theget_mode()method.If
update=Truethe following attributes ofgroupwill be modified or created:group.energy: modified by thee_offsetvalue.group.e_offset: energy offset following the alignment.
If
update=Falsethee_offsetwill be returned but not stored ingroup.Important
The energy alignment performs a local optimization that depends on the initial
offsetparameter. Therefore a judicious selection ofoffsetis required in order to obtain meaningful results.Warning
If
e_offsetalready exists in the providedgroup, thegroup.energyarray will be reverted to its original values before performing alignment.See also
find_e0Finds 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 theirtagsattributes 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
collectionis not a valid Collection instance.AttributeError – If
collectionhas notagsattribute.AttributeError – If attribute
mu_refdoes not exist in the selected groups.ValueError – If any item in
taglistis not a key of thetagsattribute.
Warning
If only one group in
collectionis 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=Falsethe scan arrays of the selected groups will be merged, as determined by theget_mode()method. Themu_refarrays of the selected groups will also be merged separately. This is the detault behavior.If
only_mu_ref=Trueonly themu_refarrays 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 ===================================================