Absorption¶
Functions to load and process x-ray absorption data.
|
Load the x-ray absorption from one scan. |
|
Load the x-ray magnetic dichroism from one scan taken in non-lock-in mode ('dichro'). |
|
Load the x-ray magnetic dichroism from one scan taken in lock-in mode. |
|
Load multiple x-ray absorption energy scans. |
|
Load multiple x-ray magnetic dichroism energy "dichro" scans. |
|
Load multiple x-ray magnetic dichroism energy "lockin" scans. |
|
Extract pre- and post-edge normalization curves by fitting polynomials. |
|
Extracts the pre-edge background by fitting a polynomial. |
|
Extracts the post-edge background by fitting a polynomial. |
|
Flattens the normalized absorption. |
|
Correct over-absorption (self-absorption) for fluorescene XAFS using the based on the larch implementation of the FLUO alogrithm of D. |
|
Process the XMCD scans of +/- magnetic fields. |
|
Plots a new figure with the combined XMCD of plus and minus fields. |
|
Saves processed XANES/XMCD data into a file. |
- polartools.absorption.fluo_corr(norm, formula, elem, edge, line, anginp, angout)[source]¶
Correct over-absorption (self-absorption) for fluorescene XAFS using the based on the larch implementation of the FLUO alogrithm of D. Haskel. See FLUO manual for details.
- Parameters:
- normiter
Normalized fluorescence
- formulastr
Chemical formula of the compound. For example: ‘EuO’.
- elemstr
Element of interest. For example: ‘Eu’.
- edgestr
Absorption edge of interest. For example: ‘L3’.
- linestr
Fluorescence line measured. For example: ‘La’.
- anginpfloat
Input angle with respect to the sample surface. See FLUO manual.
- anginpfloat
Output angle with respect to the sample surface. See FLUO manual.
- Returns:
- norm_corrnumpy.array
Corrected normalized fluorescence.
- polartools.absorption.load_absorption(scan, source, positioner=None, detector=None, monitor=None, transmission=True, **kwargs)[source]¶
Load the x-ray absorption from one scan.
- Parameters:
- scanint
Scan_id our uid. If scan_id is passed, it will load the last scan with that scan_id. See kwargs for search options.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable kwargs depend on this selection.
- positionerstring, optional
Name of the positioner, this needs to be the same as defined in Bluesky or SPEC. If None is passed, it defauts to the x-ray energy.
- detectorstring, optional
Detector to be read from this scan, again it needs to be the same name as in Bluesky. If None is passed, it defaults to the ion chamber 5.
- monitorstring, optional
Name of the monitor detector. If None is passed, it defaults to the ion chamber 4.
- transmissionbool, optional
Flag to select between transmission mode -> ln(monitor/detector) or fluorescence mode -> detector/monitor
- kwargs
The necessary kwargs are passed to the loading functions defined by the source argument:
csv -> possible kwargs: folder, name_format.
spec -> possible kwargs: folder.
databroker -> possible kwargs: stream, query, use_db_v1.
Note that a warning will be printed if the an unnecessary kwarg is passed.
- Returns:
- xnumpy.array
Positioner data.
- ynumpy.array
X-ray absorption.
See also
- polartools.absorption.load_dichro(scan, source, positioner=None, detector=None, monitor=None, transmission=True, **kwargs)[source]¶
Load the x-ray magnetic dichroism from one scan taken in non-lock-in mode (‘dichro’).
- Parameters:
- scanint
Scan_id our uid. If scan_id is passed, it will load the last scan with that scan_id. See kwargs for search options.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable kwargs depend on this selection.
- positionerstring, optional
Name of the positioner, this needs to be the same as defined in Bluesky. Defauts to the x-ray energy.
- detectorstring, optional
Detector to be read from this scan, again it needs to be the same name as in Bluesky. Defaults to the ion chamber 5.
- monitorstring, optional
Name of the monitor detector. Defaults to the ion chamber 4.
- transmission: bool, optional
Flag to select between transmission mode -> ln(monitor/detector) or fluorescence mode -> detector/monitor.
- kwargs
The necessary kwargs are passed to the loading functions defined by the source argument:
csv -> possible kwargs: folder, name_format.
spec -> possible kwargs: folder.
databroker -> possible kwargs: stream, query, use_db_v1.
Note that a warning will be printed if the an unnecessary kwarg is passed.
- Returns:
- xnumpy.array
Positioner data.
- xanesnumpy.array
X-ray absorption.
- xmcdnumpy.array
X-ray magnetic dichroism.
See also
polartools.load_data.load_absorption()polartools.load_data.load_table()
- polartools.absorption.load_lockin(scan, source, positioner=None, dc_col=None, ac_col=None, acoff_col=None, **kwargs)[source]¶
Load the x-ray magnetic dichroism from one scan taken in lock-in mode.
- Parameters:
- scanint
Scan_id our uid. If scan_id is passed, it will load the last scan with that scan_id. See kwargs for search options.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable kwargs depend on this selection.
- positionerstring, optional
Name of the positioner, this needs to be the same as defined in Bluesky or SPEC. If None is passed, it defaults to the x-ray energy.
- dc_colstring, optional
Name of the DC scaler, again it needs to be the same name as in Bluesky or SPEC. If None is passed, it defaults to ‘Lock DC’.
- ac_colstring, optional
Name of the AC scaler. If None is passed, it defaults to ‘Lock AC’.
- acoff_colstring, optional
Name of the AC offset scaler. If None is passed, it defaults to ‘Lock AC off’.
- kwargs
The necessary kwargs are passed to the loading functions defined by the source argument:
csv -> possible kwargs: folder, name_format.
spec -> possible kwargs: folder.
databroker -> possible kwargs: stream, query, use_db_v1.
Note that a warning will be printed if the an unnecessary kwarg is passed.
- Returns:
- xnumpy.array
Positioner data.
- dcnumpy.array
DC response, normally corresponds to the x-ray absorption.
- ac-ac_offnumpy.array
AC response minus the offset, normally corresponds to the x-ray magnetic dichroism.
See also
- polartools.absorption.load_multi_dichro(scans, source, return_mean=True, positioner=None, detector=None, monitor=None, transmission=True, **kwargs)[source]¶
Load multiple x-ray magnetic dichroism energy “dichro” scans.
- Parameters:
- scansiterable
Sequence of scan_ids our uids. If scan_id is passed, it will load the last scan with that scan_id. Use kwargs for search options.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable kwargs depend on this selection.
- return_meanboolean, optional
Flag to indicate if the averaging of multiple scans will be performed. Note that if True three outputs are generated, otherwise two.
- positionerstring, optional
Name of the positioner, this needs to be the same as defined in Bluesky or SPEC. If None is passed, it defauts to the x-ray energy.
- detectorstring, optional
Detector to be read from this scan, again it needs to be the same name as in Bluesky. If None is passed, it defaults to the ion chamber 5.
- monitorstring, optional
Name of the monitor detector. If None is passed, it defaults to the ion chamber 4.
- transmission: bool, optional
Flag to select between transmission mode -> ln(monitor/detector) or fluorescence mode -> detector/monitor
- kwargs
The necessary kwargs are passed to the loading functions defined by the source argument:
csv -> possible kwargs: folder, name_format.
spec -> possible kwargs: folder.
databroker -> possible kwargs: stream, query, use_db_v1.
Note that a warning will be printed if the an unnecessary kwarg is passed.
- Returns:
- energynumpy.array
X-ray energy.
- xanesnumpy.array
X-ray absorption. If return_mean = True: xanes.shape = (len(scans), len(energy)), otherwise: xanes.shape = (len(energy))
- xmcdnumpy.array
X-ray magnetic dichroism. It has the same shape as the xanes.
- xanes_stdnumpy.array, optional
Error of the mean of x-ray absorption. This will only be returned if return_mean = True.
- xmcd_stdnumpy.array, optional
Error of the mean of x-ray magnetic dichroism. This will only be returned if return_mean = True.
See also
polartools.load_data.load_dichro()
- polartools.absorption.load_multi_lockin(scans, source, return_mean=True, positioner=None, dc_col=None, ac_col=None, acoff_col=None, **kwargs)[source]¶
Load multiple x-ray magnetic dichroism energy “lockin” scans.
- Parameters:
- scansiterable
Sequence of scan_ids our uids. If scan_id is passed, it will load the last scan with that scan_id. Use kwargs for search options.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable kwargs depend on this selection.
- return_meanboolean, optional
Flag to indicate if the averaging of multiple scans will be performed. Note that if True three outputs are generated, otherwise two.
- positionerstring, optional
Name of the positioner, this needs to be the same as defined in Bluesky or SPEC. If None is passed, it defauts to the x-ray energy.
- dc_colstring, optional
Name of the DC scaler, again it needs to be the same name as in Bluesky or SPEC. If None is passed, it defaults to ‘Lock DC’.
- ac_colstring, optional
Name of the AC scaler. If None is passed, it defaults to ‘Lock AC’.
- acoff_colstring, optional
Name of the AC offset scaler. If None is passed, it defaults to ‘Lock AC off’.
- kwargs
The necessary kwargs are passed to the loading functions defined by the source argument:
csv -> possible kwargs: folder, name_format.
spec -> possible kwargs: folder.
databroker -> possible kwargs: stream, query, use_db_v1.
Note that a warning will be printed if the an unnecessary kwarg is passed.
- Returns:
- energynumpy.array
X-ray energy.
- xanesnumpy.array
X-ray absorption. If return_mean = True: xanes.shape = (len(scans), len(energy)), otherwise: xanes.shape = (len(energy))
- xmcdnumpy.array
X-ray magnetic dichroism. It has the same shape as the xanes.
- xanes_stdnumpy.array, optional
Error of the mean of x-ray absorption. This will only be returned if return_mean = True.
- xmcd_stdnumpy.array, optional
Error of the mean of x-ray magnetic dichroism. This will only be returned if return_mean = True.
See also
polartools.load_data.load_lockin()
- polartools.absorption.load_multi_xas(scans, source, return_mean=True, positioner=None, detector=None, monitor=None, transmission=True, **kwargs)[source]¶
Load multiple x-ray absorption energy scans.
- Parameters:
- scansiterable
Sequence of scan_ids our uids. If scan_id is passed, it will load the last scan with that scan_id. Use kwargs for search options.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable kwargs depend on this selection.
- return_meanboolean, optional
Flag to indicate if the averaging of multiple scans will be performed. Note that if True three outputs are generated, otherwise two.
- positionerstring, optional
Name of the positioner, this needs to be the same as defined in Bluesky or SPEC. If None is passed, it defauts to the x-ray energy.
- detectorstring, optional
Detector to be read from this scan, again it needs to be the same name as in Bluesky. If None is passed, it defaults to the ion chamber 5.
- monitorstring, optional
Name of the monitor detector. If None is passed, it defaults to the ion chamber 4.
- transmission: bool, optional
Flag to select between transmission mode -> ln(monitor/detector) or fluorescence mode -> detector/monitor
- kwargs
The necessary kwargs are passed to the loading functions defined by the source argument:
csv -> possible kwargs: folder, name_format.
spec -> possible kwargs: folder.
databroker -> possible kwargs: stream, query, use_db_v1.
Note that a warning will be printed if the an unnecessary kwarg is passed.
- Returns:
- energynumpy.array
X-ray energy.
- xanesnumpy.array
X-ray absorption. If return_mean = True: xanes.shape = (len(scans), len(energy)), otherwise: xanes.shape = (len(energy))
- xanes_stdnumpy.array, optional
Error of the mean of x-ray absorption. This will only be returned if return_mean = True.
See also
polartools.load_data.load_absorption()
- polartools.absorption.normalize_absorption(energy, mu, *, e0=None, edge_step=None, pre_range=None, pre_order=1, nvict=0, post_range=None, post_order=None, flat_range=None, flat_order=None, pre_pars=None, post_pars=None, flat_pars=None)[source]¶
Extract pre- and post-edge normalization curves by fitting polynomials.
This is a wrapper of for the pre_edge_background, post_edge_background, and post_edge_flatten. The overall process is largely based on larch.xafs.preedge, but it was modified so that a polynomial of any order can be applied to the pre-edge, and the initial parameters for the pre- and post-edge polynomials can be given by the user.
- Parameters:
- energyiterable
Incident energy. Must be in eV. It will raise an error if it notices the maximum of this list is below 100.
- muiterable
Raw x-ray absorption.
- e0float or int, optional
Absorption edge energy. If None, it is extracted from the data.
- edge_stepfloat, optional
Size of edge step of the raw data. If None, it is calculated based by postedge[e0] - preedge[e0].
- pre_rangelist, optional
List with the energy ranges [initial, final] of the pre-edge region relative to the absorption edge. If None is passed to either pre_range or one of the elements, a guessed value will be used. For example:
pre_range = None -> guess initial and final points.
pre_range = [None, -20] -> guess only initial point.
pre_range = [-40, None] -> guess only final point.
pre_range = [-40, -20] -> guess neither.
- pre_orderint, optional
Order of the polynomial to be used in the pre-edge. Defaults to 1.
- nvictint, optional
Energy exponent to use. The pre-edge background is modelled by a line that is fit to xanes(energy)*energy**pre_exponent. Defaults to 0.
- post_rangelist, optional
List with the energy ranges [initial, final] of the post-edge region relative to the absorption edge.
- post_orderint, optional
Order of the polynomial to be used in the post-edge. If None, it will be determined by larch.xafs.preedge:
If post_range[1]-post_range[0]>350 -> post_order = 2;
if 50 < post_range[1]-post_range[0] < 350 -> post_order = 1;
otherwise -> post_order = 0
- flat_rangelist, optional
List with the energy ranges [initial, final] of the post-edge region relative to the absorption edge. If None, it will be set as the same as post_range.
- flat_orderint, optional
Order of the polynomial to be used in the post-edge. If None, it will be set as the same as post_order.
- pre_pars, post_pars, flat_parslmfit.Parameters, optional
Option to input the initial parameters to the polynomial used in the data flattening. These will be labelled ‘c0’, ‘c1’, …, depending on post_order. See lmfit.models.PolynomialModel for details.
- Returns:
- resultsdict
Dictionary with the results and parameters of the normalization and flattening. The most important items are:
‘energy’ -> incident energy.
‘mu’ -> raw xanes.
‘norm’ -> normalized xanes.
‘flat’ -> flattened xanes.
See also
- polartools.absorption.plot_xmcd(plus, minus)[source]¶
Plots a new figure with the combined XMCD of plus and minus fields.
- Parameters:
- plusdictionary
XANES/XMCD taken using the “plus” magnetic field. Output of the normalize_absorption function.
- minusdictionary
XANES/XMCD taken using the “minus” magnetic field. Output of the normalize_absorption function.
- Returns:
- figmatplotlib.pyplot.figure
Figure instance.
- axslist
List of the figure axes.
- polartools.absorption.post_edge_background(energy, mu, preedge=None, e0=None, edge_step=None, post1=None, post2=None, post_order=None, post_pars=None)[source]¶
Extracts the post-edge background by fitting a polynomial.
Based on larch.xafs.preedge. Modified so that a polynomial of any order can be applied to the post-edge, and its initial parameters can be given by the user.
- Parameters:
- energyiterable
Incident energy. Must be in eV. It will raise an error if it notices the maximum of this list is below 100.
- muiterable
Raw x-ray absorption.
- e0float or int, optional
Absorption edge energy.
- edge_stepfloat, optional
Size of edge step of the raw data. If None, it is calculated based by postedge[e0] - preedge[e0].
- preedgeiterable, optional
Pre-edge polynomial. If None, it will be set to zero.
- post1, post2float, optional
- Low, high energy limit of post-edge range with respect to e0. If None,
it will try to guess it based on mu(energy).
- post_orderint, optional
Order of the polynomial to be used in the post-edge. If None, it will be determined using:
If post2-post1>350 -> post_order = 2;
if 50 < post2-post1 < 350 -> post_order = 1;
otherwise -> post_order = 0
- post_parslmfit.Parameters, optional
Option to input the initial parameters to the polynomial used in the data flattening. These will be labelled ‘c0’, ‘c1’, …, depending on post_order. See lmfit.models.PolynomialModel for details.
- Returns:
- resultsdict
Dictionary with the results and parameters of the normalization and flattening. The most important items are:
‘energy’ -> incident energy.
‘mu’ -> raw xanes.
‘norm’ -> normalized XAS.
‘post-edge’ -> post-edge background.
‘edge-step’ -> Absorption jump size.
See also
larch.xafs.preedge()larch.absorption.normalize_absorption()
- polartools.absorption.post_edge_flatten(energy, norm, bkg_results=None, e0=None, flat1=None, flat2=None, flat_order=None, flat_pars=None)[source]¶
Flattens the normalized absorption.
This is a slightly modified version from that in the larch package.
The energies inputs must have the same units.
- Parameters:
- energyiterable
Incident energy in eV.
- normiterable
Normalized x-ray absorption.
- bkg_resultsdict, optional
Results of the data processing done by post_edge_background. If None, the remaining keyword arguments will be ignored.
- e0float or int
Absorption edge energy.
- flat1, flat2float or int
Low, high energy limit of flattening range with respect to e0.
- flat_orderint, optional
Degree of polynomial to be used. If None, it will be determined using:
If post2-post1>350 -> post_order = 2;
if 50 < post2-post1 < 350 -> post_order = 1;
otherwise -> post_order = 0
- fparslmfit.Parameters, optional
Option to input the initial parameters. These will be labelled ‘c0’, ‘c1’, …, depending on nnorm. See lmfit.models.PolynomialModel for details.
- Returns:
- flatnumpy.array
Flattened x-ray absorption.
See also
larch.xafs.pre_edge()lmfit.models.PolynomialModel()
- polartools.absorption.pre_edge_background(energy, mu, e0=None, pre1=None, pre2=None, pre_order=1, nvict=0, pre_pars=None)[source]¶
Extracts the pre-edge background by fitting a polynomial.
Based on larch.xafs.preedge. Modified so that a polynomial of any order can be applied to the pre-edge, and its initial parameters can be given by the user.
- Parameters:
- energyiterable
Incident energy. Must be in eV. It will raise an error if it notices the maximum of this list is below 100.
- muiterable
Raw x-ray absorption.
- e0float or int, optional
Absorption edge energy.
- pre1, pre2float, optional
- Low, high energy limit of pre-edge range with respect to e0. If None,
it will try to guess it based on mu(energy).
- pre_orderint, optional
Order of the polynomial to be used in the pre-edge. Defaults to 1.
- nvictint, optional
Energy exponent to use. The pre-edge background is modelled by a line that is fit to xanes(energy)*energy**pre_exponent. Defaults to 0.
- pre_parslmfit.Parameters, optional
Option to input the initial parameters to the polynomial used in the data flattening. These will be labelled ‘c0’, ‘c1’, …, depending on post_order. See lmfit.models.PolynomialModel for details.
- Returns:
- resultsdict
Dictionary with the results and parameters of the normalization and flattening. The most important items are:
‘energy’ -> incident energy.
‘mu’ -> raw xanes.
‘preedge’ -> preedge polynomial.
See also
larch.xafs.preedge()larch.absorption.normalize_absorption()
- polartools.absorption.process_xmcd(scans_plus, scans_minus, source, xmcd_kind='dichro', load_parameters={}, normalization_parameters={}, normalization_parameters_minus=None)[source]¶
Process the XMCD scans of +/- magnetic fields.
- Parameters:
- scans_plusiterable
List of scan number or scan_id of XMCD taken using the “plus” magnetic field.
- scans_minusiterable
List of scan number or scan_id of XMCD taken using the “minus” magnetic field.
- sourcedatabroker database, name of the spec file, or ‘csv’
Note that applicable load_parameters depend on this selection.
- xmcd_kind“dichro” or “lockin”, optional
Type of XMCD scan used, defaults to “dichro”.
- load_parametersdictionary
Parameters used to load data. Passed as kwargs to polartools.absorption.load_multi_dichro or polartools.absorption.load_multi_lockin.
- normalization_parametersdictionary
Parameters used to normalize the “plus” data (and the “minus” data when
normalization_parameters_minusis None). Passed as kwargs to polartools.absorption.normalize_absorption.- normalization_parameters_minusdictionary, optional
If provided, used to normalize the “minus” data independently. When None (default), the “minus” data is normalized with the same parameters as the “plus” data.
- Returns:
- plusdictionary
XANES/XMCD taken using the “plus” magnetic field. Output of polartools.absorption.normalize_absorption with the XMCD data added.
- minusdictionary
XANES/XMCD taken using the “minus” magnetic field. Output of polartools.absorption.normalize_absorption with the XMCD data added.
- polartools.absorption.save_xmcd(plus, minus, file_name, header='XMCD\n', fmt='%0.5e')[source]¶
Saves processed XANES/XMCD data into a file.
- Parameters:
- plusdictionary
XMCD taken using the “plus” magnetic field. It needs at least three keys: “energy”, “norm”, and “xmcd”.
- minusdictionary
XMCD taken using the “minus” magnetic field. It needs at least three keys: “energy”, “norm”, and “xmcd”.
- file_namestring
File name (including folder if not current).
- headerstring, optional
File header. Note that each line has to be finished with the newline character.
- fmtstring, optional
Format of the data, defaults to %0.5e