Calculates absorption correction for given mu1 and mu2.
Multiply the measured spectrum with this correction factor.
This is a translation of Keijo Hamalainen’s Matlab function (KH 30.05.96).
Args
mu1 : np.array Absorption coefficient for the incident energy in [1/cm].
mu2 : np.array Absorption coefficient for the scattered energy in [1/cm].
alpha : float Incident angle relative to plane normal in [deg].
beta : float Exit angle relative to plane normal [deg].
samthick : float Sample thickness in [cm].
geometry : string, optional
Key word for different sample geometries (‘transmission’, ‘reflection’, ‘sphere’).
If geometry is set to ‘sphere’, no angular dependence is assumed.
Returns
ac : np.array
Absorption correction factor. Multiply this with your measured spectrum.
Calculates absorption correction for given mu1 and mu2.
Multiply the measured spectrum with this correction factor.
This is a translation of Keijo Hamalainen’s Matlab function (KH 30.05.96).
Args:
mu1 (np.array): absorption coefficient for the incident energy in [1/cm].
mu2 (np.array): absorption coefficient for the scattered energy in [1/cm].
alpha (float): incident angle relative to plane normal in [deg].
beta (float): exit angle relative to plane normal [deg] (for transmission geometry use beta < 0).
samthick (float): sample thickness in [cm].
Returns:
ac (np.array): absorption correction factor. Multiply this with your measured spectrum.
XRStools.xrs_utilities.addch(xold, yold, n, n0=0, errors=None)[source]¶
# ADDCH Adds contents of given adjacent channels together
#
# [x2,y2] = addch(x,y,n,n0)
# x = original x-scale (row or column vector)
# y = original y-values (row or column vector)
# n = number of channels to be summed up
# n0 = offset for adding, default is 0
# x2 = new x-scale
# y2 = new y-values
#
# KH 17.09.1990
# Modified 29.05.1995 to include offset
function [U,B,V]=bidiag_reduction(A)
% [U B V]=bidiag_reduction(A)
% Algorithm 6.5-1 in Golub & Van Loan, Matrix Computations
% Johns Hopkins University Press
% Finds an upper bidiagonal matrix B so that A=U*B*V’
% with U,V orthogonal. A is an m x n matrix
bootstrapCNNMF
Constrained non-negative matrix factorization with bootstrapping
for error estimates.
XRStools.xrs_utilities.bragg(hkl, e, xtal='Si')[source]¶
% BRAGG Calculates Bragg angle for given reflection in RAD
% output=bangle(hkl,e,xtal)
% hkl can be a matrix i.e. hkl=[1,0,0 ; 1,1,1];
% e=energy in keV
% xtal=’Si’, ‘Ge’, etc. (check dspace.m) or d0 (Si default)
%
% KH 28.09.93
%
XRStools.xrs_utilities.braggd(hkl, e, xtal='Si')[source]¶
# BRAGGD Calculates Bragg angle for given reflection in deg
# Call BRAGG.M
# output=bangle(hkl,e,xtal)
# hkl can be a matrix i.e. hkl=[1,0,0 ; 1,1,1];
# e=energy in keV
# xtal=’Si’, ‘Ge’, etc. (check dspace.m) or d0 (Si default)
#
# KH 28.09.93
cfactorizeOffDiaMatrix
constrained version of factorizeOffDiaMatrix
Returns main components from an off-diagonal Matrix (energy-loss x angular-departure).
convtoprim
converts diamond structure reciprocal lattice expressed in conventional
lattice vectors to primitive one (Helsinki -> Palaiseau conversion)
from S. Huotari
w2 (foat, array): Energy of Compton peak in [keV].
Funktion adapted from Keijo Hamalainen.
XRStools.xrs_utilities.delE_JohannAberration(E, A, R, Theta)[source]¶
Calculates the Johann aberration of a spherical analyzer crystal.
Args:
E (float): Working energy in [eV].
A (float): Analyzer aperture [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Calculates the intrinsic energy resolution of a diced crystal
analyzer.
Args:
E (float): Working energy in [eV].
Dw (float): Darwin width of the used reflection [microRad].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Intrinsic energy resolution of a perfect analyzer crystal.
XRStools.xrs_utilities.delE_offRowland(E, z, A, R, Theta)[source]¶
Calculates the off-Rowland contribution of a spherical analyzer crystal.
Args:
E (float): Working energy in [eV].
z (float): Off-Rowland distance [mm].
A (float): Analyzer aperture [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Off-Rowland contribution in [eV] to the energy resolution.
Calculates the pixel size contribution to the resolution function
of a diced analyzer crystal.
Args:
E (float): Working energy in [eV].
p (float): Pixel size in [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Pixel size contribution in [eV] to the energy resolution for a diced analyzer
crystal.
Calculates the source size contribution to the resolution function.
Args:
E (float): Working energy in [eV].
s (float): Source size in [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Source size contribution in [eV] to the energy resolution.
Calculates the stress induced contribution to the resulution function
of a spherically bent crystal analyzer.
Args:
E (float): Working energy in [eV].
t (float): Absorption length in the analyzer material [mm].
v (float): Poisson ratio of the analyzer material.
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Stress-induced contribution in [eV] to the energy resolution.
% DSPACE Gives d-spacing for given xtal
% d=dspace(hkl,xtal)
% hkl can be a matrix i.e. hkl=[1,0,0 ; 1,1,1];
% xtal=’Si’,’Ge’,’LiF’,’InSb’,’C’,’Dia’,’Li’ (case insensitive)
% if xtal is number this is user as a d0
%
% KH 28.09.93
% SH 2005
%
% ENERGY Calculates energy corrresponing to Bragg angle for given d-spacing
% function e=energy(dspace,bragg_angle)
%
% dspace for reflection
% bragg_angle in DEG
%
% KH 28.09.93
% ENERGY Calculates energy corrresponing to Bragg angle for given d-spacing
% function e=energy(dspace,bragg_angle)
%
% dspace for reflection (defaulf for Si(311) reflection)
% bragg_angle in DEG
%
% KH 28.09.93
%
get_UB_Q
Returns the momentum transfer and scattering vectors for given
FOURC spectrometer and sample angles. U-, B-matrices and
incident/scattered wavelength are passed as keyword-arguments.
function H = householder(b, k)
% H = householder(b, k)
% Atkinson, Section 9.3, p. 611
% b is a column vector, k an index < length(b)
% Constructs a matrix H that annihilates entries
% in the product H*b below index k
% $Id: householder.m,v 1.1 2008-01-16 15:33:30 mike Exp $
% M. M. Sussman
Linear interpolation scheme after Martin Sundermann that conserves
the absolute number of counts.
ONLY WORKS FOR EQUALLY/EVENLY SPACED XC, XI!
Args:
xc (np.array): The x-coordinates of the interpolated values.
xi (np.array): The x-coordinates of the data points, must be increasing.
yi (np.array): The y-coordinates of the data points, same length as xp.
i0 (np.array): Normalization values for the data points, same length as xp.
Returns:
ic (np.array): The interpolated and normalized data points.
from scipy.interpolate import Rbf
x = arange(20)
d = zeros(len(x))
d[10] = 1
xc = arange(0.5,19.5)
rbfi = Rbf(x, d)
di = rbfi(xc)
takes the profiles from ‘makepzprofile()’, converts them onto eloss
scale and normalizes them to S(q,w) [1/eV]
input:
element = element symbol (e.g. ‘Si’, ‘Al’, etc.)
filename = path and filename to tabulated profiles
E0 = scattering energy [keV]
tth = scattering angle [deg]
returns:
enscale = energy loss scale
J = total CP
C = only core contribution to CP
V = only valence contribution to CP
q = momentum transfer [a.u.]
returns the compton profile of a chemical compound with formula ‘formula’
input:
formula = string of a chemical formula (e.g. ‘SiO2’, ‘Ba8Si46’, etc.)
filename = path and filename to tabulated profiles
E0 = scattering energy [keV]
tth = scattering angle [deg]
returns:
eloss = energy loss scale
J = total CP
C = only core contribution to CP
V = only valence contribution to CP
q = momentum transfer [a.u.]
constructs compton profiles of element ‘element’ on pz-scale
(-100:100 a.u.) from the Biggs tables provided in ‘filename’
input:
element = element symbol (e.g. ‘Si’, ‘Al’, etc.)
filename = path and filename to tabulated profiles
returns:
pzprofile = numpy array of the CP:
* 1. column: pz-scale
* 2. … n. columns: compton profile of nth shell
* binden = binding energies of shells
* occupation = number of electrons in the according shells
Calculates the momentum transfer in atomic units
input:
e1 = incident energy [keV]
e2 = scattered energy [keV]
tth = scattering angle [deg]
returns:
q = momentum transfer [a.u.] (corresponding to sin(th)/lambda)
Calculates the momentum transfer in inverse angstrom
input:
e1 = incident energy [keV]
e2 = scattered energy [keV]
tth = scattering angle [deg]
returns:
q = momentum transfer [a.u.] (corresponding to sin(th)/lambda)
#% [T,Y] = ODE23(ODEFUN,TSPAN,Y0,OPTIONS,P1,P2,…) passes the additional
#% parameters P1,P2,… to the ODE function as ODEFUN(T,Y,P1,P2…), and to
#% all functions specified in OPTIONS. Use OPTIONS = [] as a place holder if
#% no options are set.
opens a plot window of the penetration depth of a mixture of chemical formulas
with certain concentrations and densities plotted along the given energy vector
primtoconv
converts diamond structure reciprocal lattice expressed in primitive basis
to the conventional basis (Palaiseau -> Helsinki conversion)
from S. Huotari
Calculates the incident energy for a specific scattered photon and momentum value.
Returns the incident energy for a given photon energy and scattering angle.
This function is translated from Keijo Hamalainen’s Matlab implementation (KH 29.05.96).
Args:
w2 (float): scattered photon energy in [keV]
pz (np.array): pz scale in [a.u.]
th (float): scattering angle two theta in [deg]
Returns:
w1 (np.array): incident energy in [keV]
XRStools.xrs_utilities.read_dft_wfn(element, n, l, spin=None, directory='/usr/lib/python3/dist-packages/XRStools/resources/data')[source]¶
read_dft_wfn
Parses radial parts of wavefunctions.
Args:
element (str): Element symbol.
n (int): Main quantum number.
l (int): Orbital quantum number.
spin (str): Which spin channel, default is average over up and down.
directory (str): Path to directory where the wavefunctions can be found.
Reads Hartree-Fock Profile of element ‘element’ from values tabulated
by Biggs et al. (Atomic Data and Nuclear Data Tables 16, 201-309 (1975))
as provided by the DABAX library (http://ftp.esrf.eu/pub/scisoft/xop2.3/DabaxFiles/ComptonProfiles.dat).
input:
filename = path to the ComptonProfiles.dat file (the file should be distributed with this package)
element = string of element name
returns:
data = the data for the according element as in the file:
#UD Columns:
#UD col1: pz in atomic units
#UD col2: Total compton profile (sum over the atomic electrons
#UD col3,…coln: Compton profile for the individual sub-shells
occupation = occupation number of the according shells
bindingen = binding energies of the accorting shells
colnames = strings of column names as used in the file
Smooth (and optionally differentiate) data with a Savitzky-Golay filter.
The Savitzky-Golay filter removes high frequency noise from data.
It has the advantage of preserving the original shape and
features of the signal better than other types of filtering
approaches, such as moving averages techniques.
Parameters:
y : array_like, shape (N,)
the values of the time history of the signal.
window_size : int
the length of the window. Must be an odd integer number.
order : int
the order of the polynomial used in the filtering.
Must be less then window_size - 1.
deriv: int
the order of the derivative to compute (default = 0 means only smoothing)
Returns
ys : ndarray, shape (N)
the smoothed signal (or it’s n-th derivative).
Notes:
The Savitzky-Golay is a type of low-pass filter, particularly
suited for smoothing noisy data. The main idea behind this
approach is to make for each point a least-square fit with a
polynomial of high order over a odd-sized window centered at
the point.
stiff_compl_matrix_Si
Returns stiffnes and compliance tensor of Si for a given
orientation.
Args:
e1 (np.array): unit vector normal to crystal surface
e2 (np.array): unit vector crystal surface
e3 (np.array): unit vector orthogonal to e2
Returns:
S (np.array): compliance tensor in new coordinate system
C (np.array): stiffnes tensor in new coordinate system
E (np.array): Young’s modulus in [GPa]
G (np.array): shear modulus in [GPa]
nu (np.array): Poisson ratio
Copied from S.I. of L. Zhang et al. “Anisotropic elasticity of silicon
and its application to the modelling of X-ray optics.”
J. Synchrotron Rad. 21, no. 3 (2014): 507-517.
% TAUPGEN Calculates the reflectivity curves of bent crystals
%
% function [refl,e,dev]=taupgen_new(e,hkl,crystals,R,dev,alpha);
%
% e = fixed nominal energy in keV
% hkl = reflection order vector, e.g. [1 1 1]
% crystals = crystal string, e.g. ‘si’ or ‘ge’
% R = bending radius in meters
% dev = deviation parameter for which the
% curve will be calculated (vector) (optional)
% alpha = asymmetry angle
% based on a FORTRAN program of Michael Krisch
% Translitterated to Matlab by Simo Huotari 2006, 2007
% Is far away from being good matlab writing - mostly copy&paste from
% the fortran routines. Frankly, my dear, I don’t give a damn.
% Complaints -> /dev/null
% TAUPGEN Calculates the reflectivity curves of bent crystals
%
% function [refl,e,dev]=taupgen_new(e,hkl,crystals,R,dev,alpha);
%
% e = fixed nominal energy in keV
% hkl = reflection order vector, e.g. [1 1 1]
% crystals = crystal string, e.g. ‘si’ or ‘ge’
% R = bending radius in meters
% dev = deviation parameter for which the
% curve will be calculated (vector) (optional)
% alpha = asymmetry angle
% based on a FORTRAN program of Michael Krisch
% Translitterated to Matlab by Simo Huotari 2006, 2007
% Is far away from being good matlab writing - mostly copy&paste from
% the fortran routines. Frankly, my dear, I don’t give a damn.
% Complaints -> /dev/null
unconstrained_mf
Returns main components from an off-diagonal Matrix (energy-loss x angular-departure),
using the power method iteratively on the different main components.
function [e2,s2] = broaden_diagram2(e,s,params,npoints)
% BROADEN_DIAGRAM2 Broaden a StoBe line diagram
%
% [ENE2,SQW2] = BROADEN_DIAGRAM2(ENE,SQW,PARAMS,NPOINTS)
%
% gives the broadened spectrum SQW2(ENE2) of the line-spectrum
% SWQ(ENE). Each line is substituted with a Gaussian peak,
% the FWHM of which is determined by PARAMS. ENE2 is a linear
% scale of length NPOINTS (default 1000).
%
% PARAMS = [f_min f_max emin max]
%
% For ENE <= e_min, FWHM = f_min.
% For ENE >= e_max, FWHM = f_min.
% FWHM increases linearly from [f_min f_max] between [e_min e_max].
%
% T Pylkkanen @ 2008-04-18 [17:37]
broadens a spectrum with a Gaussian of width params[0] below
params[2] and width params[1] above params[3], width increases
linear in between.
returns two-column numpy array of length npoints with energy and the broadened spectrum
Calculates the distance vector between two atoms from an
arbitrary simulation box using the minimum image convention.
Args:
atom1 (obj): Instance of the xzyAtom class.
atom2 (obj): Instance of the xzyAtom class.
lattice (np.array): Array with lattice vectors as columns.
lattice_inv (np.array): Inverse of lattice.
Returns:
The distance vector between the two atoms (np.array).
Calculates the distance of two atoms from an arbitrary
simulation box using the minimum image convention.
Args:
atom1 (obj): Instance of the xzyAtom class.
atom2 (obj): Instance of the xzyAtom class.
lattice (np.array): Array with lattice vectors as columns.
lattice_inv (np.array): Inverse of lattice.
load a bunch of StoBe calculations, which filenames are made up of the
prefix, postfix, and the counter in the between the prefix and postfix
runs from ‘fromnumber’ to ‘tonumber’ in steps of ‘step’ (number of digits
is ‘stepformat’)
function output = readxas(filename)%[e,p,s,px,py,pz] = readxas(filename)
% READSTF Load StoBe fort.11 (XAS output) data
%
% [E,P,S,PX,PY,PZ] = READXAS(FILENAME)
%
% E energy transfer [eV]
% P dipole transition intensity
% S r^2 transition intensity
% PX dipole transition intensity along x
% PY dipole transition intensity along y
% PZ dipole transition intensity along z
%
% as line diagrams.
%
% T Pylkkanen @ 2011-10-17
removePolyCoreAv
Subtract a polynomial from averaged data guided by the HF core Compton profile.
Args
element : str
String (e.g. ‘Si’) for the element you want to work on.
edge: str
String (e.g. ‘K’ or ‘L23’) for the edge to extract.
range1 : list
List with start and end value for fit-region 1.
range2 : list
List with start and end value for fit-region 2.
weigths : list of ints
List with weights for the respective fit-regions 1 and 2. Default is [1,1].
guess : list
List of starting values for the fit. Default is [1.0,0.0,0.0] (i.e. a quadratic
function. Change the number of guess values to get other degrees of polynomials
(i.e. [1.0, 0.0] for a constant, [1.0,0.0,0.0,0.0] for a cubic, etc.).
The first guess value passed is for scaling of the experimental data to the HF
core Compton profile.
ewindow: float
Width of energy window used in the plot. Default is 100.0.
Apply absorption correction to the Compton profiles on energy loss scale.
Args:
alpha :float
Angle of incidence (degrees).
beta : float
Exit angle for the scattered x-rays (degrees). If ‘beta’ is negative,
transmission geometry is assumed, if ‘beta’ is positive, reflection geometry.
This class should hold one or more instances of the ComptonProfile class
and have methods to return profiles from single atoms, single shells, all
atoms. It should be able to apply corrections etc. on those…
Attributes:
element (string): Element symbol as in the periodic table.
elementNr (int) : Number of the element as in the periodic table.
Uses the PzProfile function to read read in Biggs HF profiles
and converts them onto energy loss scale. The profiles are cut
at the respective electron binding energies and are normalized
to the f-sum rule (i.e. S(q,w) is in units of [1/eV]).
Args:
element (string): element symbol.
filename (string): absolute path and filename to tabulated Compton profiles.
E0 (float): analyzer energy in [keV].
tth (float): scattering angle two theta in [deg].
correctasym (np.array): vector of scaling factors to be applied.
valence_cutoff (float): energy value below which edges are considered as valence
Returns:
enScale (np.array): energy loss scale in [eV]
J_total (np.array): total S(q,w) in [1/eV]
C_total (np.array): core contribution to S(q,w) in [1/eV]
V_total (np.array): valence contribution to S(q,w) in [1/eV], the valence is defined by valence_cutoff
q (np.array): momentum transfer in [a.u]
J_shell (dict of np.arrays): dictionary of contributions for each shell, the key are defines as in Biggs table.
C_shell (dict of np.arrays): same as J_shell for core contribution
V_shell (dict of np.arrays): same as J_shell for valence contribution
Reads Hartree-Fock Profile of element ‘element’ from values tabulated
by Biggs et al. (Atomic Data and Nuclear Data Tables 16, 201-309 (1975))
as provided by the DABAX library (http://ftp.esrf.eu/pub/scisoft/xop2.3/DabaxFiles/ComptonProfiles.dat).
input:
filename = path to the ComptonProfiles.dat file (the file should be distributed with this package)
element = string of element name
returns:
data = the data for the according element as in the file:
#UD Columns:
#UD col1: pz in atomic units
#UD col2: Total compton profile (sum over the atomic electrons
#UD col3,…coln: Compton profile for the individual sub-shells
occupation = occupation number of the according shells
bindingen = binding energies of the accorting shells
colnames = strings of column names as used in the file
Class to calculate an expected cross section in absolute counts using objects of the ‘beam’, ‘sample’,
‘analyzer’, ‘detector’, ‘thomson’, and ‘compton_profile’ classes.
Calculates number of scatterers/atoms using beam size, sample thickness, sample densites,
sample molar masses (so far does not differentiate between target atoms and random sample atoms)
Calculates the efficiency of the analyzer crystal based on the calculated reflectivity curve.
The efficiency is calculated by averaging over the energy resolution set upon class initialization.
energy = energy (in [keV]) for wich the efficiency is to be calculated
Calculates the reflectivity curve for a given analyzer crystal. Checks
in the directory self.database_dir, if desired reflectivity curve has
been calculated before.
IN:
energy = energy at which the reflectivity is to be calculated in [keV]
dev = deviation parameter for which the curve is to be calculated
alpha = deviation angle from exact Bragg angle [deg]
Parses an input file, which has a structure like the example input file (‘prediction.inp’) provided in the
examples/ folder. (Python lists and numpy arrays have to be profived without white spaces in their definitions,
e.g. ‘hkl = [6,6,0]’ instead of ‘hkl = [6, 6, 0]’)
Calculates the absorption correction factor for the sample
to be multiplied with experimental data to correct for absorption effects.
energy1 = numpy array of energies in [keV] for which the factor is to be calculated
energy2 = numpy array of energies in [keV] for which the factor is to be calculated
Calculates the total photoelectric absorption coefficient of the sample
for the two energies given. Returns only one array, if only one energy axis
is defined.
energy1 = numpy array of energies in [keV]
energy2 = numpy array of energies in [keV] (defalt is None, i.e. only one mu is returned)
Generates a figure which plots 1/Abscorr for the sample as a function of different thicknesses.
This is usefull for finding optimum sample thicknesses for an experiment.
energy1 = energy in [keV] at the desired edge
energy2 = energy in [keV] at the elastic
range_of_thickness = numpy array of sample thicknesses in [cm]
!!! right now all samples are treates as if spherical !!!
Calculates absorption correction for given mu1 and mu2.
Multiply the measured spectrum with this correction factor.
This is a translation of Keijo Hamalainen’s Matlab function (KH 30.05.96).
Args
mu1 : np.array Absorption coefficient for the incident energy in [1/cm].
mu2 : np.array Absorption coefficient for the scattered energy in [1/cm].
alpha : float Incident angle relative to plane normal in [deg].
beta : float Exit angle relative to plane normal [deg].
samthick : float Sample thickness in [cm].
geometry : string, optional
Key word for different sample geometries (‘transmission’, ‘reflection’, ‘sphere’).
If geometry is set to ‘sphere’, no angular dependence is assumed.
Returns
ac : np.array
Absorption correction factor. Multiply this with your measured spectrum.
Calculates absorption correction for given mu1 and mu2.
Multiply the measured spectrum with this correction factor.
This is a translation of Keijo Hamalainen’s Matlab function (KH 30.05.96).
Args:
mu1 (np.array): absorption coefficient for the incident energy in [1/cm].
mu2 (np.array): absorption coefficient for the scattered energy in [1/cm].
alpha (float): incident angle relative to plane normal in [deg].
beta (float): exit angle relative to plane normal [deg] (for transmission geometry use beta < 0).
samthick (float): sample thickness in [cm].
Returns:
ac (np.array): absorption correction factor. Multiply this with your measured spectrum.
XRStools.xrs_utilities.addch(xold, yold, n, n0=0, errors=None)[source]¶
# ADDCH Adds contents of given adjacent channels together
#
# [x2,y2] = addch(x,y,n,n0)
# x = original x-scale (row or column vector)
# y = original y-values (row or column vector)
# n = number of channels to be summed up
# n0 = offset for adding, default is 0
# x2 = new x-scale
# y2 = new y-values
#
# KH 17.09.1990
# Modified 29.05.1995 to include offset
function [U,B,V]=bidiag_reduction(A)
% [U B V]=bidiag_reduction(A)
% Algorithm 6.5-1 in Golub & Van Loan, Matrix Computations
% Johns Hopkins University Press
% Finds an upper bidiagonal matrix B so that A=U*B*V’
% with U,V orthogonal. A is an m x n matrix
bootstrapCNNMF
Constrained non-negative matrix factorization with bootstrapping
for error estimates.
XRStools.xrs_utilities.bragg(hkl, e, xtal='Si')[source]¶
% BRAGG Calculates Bragg angle for given reflection in RAD
% output=bangle(hkl,e,xtal)
% hkl can be a matrix i.e. hkl=[1,0,0 ; 1,1,1];
% e=energy in keV
% xtal=’Si’, ‘Ge’, etc. (check dspace.m) or d0 (Si default)
%
% KH 28.09.93
%
XRStools.xrs_utilities.braggd(hkl, e, xtal='Si')[source]¶
# BRAGGD Calculates Bragg angle for given reflection in deg
# Call BRAGG.M
# output=bangle(hkl,e,xtal)
# hkl can be a matrix i.e. hkl=[1,0,0 ; 1,1,1];
# e=energy in keV
# xtal=’Si’, ‘Ge’, etc. (check dspace.m) or d0 (Si default)
#
# KH 28.09.93
cfactorizeOffDiaMatrix
constrained version of factorizeOffDiaMatrix
Returns main components from an off-diagonal Matrix (energy-loss x angular-departure).
convtoprim
converts diamond structure reciprocal lattice expressed in conventional
lattice vectors to primitive one (Helsinki -> Palaiseau conversion)
from S. Huotari
w2 (foat, array): Energy of Compton peak in [keV].
Funktion adapted from Keijo Hamalainen.
XRStools.xrs_utilities.delE_JohannAberration(E, A, R, Theta)[source]¶
Calculates the Johann aberration of a spherical analyzer crystal.
Args:
E (float): Working energy in [eV].
A (float): Analyzer aperture [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Calculates the intrinsic energy resolution of a diced crystal
analyzer.
Args:
E (float): Working energy in [eV].
Dw (float): Darwin width of the used reflection [microRad].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Intrinsic energy resolution of a perfect analyzer crystal.
XRStools.xrs_utilities.delE_offRowland(E, z, A, R, Theta)[source]¶
Calculates the off-Rowland contribution of a spherical analyzer crystal.
Args:
E (float): Working energy in [eV].
z (float): Off-Rowland distance [mm].
A (float): Analyzer aperture [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Off-Rowland contribution in [eV] to the energy resolution.
Calculates the pixel size contribution to the resolution function
of a diced analyzer crystal.
Args:
E (float): Working energy in [eV].
p (float): Pixel size in [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Pixel size contribution in [eV] to the energy resolution for a diced analyzer
crystal.
Calculates the source size contribution to the resolution function.
Args:
E (float): Working energy in [eV].
s (float): Source size in [mm].
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Source size contribution in [eV] to the energy resolution.
Calculates the stress induced contribution to the resulution function
of a spherically bent crystal analyzer.
Args:
E (float): Working energy in [eV].
t (float): Absorption length in the analyzer material [mm].
v (float): Poisson ratio of the analyzer material.
R (float): Radius of the Rowland circle [mm].
Theta (float): Analyzer Bragg angle [degree].
Returns:
Stress-induced contribution in [eV] to the energy resolution.
% DSPACE Gives d-spacing for given xtal
% d=dspace(hkl,xtal)
% hkl can be a matrix i.e. hkl=[1,0,0 ; 1,1,1];
% xtal=’Si’,’Ge’,’LiF’,’InSb’,’C’,’Dia’,’Li’ (case insensitive)
% if xtal is number this is user as a d0
%
% KH 28.09.93
% SH 2005
%
% ENERGY Calculates energy corrresponing to Bragg angle for given d-spacing
% function e=energy(dspace,bragg_angle)
%
% dspace for reflection
% bragg_angle in DEG
%
% KH 28.09.93
% ENERGY Calculates energy corrresponing to Bragg angle for given d-spacing
% function e=energy(dspace,bragg_angle)
%
% dspace for reflection (defaulf for Si(311) reflection)
% bragg_angle in DEG
%
% KH 28.09.93
%
get_UB_Q
Returns the momentum transfer and scattering vectors for given
FOURC spectrometer and sample angles. U-, B-matrices and
incident/scattered wavelength are passed as keyword-arguments.
function H = householder(b, k)
% H = householder(b, k)
% Atkinson, Section 9.3, p. 611
% b is a column vector, k an index < length(b)
% Constructs a matrix H that annihilates entries
% in the product H*b below index k
% $Id: householder.m,v 1.1 2008-01-16 15:33:30 mike Exp $
% M. M. Sussman
Linear interpolation scheme after Martin Sundermann that conserves
the absolute number of counts.
ONLY WORKS FOR EQUALLY/EVENLY SPACED XC, XI!
Args:
xc (np.array): The x-coordinates of the interpolated values.
xi (np.array): The x-coordinates of the data points, must be increasing.
yi (np.array): The y-coordinates of the data points, same length as xp.
i0 (np.array): Normalization values for the data points, same length as xp.
Returns:
ic (np.array): The interpolated and normalized data points.
from scipy.interpolate import Rbf
x = arange(20)
d = zeros(len(x))
d[10] = 1
xc = arange(0.5,19.5)
rbfi = Rbf(x, d)
di = rbfi(xc)
takes the profiles from ‘makepzprofile()’, converts them onto eloss
scale and normalizes them to S(q,w) [1/eV]
input:
element = element symbol (e.g. ‘Si’, ‘Al’, etc.)
filename = path and filename to tabulated profiles
E0 = scattering energy [keV]
tth = scattering angle [deg]
returns:
enscale = energy loss scale
J = total CP
C = only core contribution to CP
V = only valence contribution to CP
q = momentum transfer [a.u.]
returns the compton profile of a chemical compound with formula ‘formula’
input:
formula = string of a chemical formula (e.g. ‘SiO2’, ‘Ba8Si46’, etc.)
filename = path and filename to tabulated profiles
E0 = scattering energy [keV]
tth = scattering angle [deg]
returns:
eloss = energy loss scale
J = total CP
C = only core contribution to CP
V = only valence contribution to CP
q = momentum transfer [a.u.]
constructs compton profiles of element ‘element’ on pz-scale
(-100:100 a.u.) from the Biggs tables provided in ‘filename’
input:
element = element symbol (e.g. ‘Si’, ‘Al’, etc.)
filename = path and filename to tabulated profiles
returns:
pzprofile = numpy array of the CP:
* 1. column: pz-scale
* 2. … n. columns: compton profile of nth shell
* binden = binding energies of shells
* occupation = number of electrons in the according shells
Calculates the momentum transfer in atomic units
input:
e1 = incident energy [keV]
e2 = scattered energy [keV]
tth = scattering angle [deg]
returns:
q = momentum transfer [a.u.] (corresponding to sin(th)/lambda)
Calculates the momentum transfer in inverse angstrom
input:
e1 = incident energy [keV]
e2 = scattered energy [keV]
tth = scattering angle [deg]
returns:
q = momentum transfer [a.u.] (corresponding to sin(th)/lambda)
#% [T,Y] = ODE23(ODEFUN,TSPAN,Y0,OPTIONS,P1,P2,…) passes the additional
#% parameters P1,P2,… to the ODE function as ODEFUN(T,Y,P1,P2…), and to
#% all functions specified in OPTIONS. Use OPTIONS = [] as a place holder if
#% no options are set.
opens a plot window of the penetration depth of a mixture of chemical formulas
with certain concentrations and densities plotted along the given energy vector
primtoconv
converts diamond structure reciprocal lattice expressed in primitive basis
to the conventional basis (Palaiseau -> Helsinki conversion)
from S. Huotari
Calculates the incident energy for a specific scattered photon and momentum value.
Returns the incident energy for a given photon energy and scattering angle.
This function is translated from Keijo Hamalainen’s Matlab implementation (KH 29.05.96).
Args:
w2 (float): scattered photon energy in [keV]
pz (np.array): pz scale in [a.u.]
th (float): scattering angle two theta in [deg]
Returns:
w1 (np.array): incident energy in [keV]
XRStools.xrs_utilities.read_dft_wfn(element, n, l, spin=None, directory='/usr/lib/python3/dist-packages/XRStools/resources/data')[source]¶
read_dft_wfn
Parses radial parts of wavefunctions.
Args:
element (str): Element symbol.
n (int): Main quantum number.
l (int): Orbital quantum number.
spin (str): Which spin channel, default is average over up and down.
directory (str): Path to directory where the wavefunctions can be found.
Reads Hartree-Fock Profile of element ‘element’ from values tabulated
by Biggs et al. (Atomic Data and Nuclear Data Tables 16, 201-309 (1975))
as provided by the DABAX library (http://ftp.esrf.eu/pub/scisoft/xop2.3/DabaxFiles/ComptonProfiles.dat).
input:
filename = path to the ComptonProfiles.dat file (the file should be distributed with this package)
element = string of element name
returns:
data = the data for the according element as in the file:
#UD Columns:
#UD col1: pz in atomic units
#UD col2: Total compton profile (sum over the atomic electrons
#UD col3,…coln: Compton profile for the individual sub-shells
occupation = occupation number of the according shells
bindingen = binding energies of the accorting shells
colnames = strings of column names as used in the file
Smooth (and optionally differentiate) data with a Savitzky-Golay filter.
The Savitzky-Golay filter removes high frequency noise from data.
It has the advantage of preserving the original shape and
features of the signal better than other types of filtering
approaches, such as moving averages techniques.
Parameters:
y : array_like, shape (N,)
the values of the time history of the signal.
window_size : int
the length of the window. Must be an odd integer number.
order : int
the order of the polynomial used in the filtering.
Must be less then window_size - 1.
deriv: int
the order of the derivative to compute (default = 0 means only smoothing)
Returns
ys : ndarray, shape (N)
the smoothed signal (or it’s n-th derivative).
Notes:
The Savitzky-Golay is a type of low-pass filter, particularly
suited for smoothing noisy data. The main idea behind this
approach is to make for each point a least-square fit with a
polynomial of high order over a odd-sized window centered at
the point.
stiff_compl_matrix_Si
Returns stiffnes and compliance tensor of Si for a given
orientation.
Args:
e1 (np.array): unit vector normal to crystal surface
e2 (np.array): unit vector crystal surface
e3 (np.array): unit vector orthogonal to e2
Returns:
S (np.array): compliance tensor in new coordinate system
C (np.array): stiffnes tensor in new coordinate system
E (np.array): Young’s modulus in [GPa]
G (np.array): shear modulus in [GPa]
nu (np.array): Poisson ratio
Copied from S.I. of L. Zhang et al. “Anisotropic elasticity of silicon
and its application to the modelling of X-ray optics.”
J. Synchrotron Rad. 21, no. 3 (2014): 507-517.
% TAUPGEN Calculates the reflectivity curves of bent crystals
%
% function [refl,e,dev]=taupgen_new(e,hkl,crystals,R,dev,alpha);
%
% e = fixed nominal energy in keV
% hkl = reflection order vector, e.g. [1 1 1]
% crystals = crystal string, e.g. ‘si’ or ‘ge’
% R = bending radius in meters
% dev = deviation parameter for which the
% curve will be calculated (vector) (optional)
% alpha = asymmetry angle
% based on a FORTRAN program of Michael Krisch
% Translitterated to Matlab by Simo Huotari 2006, 2007
% Is far away from being good matlab writing - mostly copy&paste from
% the fortran routines. Frankly, my dear, I don’t give a damn.
% Complaints -> /dev/null
% TAUPGEN Calculates the reflectivity curves of bent crystals
%
% function [refl,e,dev]=taupgen_new(e,hkl,crystals,R,dev,alpha);
%
% e = fixed nominal energy in keV
% hkl = reflection order vector, e.g. [1 1 1]
% crystals = crystal string, e.g. ‘si’ or ‘ge’
% R = bending radius in meters
% dev = deviation parameter for which the
% curve will be calculated (vector) (optional)
% alpha = asymmetry angle
% based on a FORTRAN program of Michael Krisch
% Translitterated to Matlab by Simo Huotari 2006, 2007
% Is far away from being good matlab writing - mostly copy&paste from
% the fortran routines. Frankly, my dear, I don’t give a damn.
% Complaints -> /dev/null
unconstrained_mf
Returns main components from an off-diagonal Matrix (energy-loss x angular-departure),
using the power method iteratively on the different main components.