XRSTOOLS(1)

๐Ÿ“ฆ version 0.15.0+git20210910+c147919d, in ubuntu jammy

XRSTOOLS ๐Ÿ’– the XRStools manual, bestie edition

okay so this is XRSTOOLS(1) โ€” the whole XRStools documentation, and yes we are doing ALL of it. grab a snack. ๐Ÿ“

NAME

xrstools โ€” XRStools Documentation โœจ

Contents, coming at you in order:


INSTALLATION ๐Ÿ› ๏ธ

  • If you install from a Debian package you can literally skip all the points below, just install it, and then head straight on over to the code invocation section. no cap. ๐Ÿ’…
  • Using Git, sources can be retrieved with the following command:
git clone https://gitlab.esrf.fr/ixstools/xrstools
  • for a local installation you can use
python setup.py install --prefix=~/packages

then to run the code you must do beforehand

export PYTHONPATH=/home/yourname/packages/lib/python2.7/site-packages
export PATH=/home/yourname/bin:$PATH
  • To install by creating a virtual environment ๐ŸŒธ
export MYPREFIX=/REPLACE/WITH/YOUR/TARGET
cd ${MYPREFIX}
python3 -m venv myenv
source ${MYPREFIX}/myenv/bin/activate
pip install pip --upgrade
pip install setuptools --upgrade

git clone https://gitlab.esrf.fr/ixstools/xrstools

cd ${MYPREFIX}/xrstools/
pip install -r requirements.txt
python setup.py install
  • Examples can be found in the nonregression directory. ๐Ÿ‘‘
  • For the roi selection tool you need a recent version of pymca installed on your sistem. (yes, "sistem". we keep it. it's iconic. ๐Ÿ’€)
  • Usage examples can be found in the non regression directory.

CODE INVOCATION ๐Ÿš€

  • Some of the XRStools capabilities can be accessed by invocation of the XRS_swissknife script, providing as input a file in the yaml format.
  • To use the wizard the suggested instruction is
XRS_wizard  --wroot ~/software/XRStoolsSuperResolution/XRStools/WIZARD/methods/

the wroot argument tells where extra workflow can be found. In the above instruction we give workflows in the home source directory. This is practical because the wizard allows to edit them online and the modification will remain in the sources. or to access extra workflows that are not coming with the main disribution.

  • Depending on the details of your installation, you have the XRS_swissknife script sitting somewhere in a directory. Check the Installation page to see how to set PYTHONPATH and PATH in case of a local installation.

The following documentation has been generated automatically from the comments found in the code. ๐Ÿค–

GENERALITIES about XRS_swissknife

Super Resolution

  • to fit optical responses of all the analysers (you selected a ROI for) and the pixel response based on a foil scan embedded doc :
  • to extrapolate to a larger extent the ROIS and the foils scan, thus to cover a larger sample embedded doc :
  • to calculate the scalar product between a foil scan and a sample, for futher use in the inversion problem embedded doc :

Other features

  • e_rois

EXAMPLES EN VRAC ๐Ÿ‡ซ๐Ÿ‡ท

xrstools imaging example


VIDEOS ๐ŸŽฌ

  • A Tool to clean the spectra from Compton profile and absorption edge
  • A Tool to define ROI by using NNMF in spectral and spatial domain

DEVELOPERS CORNER ๐Ÿ‘ฉโ€๐Ÿ’ป

XRStools.roifinder_and_gui Module

XRStools.xrs_utilities Module

XRStools.xrs_utilities.Chi(chi, degrees=True)

rotation around (1,0,0), pos sense

XRStools.xrs_utilities.HRcorrect(pzprofile, occupation, q)

Returns the first order correction to filled 1s, 2s, and 2p Compton profiles.

Implementation after Holm and Ribberfors (citation ...).

Args:

  • pzprofile (np.array): Compton profile (e.g. tabulated from Biggs) to be corrected (2D matrix).
  • occupation (list): electron configuration.
  • q (float or np.array): momentum transfer in [a.u.].

Returns: asymmetry (np.array): asymmetries to be added to the raw profiles (normalized to the number of electrons on pz scale)

XRStools.xrs_utilities.NNMFcost(x, A, F, C, F_up, C_up, n, k, m)

NNMFcost Returns cost and gradient for NNMF with constraints.

XRStools.xrs_utilities.NNMFcost_der(x, A, F, C, F_up, C_up, n, k, m)

XRStools.xrs_utilities.NNMFcost_old(x, A, W, H, W_up, H_up)

NNMFcost Returns cost and gradient for NNMF with constraints.

XRStools.xrs_utilities.Omega(omega, degrees=True)

rotation around (0,0,1), pos sense

XRStools.xrs_utilities.Phi(phi, degrees=True)

rotation around (0,1,0), neg sense

XRStools.xrs_utilities.Rx(chi, degrees=True)

Rx Rotation matrix for vector rotations around the [1,0,0]-direction.

Args:

  • chi (float) : Angle of rotation.
  • degrees (bool) : Angle given in radians or degrees.

Returns:

  • 3x3 rotation matrix.

XRStools.xrs_utilities.Ry(phi, degrees=True)

Ry Rotation matrix for vector rotations around the [0,1,0]-direction.

Args:

  • phi (float) : Angle of rotation.
  • degrees (bool) : Angle given in radians or degrees.

Returns:

  • 3x3 rotation matrix.

XRStools.xrs_utilities.Rz(omega, degrees=True)

Rz Rotation matrix for vector rotations around the [0,0,1]-direction.

Args:

  • omega (float) : Angle of rotation.
  • degrees (bool) : Angle given in radians or degrees.

Returns:

  • 3x3 rotation matrix.

XRStools.xrs_utilities.TTsolver1D(el_energy, hkl=[6, 6, 0], crystal='Si', R=1.0, dev=array([...]), alpha=0.0, chitable_prefix='/home/christoph/sources/XRStools/data/chitables/chitable_')

okay the full signature is a LOT, here it is verbatim bestie, don't blink:

XRStools.xrs_utilities.TTsolver1D(el_energy, hkl=[6, 6, 0],
crystal='Si', R=1.0, dev=array([- 50., - 49., - 48., - 47., - 46., -
45., - 44., - 43., - 42., - 41., - 40., - 39., - 38., - 37., - 36., -
35., - 34., - 33., - 32., - 31., - 30., - 29., - 28., - 27., - 26., -
25., - 24., - 23., - 22., - 21., - 20., - 19., - 18., - 17., - 16., -
15., - 14., - 13., - 12., - 11., - 10., - 9., - 8., - 7., - 6., - 5., -
4., - 3., - 2., - 1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.,
12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25.,
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53.,
54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67.,
68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81.,
82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95.,
96., 97., 98., 99., 100., 101., 102., 103., 104., 105., 106., 107.,
108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119.,
120., 121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131.,
132., 133., 134., 135., 136., 137., 138., 139., 140., 141., 142., 143.,
144., 145., 146., 147., 148., 149.]), alpha=0.0,
chitable_prefix='/home/christoph/sources/XRStools/data/chitables/chitable_')

TTsolver Solves the Takagi-Taupin equation for a bent crystal.

This function is based on a Matlab implementation by S. Huotari of M. Krisch's Fortran programs.

Args:

  • el_energy (float): Fixed nominal (working) energy in keV.
  • hkl (array): Reflection order vector, e.g. [6, 6, 0]
  • crystal (str): Crystal used (can be silicon 'Si' or 'Ge')
  • R (float): Crystal bending radius in m.
  • dev (np.array): Deviation parameter (in arc. seconds) for which the reflectivity curve should be calculated.
  • alpha (float): Crystal assymetry angle.

Returns:

  • refl (np.array): Reflectivity curve.
  • e (np.array): Deviation from Bragg angle in meV.
  • dev (np.array): Deviation from Bragg angle in microrad.

XRStools.xrs_utilities.absCorrection(mu1, mu2, alpha, beta, samthick, geometry='transmission')

absCorrection

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.

XRStools.xrs_utilities.abscorr2(mu1, mu2, alpha, beta, samthick)

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)

this one is literally the original comment block, unedited, we are NOT touching it ๐Ÿซถ

# 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

XRStools.xrs_utilities.bidiag_reduction(A)

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

and that's part 1 bestie, more is coming so don't go anywhere ๐Ÿ’–

  • XRStools.xrs_utilities.bootstrapCNNMF(A, F_ini, C_ini, F_up, C_up, Niter) โ€” bootstrapCNNMF</p>, aka Constrained non-negative matrix factorization with bootstrapping for error estimates. bestie this one bootstraps so you get error bars too ๐Ÿ’…
  • XRStools.xrs_utilities.bootstrapCNNMF_old(A, k, Aerr, F_ini, C_ini, F_up, C_up, Niter=100) โ€” the legacy version, same deal: Constrained non-negative matrix factorization with bootstrapping for error estimates. note the extra k and Aerr args and the Niter=100 default ๐ŸŽ€
  • XRStools.xrs_utilities.bragg(hkl, e, xtal='Si') โ€” the OG Bragg angle calculator, and it wants it in RAD:
% 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
%

  • class XRStools.xrs_utilities.bragg_refl(crystal, hkl, alpha=0.0) โ€” Bases: object. it's the Dynamical theory of diffraction era, we love to see it โœจ
    • get_chi(energy, crystal=None, hkl=None)
    • get_nff(nff_path=None)
    • get_polarization_factor(tth, case='sigma') โ€” Calculate polarization factor. slay.
    • get_reflectivity(energy, delta_theta, case='sigma')
    • get_reflectivity_bent(energy, delta_theta, R)

  • XRStools.xrs_utilities.braggd(hkl, e, xtal='Si') โ€” same energy, but degrees this time, no cap:
# 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
  • XRStools.xrs_utilities.cNNMF_chris(A, W_fixed, W_free, maxIter=100, verbose=True) โ€” ok that's it, that's the whole entry, no description given, we move ๐Ÿ’€
  • XRStools.xrs_utilities.cixsUBfind(x, G, Q_sample, wi, wo, lambdai, lambdao) โ€” cixsUBfind. literally just its name.
  • XRStools.xrs_utilities.cixsUBgetAngles_primo(Q) โ€” primo angles, coming right up ๐Ÿ“
  • XRStools.xrs_utilities.cixsUBgetAngles_secondo(Q) โ€” secondo edition ๐Ÿ’œ
  • XRStools.xrs_utilities.cixsUBgetAngles_terzo(Q) โ€” terzo, completing the trio ๐Ÿ‘‘
  • XRStools.xrs_utilities.cixsUBgetQ_primo(tthv, tthh, psi) โ€” returns the Q0 given the detector position (tthv, tth) and th crystal orientation. This orientation is calculated considering :
    • the Bragg condition and the rotation around the G vector : this rotation is defined by psi which is a rotation around G
  • XRStools.xrs_utilities.cixsUBgetQ_secondo(tthv, tthh, psi) โ€” same vibes, secondo flavor ๐ŸŒธ
  • XRStools.xrs_utilities.cixsUBgetQ_terzo(tthv, tthh, psi) โ€” and terzo to close it out โœจ
  • XRStools.xrs_utilities.cixs_primo(tthv, tthh, psi, anal_braggd=86.5) โ€” cixs_primo, note that anal_braggd=86.5 default, iconic.
  • XRStools.xrs_utilities.cixs_secondo(tthv, tthh, psi, anal_braggd=86.5) โ€” cixs_secondo, same default, we stay consistent ๐Ÿซถ
  • XRStools.xrs_utilities.cixs_terzo(tthv, tthh, psi, anal_braggd=86.5) โ€” cixs_terzo, and 86.5 again. periodt.
  • XRStools.xrs_utilities.compute_matrix_elements(R1, R2, k, r) โ€” computes matrix elements, that's the whole lore ๐Ÿ’…
  • XRStools.xrs_utilities.con2mat(x, W, H, W_up, H_up) โ€” con2mat, no description, we respect the mystery ๐Ÿ™ˆ
  • XRStools.xrs_utilities.constrained_mf(A, W_ini, W_up, coeff_ini, coeff_up, maxIter=1000, tol=1e-08, maxIter_power=1000) โ€” cfactorizeOffDiaMatrix constrained version of factorizeOffDiaMatrix. Returns main components from an off-diagonal Matrix (energy-loss x angular-departure). so it eats an off-diagonal matrix and gives you the main components back, and yes those defaults are maxIter=1000, tol=1e-08, maxIter_power=1000 ๐Ÿ”ฅ
  • XRStools.xrs_utilities.constrained_svd(M, U_ini, S_ini, VT_ini, U_up, max_iter=10000, verbose=False) โ€” constrained_nnmf, Approximate singular value decomposition with constraints. and the signature it carries around is:
function [U, S, V] =
constrained_svd(M,U_ini,S_ini,V_ini,U_up,max_iter=10000,verbose=False)
  • XRStools.xrs_utilities.convertSplitEDF2EDF(foldername) โ€” converts the old style EDF files (one image for horizontal and one image for vertical chambers) to the new style EDF (one single image). glow-up for your files fr fr ๐Ÿ’–
    • Arg:
      • foldername (str): Path to folder with all the EDF-files to be converted.
  • XRStools.xrs_utilities.convg(x, y, fwhm) โ€” Convolution with Gaussian. x = x-vector, y = y-vector, fwhm = fulll width at half maximum of the gaussian with which y is convoluted. (yes it says "fulll", we keep it, we don't touch the lore) ๐ŸŽ€
  • XRStools.xrs_utilities.convtoprim(hklconv) โ€” convtoprim converts diamond structure reciprocal lattice expressed in conventional lattice vectors to primitive one (Helsinki -> Palaiseau conversion) from S. Huotari. it's giving international relocation ๐Ÿฆ‹
  • XRStools.xrs_utilities.cshift(w1, th) โ€” cshift Calculates Compton peak position.
    • Args:
      • w1 (float, array): Incident energy in [keV].
      • th (float): Scattering angle in [deg].
    • Returns:
      • w2 (foat, array): Energy of Compton peak in [keV].
    • Funktion adapted from Keijo Hamalainen. (yes, "Funktion", verbatim bestie ๐Ÿ˜ญ)
  • XRStools.xrs_utilities.delE_JohannAberration(E, A, R, Theta) โ€” 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].
    • Returns: Johann abberation in [eV].
  • XRStools.xrs_utilities.delE_dicedAnalyzerIntrinsic(E, Dw, Theta) โ€” 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) โ€” 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.
  • XRStools.xrs_utilities.delE_pixelSize(E, p, R, Theta) โ€” 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.
  • XRStools.xrs_utilities.delE_sourceSize(E, s, R, Theta) โ€” 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.
  • XRStools.xrs_utilities.delE_stressedCrystal(E, t, v, R, Theta) โ€” 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.
  • XRStools.xrs_utilities.diode(current, energy, thickness=0.03) โ€” diode Calculates the number of photons incident for a Si PIPS diode.
    • Args:
      • current (float): Diode current in [pA].
      • energy (float): Photon energy in [keV].
      • thickness (float): Thickness of Si active layer in [cm].
    • Returns:
      • flux (float): Number of photons per second.
    • Function adapted from Matlab function by S. Huotari. ๐Ÿ’œ
  • XRStools.xrs_utilities.dspace(hkl=[6, 6, 0], xtal='Si') โ€” the d-spacing plug, default hkl=[6, 6, 0] and xtal='Si':
% 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
%
  • class XRStools.xrs_utilities.dtxrd(hkl, energy, crystal='Si', asym_angle=0.0, angular_range=[- 0.0005, 0.0005], angular_step=1e-08) โ€” Bases: object. class to hold all things dynamic theory of diffraction. the main character of this section honestly ๐Ÿ‘‘
    • get_anomalous_absorption(energy=None)
    • get_eta(angular_range, angular_step=1e-08)
    • get_extinction_length(energy=None)
    • get_reflection_width()
    • get_reflectivity(angular_range=None, angular_step=None)
    • set_asymmetry(alpha) โ€” negative alpha -> more grazing incidence
    • set_energy(energy)
    • set_hkl(hkl)
  • XRStools.xrs_utilities.dtxrd_anomalous_absorption(energy, hkl, alpha=0.0, crystal='Si', angular_range=array([- 0.0005])) โ€” standalone version of the anomalous absorption getter โœจ
  • XRStools.xrs_utilities.dtxrd_extinction_length(energy, hkl, alpha=0.0, crystal='Si') โ€” extinction length, standalone, no description, take it as it is ๐ŸŒˆ
  • XRStools.xrs_utilities.dtxrd_reflectivity(energy, hkl, alpha=0.0, crystal='Si', angular_range=array([- 0.0005])) โ€” reflectivity, standalone, same defaults as the class method fam ๐ŸŽ€
  • XRStools.xrs_utilities.e2pz(w1, w2, th) โ€” Calculates the momentum scale and the relativistic Compton cross section correction according to P. Holm, PRA 37, 3706 (1988). This function is translated from Keijo Hamalainen's Matlab implementation (KH 29.05.96).
    • Args:
      • w1 (float or np.array): incident energy in [keV]
      • w2 (float or np.array): scattered energy in [keV]
      • th (float): scattering angle two theta in [deg]
    • returns:
      • pz (float or np.array): momentum scale in [a.u.]
      • cf (float or np.array): cross section correction factor such that: J(pz) = cf * d^2(sigma)/d(w2)*d(Omega) [barn/atom/keV/srad]
  • XRStools.xrs_utilities.edfread(filename) โ€” reads edf-file with filename "filename". OUTPUT: data = 256x256 numpy array ๐Ÿ“ธ
  • XRStools.xrs_utilities.edfread_test(filename) โ€” reads edf-file with filename "filename". OUTPUT: data = 256x256 numpy array. and here's how i opened the HH data, literally:
data = np.fromfile(f,np.int32)
image = np.reshape(data,(dim,dim))
  • XRStools.xrs_utilities.element(z) โ€” Converts atomic number into string of the element symbol and vice versa. two-way street bestie ๐Ÿ”

Returns the atomic number of the element you feed it, when z is a string of the element symbol โ€” or, flip it, the string of the element symbol for a given atomic number z. Both directions, iconic ๐Ÿ’ซ

Args:

  • z (string or int): string of the element symbol or atomic number.

Returns:

  • Z (string or int): string of the element symbol or atomic number.

XRStools.xrs_utilities.energy(d, ba)

Okay this one is lowkey just a docstring dump, so here it is verbatim, typos and all, because we respect the ancestors ๐Ÿซถ

% 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
Yes, corrresponing has three r's. That's the original's business, not mine. ๐Ÿ’…

XRStools.xrs_utilities.energy_monoangle(angle, d=1.6374176589984608)

Same energy-to-Bragg-angle situation, except this one has a default d already baked in โ€” and that default is for the Si(311) reflection. The bragg_angle is in DEG, bestie, don't come at me with radians.

% 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 %
(defaulf is also theirs. We're just the messengers. ๐ŸŽ€)

XRStools.xrs_utilities.fermi(rs)

fermi calculates the plasmon energy (in eV), the Fermi energy (in eV), the Fermi momentum (in a.u.), and the critical plasmon cut-off vector (in a.u.). Four-for-one, it's giving combo meal โœจ

Args:

  • rs (float): electron separation parameter

Returns:

  • wp (float): plasmon energy (in eV)
  • ef (float): Fermi energy (in eV)
  • kf (float): Fermi momentum (in a.u.)
  • kc (float): critical plasmon cut-off vector (in a.u.)

Based on Matlab function from A. Soininen. ๐Ÿซก


XRStools.xrs_utilities.find_center_of_mass(x, y)

Returns the center of mass (that's the first moment) for the curve y(x) you hand it. That's it. That's the whole function. Short queen. ๐Ÿ‘‘


XRStools.xrs_utilities.find_diag_angles(q, x0, U, B, Lab, beam_in, lambdai, lambdao, tol=1e-08, method='BFGS')

find_diag_angles finds the FOURC spectrometer and sample angles for a desired q. It's a whole optimization vibe.

Args:

  • q (array): Desired momentum transfer in Lab coordinates.
  • x0 (list): Guesses for the angles (tthv, tthh, chi, phi, omega).
  • U (array): 3x3 U-matrix Lab-to-sample transformation.
  • B (array): 3x3 B-matrix reciprocal lattice to absolute units transformation.
  • lambdai (float): Incident x-ray wavelength in Angstrom.
  • lambdao (float): Scattered x-ray wavelength in Angstrom.
  • tol (float): Toleranz for minimization (see scipy.optimize.minimize)
  • method (str): Method for minimization (see scipy.optimize.minimize)

Returns:

  • ans (array): tthv, tthh, phi, chi, omega
Toleranz is staying exactly as written. German moment. ๐Ÿ‡ฉ๐Ÿ‡ชโœจ

XRStools.xrs_utilities.fwhm(x, y)

Finds the full width at half maximum of the curve y vs. x. Returns f = FWHM and x0 = position of the maximum. Two little outputs, both main characters. ๐ŸŽ€


XRStools.xrs_utilities.gauss(x, x0, fwhm)

No description in the source. It exists. It's a Gaussian. Mysterious, unbothered, thriving. ๐Ÿฆ‹


XRStools.xrs_utilities.get_UB_Q(tthv, tthh, phi, chi, omega, **kwargs)

get_UB_Q returns the momentum transfer and scattering vectors for given FOURC spectrometer and sample angles. The U-matrix, B-matrix and the incident/scattered wavelengths get passed in as keyword-arguments, so watch those kwargs. ๐Ÿ‘€

Args:

  • tthv (float): Spectrometer vertical 2Theta angle.
  • tthh (float): Spectrometer horizontal 2Theta angle.
  • chi (float): Sample rotation around x-direction.
  • phi (float): Sample rotation around y-direction.
  • omega (float): Sample rotation around z-direction.
  • kwargs (dict): Dictionary with key-word arguments:
    • kwargs['U'] (array): 3x3 U-matrix Lab-to-sample transformation.
    • kwargs['B'] (array): 3x3 B-matrix reciprocal lattice to absolute units transformation.
    • kwargs['lambdai'] (float): Incident x-ray wavelength in Angstrom.
    • kwargs['lambdao'] (float): Scattered x-ray wavelength in Angstrom.

Returns:

  • Q_sample (array): Momentum transfer in sample coordinates.
  • Ki_sample (array): Incident beam direction in sample coordinates.
  • Ko_sample (array): Scattered beam direction in sample coordinates.

XRStools.xrs_utilities.get_gnuplot_rgb(start=None, end=None, length=None)

get_gnuplot_rgb prints out a progression of RGB hex-keys to use in Gnuplot. Plot aesthetic unlocked. ๐ŸŒˆ

Args:

  • start (array): RGB code to start from (must be numbers out of [0,1]).
  • end (array): RGB code to end at (must be numbers out of [0,1]).
  • length (int): How many colors to print out.

XRStools.xrs_utilities.get_num_of_MD_steps(time_ps, time_step)

Calculates the number of steps in an MD simulation</cya> for a desired time (in ps) and given step size (in a.u.).

Args:

  • time_ps (float): Desired time span (ps).
  • time_step (float): Chosen time step (a.u.).

Returns: The number of steps required to span the desired time span.


XRStools.xrs_utilities.getpenetrationdepth(energy, formulas, concentrations, densities)

Returns the penetration depth of a mixture of chemical formulas with certain concentrations and densities. Mixing chemicals in a trench coat, and this tells you how deep the x-rays get. ๐Ÿ•ต๏ธโ€โ™€๏ธ


XRStools.xrs_utilities.gettransmission(energy, formulas, concentrations, densities, thickness)

Returns the transmission through a sample composed of chemical formulas with certain densities mixed to certain concentrations, and a thickness. Basically getpenetrationdepth's extroverted sibling. โœจ


XRStools.xrs_utilities.hex2rgb(hex_val)

No description given. Converts a hex value to RGB. The name is doing all the talking and honestly? She's right. ๐Ÿ’…


XRStools.xrs_utilities.hlike_Rwfn(n, l, r, Z)

hlike_Rwfn returns an array with the radial part of a hydrogen-like wave function. Quantum girlies, this one's for you. โš›๏ธ

Args:

  • n (integer): main quantum number n
  • l (integer): orbitalquantum number l
  • r (array): vector of radii on which the function should be evaluated
  • Z (float): effective nuclear charge

XRStools.xrs_utilities.householder(b, k)

The docstring, faithfully, in all its Matlab-era glory:

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

That $Id: line is a fossil from version control past. We keep it because history is sacred. ๐Ÿซถ


XRStools.xrs_utilities.interpolate_M(xc, xi, yi, i0)

Linear interpolation scheme after Martin Sundermann that conserves the absolute number of counts.

ONLY WORKS FOR EQUALLY/EVENLY SPACED XC, XI! Not a suggestion, bestie. It's a whole warning. ๐Ÿ’€

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.

And then there's this little snippet hanging out at the bottom, verbatim:

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)

XRStools.xrs_utilities.is_allowed_refl_fcc(H)

is_allowed_refl_fcc checks if the given reflection is allowed for an FCC lattice. Yes/no, allowed or not, no nuance. ๐ŸŽฏ

Args:

  • H (array, list, tuple): H=[h,k,l]

Returns:

  • boolean

XRStools.xrs_utilities.lindhard_pol(q, w, rs=3.93, use_corr=False, lifetime=0.28)

lindhard_pol calculates the Lindhard polarizability function (RPA) for certain q (a.u.), w (a.u.) and rs (a.u.). Big physics energy, no cap.

Args:

  • q (float): momentum transfer (in a.u.)
  • w (float): energy (in a.u.)
  • rs (float): electron parameter
  • use_corr (boolean): if True, uses Bernardo's calculation for n(k) instead of the Fermi function.
  • lifetime (float): life time (default is 0.28 eV for Na).

Based on Matlab function by S. Huotari. ๐Ÿซก


XRStools.xrs_utilities.makeprofile(element, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat', E0=9.69, tth=35.0, correctasym=None)

Takes the profiles from makepzprofile(), converts them onto the 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.]

XRStools.xrs_utilities.makeprofile_comp(formula, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat', E0=9.69, tth=35, correctasym=None)

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.]

XRStools.xrs_utilities.makeprofile_compds(formulas, concentrations=None, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat', E0=9.69, tth=35.0, correctasym=None)

Returns the sum of compton profiles from a lost of chemical compounds weighted by the given concentration.

("a lost of" is exactly what the original says. I am not touching it. It's canon now. ๐ŸŽ€)

XRStools.xrs_utilities.makepzprofile(element, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat')

Constructs compton profiles of element 'element' on the 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:

โ€ฆand that's a cliffhanger, bestie ๐Ÿ’… the actual returns list is literally the next thing up, so hold that thought ๐Ÿฆ‹โœจ

  • pzprofile โ€” numpy array of the CP, and it comes in layers:
    • 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

  • XRStools.xrs_utilities.mat2con(W, H, W_up, H_up) โ€” and that's the whole entry bestie, the docs just hand you the signature and walk away ๐Ÿ’€
  • XRStools.xrs_utilities.mat2vec(F, C, F_up, C_up, n, k, m) โ€” same situation, no description attached, the signature is all we got
  • class XRStools.xrs_utilities.maxipix_det(name, spot_arrangement) โ€” Bases: object
    • it's a whole class whose job is to hold onto some useful values from the detectors you're using, and it exists so you can arrange the ROIs. that's the vibe ๐ŸŽ€
    • get_det_name()
    • get_pixel_range()
  • XRStools.xrs_utilities.momtrans_au(e1, e2, tth) โ€” 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)
  • XRStools.xrs_utilities.momtrans_inva(e1, e2, tth) โ€” 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)
  • XRStools.xrs_utilities.mpr(energy, compound) โ€” Calculates the photoelectric, elastic, and inelastic absorption of a chemical compound. (yes bestie it says it twice, iconic of it honestly โœจ)
    • Args:
      • energy (np.array): energy scale in [keV].
      • compound (string): chemical sum formula (e.g. 'SiO2')
    • Returns:
      • murho (np.array): absorption coefficient normalized by the density.
      • rho (float): density in UNITS?
      • m (float): atomic mass in UNITS?
  • XRStools.xrs_utilities.mpr_compds(energy, formulas, concentrations, E0, rho_formu) โ€” Calculates the photoelectric, elastic, and inelastic absorption of a mix of compounds. Returns the photoelectric absorption for a sum of different chemical compounds.
    • Args:
      • energy (np.array): energy scale in [keV].
      • formulas (list of strings): list of chemical sum formulas
    • Returns:
      • murho (np.array): absorption coefficient normalized by the density.
      • rho (float): density in UNITS?
      • m (float): atomic mass in UNITS?
  • XRStools.xrs_utilities.myprho(energy, Z, logtablefile='/usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat') โ€” Calculates the photoelectric, elastic, and inelastic absorption of an element Z. Calculates the photelectric , elastic, and inelastic absorption of an element Z. Z can be atomic number or element symbol.
    • Args:
      • energy (np.array): energy scale in [keV].
      • Z (string or int): atomic number or string of element symbol.
    • Returns:
      • murho (np.array): absorption coefficient normalized by the density.
      • rho (float): density in UNITS?
      • m (float): atomic mass in UNITS?
  • XRStools.xrs_utilities.nonzeroavg(y=None) โ€” that's it, that's the entry ๐ŸŒธ
  • XRStools.xrs_utilities.odefctn(y, t, abb0, abb1, abb7, abb8, lex, sgbeta, y0, c1) โ€” the docs for this one are literally just a pasted comment block, so here it is verbatim:
#%    [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.
  • XRStools.xrs_utilities.odefctn_CN(yCN, t, abb0, abb1, abb7, abb8N, lex, sgbeta, y0, c1) โ€” no description given, just the signature, and honestly we respect the mystery ๐Ÿ™ˆ
  • XRStools.xrs_utilities.parseformula(formula) โ€” Parses a chemical sum formula. Parses the constituing elements and stoichiometries from a given chemical sum formula.
    • Args:
      • formula (string): string of a chemical formula (e.g. 'SiO2', 'Ba8Si46', etc.)
    • Returns:
      • elements (list): list of strings of constituting elemental symbols.
      • stoichiometries (list): list of according stoichiometries in the same order as 'elements'.
  • XRStools.xrs_utilities.plotpenetrationdepth(energy, formulas, concentrations, densities) โ€” 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
  • XRStools.xrs_utilities.plottransmission(energy, formulas, concentrations, densities, thickness) โ€” opens a plot with the transmission plotted along the given energy vector
  • XRStools.xrs_utilities.primtoconv(hklprim) โ€” primtoconv converts diamond structure reciprocal lattice expressed in primitive basis to the conventional basis (Palaiseau -> Helsinki conversion) from S. Huotari
  • XRStools.xrs_utilities.pz2e1(w2, pz, th) โ€” 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') โ€” 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.
    • Returns:
      • r (np.array): radius
      • wfn (np.array):
  • XRStools.xrs_utilities.readbiggsdata(filename, element) โ€” 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
  • XRStools.xrs_utilities.readfio(prefix, scannumber, repnumber=0) โ€” if repnumber = 0: reads a spectra-file (name: prefix_scannumber.fio) if repnumber > 1: reads a spectra-file (name: prefix_scannumber_rrepnumber.fio)
  • XRStools.xrs_utilities.readp01image(filename) โ€” reads a detector file from PetraIII beamline P01
  • XRStools.xrs_utilities.readp01scan(prefix, scannumber) โ€” reads a whole scan from PetraIII beamline P01 (experimental)
  • XRStools.xrs_utilities.readp01scan_rep(prefix, scannumber, repetition) โ€” reads a whole scan with repititions from PetraIII beamline P01 (experimental)
  • XRStools.xrs_utilities.savitzky_golay(y, window_size, order, deriv=0, rate=1) โ€” 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. lowkey a legend for this one ๐Ÿ‘‘
    • 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.
    • Examples
t = np.linspace(-4, 4, 500)
y = np.exp( -t**2 ) + np.random.normal(0, 0.05, t.shape)
ysg = savitzky_golay(y, window_size=31, order=4)
import matplotlib.pyplot as plt
plt.plot(t, y, label='Noisy signal')
plt.plot(t, np.exp(-t**2), 'k', lw=1.5, label='Original signal')
plt.plot(t, ysg, 'r', label='Filtered signal')
plt.legend()
plt.show()
  • References ::
[1]  A. Savitzky, M. J. E. Golay, Smoothing and Differentiation
     of Data by Simplified Least Squares Procedures. Analytical
     Chemistry, 1964, 36 (8), pp 1627-1639.

[2]  Numerical Recipes 3rd Edition: The Art of Scientific
     Computing W.H. Press, S.A. Teukolsky, W.T. Vetterling, B.P.
     Flannery Cambridge University Press ISBN-13: 9780521880688
  • XRStools.xrs_utilities.sgolay2d(z, window_size, order, derivative=None) โ€” no description, just the signature, she's mysterious like that ๐Ÿฆ‹
  • XRStools.xrs_utilities.sigmainc(Z, energy, logtablefile='/usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat') โ€” sigmainc Calculates the Incoherent Scattering Cross Section in cm^2/g using Log-Log Fit.
    • Args:
  • z (int or string) โ€” the element number, or honestly just the element's symbol, whatever's easier for you bestie ๐Ÿ’–
  • energy (float or array) โ€” the energy (a plain number OR a whole vector, she's flexible like that)

Returns:

  • tau (float or array) โ€” the photoelectric cross section, in [cm**2/g] โœจ

Adapted from original Matlab function of Keijo Hamalainen.


XRStools.xrs_utilities.specread(filename, nscan) โ€” reads scan "nscan" out of SPEC-file "filename" ๐ŸŽ€

INPUT:

  • filename = string with the SPEC-file name
  • nscan = number (int) of desired scan

OUTPUT:

  • data =
  • motors =
  • counters = dictionary

XRStools.xrs_utilities.spline2(x, y, x2) โ€” Extrapolates the smaller and larger valuea as a constant

not me leaving the typo in, that's literally what it says ๐Ÿ’€ keep it, it's canon

XRStools.xrs_utilities.split_hdf5_address(dataadress)

she has zero documentation, no notes, nothing. iconic mysterious queen behavior. we simply pass the address and vibe ๐Ÿ™ˆ

XRStools.xrs_utilities.stiff_compl_matrix_Si(e1, e2, e3, ansys=False)

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.


XRStools.xrs_utilities.sumx(A) โ€” Short-hand command to sum over 1st dimension of a N-D matrix (N>2) and to squeeze it to N-1-D matrix.

lowkey the most relatable function in this whole file, she just squishes ๐Ÿซถ

XRStools.xrs_utilities.svd_my(M, maxiter=100, eta=0.1)

no description, no args, no notes. she's giving mystery main character energy and we respect it ๐Ÿ’…

XRStools.xrs_utilities.taupgen(e, hkl=[6, 6, 0], crystals='Si', R=1.0, dev=array([- 50., - 49., - 48., - 47., - 46., - 45., - 44., - 43., - 42., - 41., - 40., - 39., - 38., - 37., - 36., - 35., - 34., - 33., - 32., - 31., - 30., - 29., - 28., - 27., - 26., - 25., - 24., - 23., - 22., - 21., - 20., - 19., - 18., - 17., - 16., - 15., - 14., - 13., - 12., - 11., - 10., - 9., - 8., - 7., - 6., - 5., - 4., - 3., - 2., - 1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95., 96., 97., 98., 99., 100., 101., 102., 103., 104., 105., 106., 107., 108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119., 120., 121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131., 132., 133., 134., 135., 136., 137., 138., 139., 140., 141., 142., 143., 144., 145., 146., 147., 148., 149.]), alpha=0.0)

and the docstring, verbatim, because it is a cultural artifact ๐Ÿ˜ญ:

% 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
"Frankly, my dear, I don't give a damn." โ€” the author said what she said and honestly? periodt. the complaints department is /dev/null, do not email her ๐Ÿ’€

XRStools.xrs_utilities.taupgen_amplitude(e, hkl=[6, 6, 0], crystals='Si', R=1.0, dev=array([- 50., - 49., - 48., - 47., - 46., - 45., - 44., - 43., - 42., - 41., - 40., - 39., - 38., - 37., - 36., - 35., - 34., - 33., - 32., - 31., - 30., - 29., - 28., - 27., - 26., - 25., - 24., - 23., - 22., - 21., - 20., - 19., - 18., - 17., - 16., - 15., - 14., - 13., - 12., - 11., - 10., - 9., - 8., - 7., - 6., - 5., - 4., - 3., - 2., - 1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95., 96., 97., 98., 99., 100., 101., 102., 103., 104., 105., 106., 107., 108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119., 120., 121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131., 132., 133., 134., 135., 136., 137., 138., 139., 140., 141., 142., 143., 144., 145., 146., 147., 148., 149.]), alpha=0.0)

and the docstring, also verbatim, because she is her sister's twin ๐Ÿฆ‹:

% 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

XRStools.xrs_utilities.tauphoto(Z, energy, logtablefile='/usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat')

tauphoto Calculates Photoelectric Cross Section in cm^2/g using Log-Log Fit.

Args:

  • z (int or string) โ€” Element number or elements symbol.
  • energy (float or array) โ€” Energy (can be number or vector)

Returns:

  • tau (float or array) โ€” Photoelectric cross section in [cm**2/g]

Adapted from original Matlab function of Keijo Hamalainen.

and yes the default logtablefile path is literally that long, bestie, /usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat, copy it exactly or perish ๐Ÿ’…

XRStools.xrs_utilities.unconstrained_mf(A, numComp=3, maxIter=1000, tol=1e-08)

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.


XRStools.xrs_utilities.vangle(v1, v2)

vangle Calculates the angle between two cartesian vectors v1 and v2 in degrees.

Args:

  • v1 (np.array) โ€” first vector.
  • v2 (np.array) โ€” second vector.

Returns:

  • th (float) โ€” angle between first and second vector.

Function by S. Huotari, adopted for Python.


XRStools.xrs_utilities.vec2mat(x, F, C, F_up, C_up, n, k, m)

no description. she just sits there. seven arguments and a dream ๐Ÿ™ˆ

XRStools.xrs_utilities.vrot(v, vaxis, phi)

vrot Rotates a vector around a given axis.

Args:

  • v (np.array) โ€” vector to be rotated
  • vaxis (np.array) โ€” rotation axis
  • phi (float) โ€” angle [deg] respecting the right-hand rule

Returns:

  • v2 (np.array) โ€” new rotated vector

Function by S. Huotari (2007) adopted to Python.


XRStools.xrs_utilities.vrot2(vector1, vector2, angle)

rotMatrix Rotate vector1 around vector2 by an angle.


XRStools.xrs_utilities.xas_fluo_correct(ene, mu, formula, fluo_ene, edge_ene, angin, angout)

xas_fluo_correct Fluorescence yield over-absorption correction as in Larch/Athena. see: https://www3.aps.anl.gov/haskel/FLUO/Fluo-manual.pdf

Args:

  • ene (np.array) โ€” energy axis in [keV]
  • mu (np.array) โ€” measured fluorescence spectrum
  • formula (str) โ€” chemical sum formulas (e.g. 'SiO2')
  • fluo_ene (float) โ€” energy in keV of main fluorescence line
  • edge_ene (float) โ€” edge energy in [keV]
  • angin (float) โ€” incidence angle (relative to sample normal) [deg.]
  • angout (float) โ€” exit angle (relative to sample normal) [deg.]

Returns:

  • ene (np.array) โ€” energy axis in [keV]
  • mu_corr (np.array) โ€” corrected fluorescence spectrum

๐ŸŒˆ XRStools.XRStool Package ๐ŸŒˆ


โœจ XRStools.xrs_calctools Module โœจ

XRStools.xrs_calctools.alterGROatomNames(filename, oldName, newName)

another mysterious no-doc queen. she renames atoms in your GRO file and says nothing else ๐ŸŽ€

XRStools.xrs_calctools.axsfTrajParser(filename)

axsfTrajParser

that's it. that's the whole description. she's self-titled ๐Ÿ˜ญ

XRStools.xrs_calctools.beta(a, b, size=None)

Draw samples from a Beta distribution.

The Beta distribution is a special case of the Dirichlet distribution, and is related to the Gamma distribution. It has the probability distribution function

f(x; a,b) = \frac{1}{B(\alpha, \beta)} x^{\alpha - 1} (1 - x)^{\beta - 1},

where the normalization, B, is the beta function,

B(\alpha, \beta) = \int_0^1 t^{\alpha - 1} (1 - t)^{\beta - 1} dt.

It is often seen in Bayesian inference and order statistics.

NOTE: New code should use the beta method of a default_rng() instance instead; please see the random-quick-start. (translation: this one's kinda old, bestie, there's a newer cuter version ๐Ÿ’…)
  • a โ€” float or array_like of floats Alpha, positive (>0).
  • b โ€” float or array_like of floats Beta, positive (>0).
  • size โ€” int or tuple of ints, optional Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if a and b are both scalars. Otherwise, np.broadcast(a, b).size samples are drawn.
  • out โ€” ndarray or scalar Drawn samples from the parameterized beta distribution.

Generator.beta: which should be used for new code.


XRStools.xrs_calctools.binomial(n, p, size=None)

Draw samples from a binomial distribution.

okay bestie, we're still deep in function-reference territory and honestly it's giving โœจ*living documentation*โœจ โ€” no skipping, we read it ALL ๐Ÿ’…

Samples are drawn from a binomial distribution with specified parameters, n trials and p probability of success where n an integer >= 0 and p is in the interval [0,1]. (n may be input as a float, but it is truncated to an integer in use)

NOTE: New code should use the binomial method of a default_rng() instance instead; please see the random-quick-start.
  • n โ€” int or array_like of ints. Parameter of the distribution, >= 0. Floats are also accepted, but they will be truncated to integers.
  • p โ€” float or array_like of floats. Parameter of the distribution, >= 0 and <=1.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if n and p are both scalars. Otherwise, np.broadcast(n, p).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized binomial distribution, where each sample is equal to the number of successes over the n trials.
  • scipy.stats.binom โ€” probability density function, distribution or cumulative density function, etc.
  • Generator.binomial: which should be used for new code.

The probability density for the binomial distribution is

P(N) = \binom{n}{N}p^N(1-p)^{n-N},

where n is the number of trials, p is the probability of success, and N is the number of successes.

When estimating the standard error of a proportion in a population by using a random sample, the normal distribution works well unless the product p*n <=5, where p = population proportion estimate, and n = number of samples, in which case the binomial distribution is used instead. For example, a sample of 15 people shows 4 who are left handed, and 11 who are right handed. Then p = 4/15 = 27%. 0.27*15 = 4, so the binomial distribution should be used in this case. ๐ŸŒธ

References, bestie, keep them all:

  1. Dalgaard, Peter, "Introductory Statistics with R", Springer-Verlag, 2002.
  2. Glantz, Stanton A. "Primer of Biostatistics.", McGraw-Hill, Fifth Edition, 2002.
  3. Lentner, Marvin, "Elementary Applied Statistics", Bogden and Quigley, 1972.
  4. Weisstein, Eric W. "Binomial Distribution." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/BinomialDistribution.html
  5. Wikipedia, "Binomial distribution", https://en.wikipedia.org/wiki/Binomial_distribution

Draw samples from the distribution:

>>> n, p = 10, .5  # number of trials, probability of each trial
>>> s = np.random.binomial(n, p, 1000)
# result of flipping a coin 10 times, tested 1000 times.

A real world example. A company drills 9 wild-cat oil exploration wells, each with an estimated probability of success of 0.1. All nine wells fail. What is the probability of that happening?

Let's do 20,000 trials of the model, and count the number that generate zero positive results.

>>> sum(np.random.binomial(9, 0.1, 20000) == 0)/20000.
# answer = 0.38885, or 38%.

XRStools.xrs_calctools.boxParser(filename)

parseXYZfile Reads an xyz-style file. ๐ŸŽ€

XRStools.xrs_calctools.broaden_diagram(e, s, params=[1.0, 1.0, 537.5, 540.0], npoints=1000)

okay this one comes with its whole original docstring attached, and we are NOT paraphrasing it, we're keeping it ๐Ÿ’ฏ:

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]

XRStools.xrs_calctools.broaden_linear(spec, params=[0.8, 8, 537.5, 550], npoints=1000)

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 ๐ŸŒˆ

XRStools.xrs_calctools.calculateCOMlist(atomList)

calculateCOMlist Calculates center of mass for a list of atoms. โญ

XRStools.xrs_calctools.calculateRIJhist(atoms, boxLength, DELR=0.01, MAXBIN=1000)

no extra tea on this one, the signature says it all, periodt ๐Ÿซถ

XRStools.xrs_calctools.calculateRIJhist2_arb(atoms1, atoms2, lattice, lattice_inv, DELR=0.01, MAXBIN=1000)

same energy as above, just the _arb variant ๐Ÿ’œ

XRStools.xrs_calctools.calculateRIJhist_arb(atoms1, atoms2, lattice, lattice_inv, DELR=0.01, MAXBIN=1000)

yep, another one, keep scrolling bestie โœจ

XRStools.xrs_calctools.changeOHBondLength(h2oMol, fraction, boxLength=None, oName='O', hName='H')

no description in the source, just vibes and these exact arguments ๐Ÿ”ฅ

XRStools.xrs_calctools.chisquare(df, size=None)

Draw samples from a chi-square distribution.

When df independent random variables, each with standard normal distributions (mean 0, variance 1), are squared and summed, the resulting distribution is chi-square (see Notes). This distribution is often used in hypothesis testing. ๐Ÿงš

NOTE: New code should use the chisquare method of a default_rng() instance instead; please see the random-quick-start.
  • df โ€” float or array_like of floats. Number of degrees of freedom, must be > 0.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if df is a scalar. Otherwise, np.array(df).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized chi-square distribution.
  • ValueError โ€” When df <= 0 or when an inappropriate size (e.g. size=-1) is given.
  • Generator.chisquare: which should be used for new code.

The variable obtained by summing the squares of df independent, standard normally distributed random variables:

Q = \sum_{i=0}^{\mathtt{df}} X^2_i

is chi-square distributed, denoted

Q \sim \chi^2_k.

The probability density function of the chi-squared distribution is

p(x) = \frac{(1/2)^{k/2}}{\Gamma(k/2)} x^{k/2 - 1} e^{-x/2},

where \Gamma is the gamma function,

\Gamma(x) = \int_0^{-\infty} t^{x - 1} e^{-t} dt.

Reference:

  1. NIST "Engineering Statistics Handbook" https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
>>> np.random.chisquare(2,4)
array([ 1.89920014,  9.00867716,  3.13710533,  5.62318272]) # random

XRStools.xrs_calctools.choice(a, size=None, replace=True, p=None)

Generates a random sample from a given 1-D array

New in version 1.7.0. ๐ŸŽ‰

NOTE: New code should use the choice method of a default_rng() instance instead; please see the random-quick-start.
  • a โ€” 1-D array-like or int. If an ndarray, a random sample is generated from its elements. If an int, the random sample is generated as if it were np.arange(a)
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
  • replace โ€” boolean, optional. Whether the sample is with or without replacement. Default is True, meaning that a value of a can be selected multiple times.
  • p โ€” 1-D array-like, optional. The probabilities associated with each entry in a. If not given, the sample assumes a uniform distribution over all entries in a.

Returns:

  • samples โ€” single item or ndarray. The generated random samples
  • ValueError โ€” If a is an int and less than zero, if a or p are not 1-dimensional, if a is an array-like of size 0, if p is not a vector of probabilities, if a and p have different lengths, or if replace=False and the sample size is greater than the population size
  • randint, shuffle, permutation
  • Generator.choice: which should be used in new code

Setting user-specified probabilities through p uses a more general but less efficient sampler than the default. The general sampler produces a different sample than the optimized sampler even if each element of p is 1 / len(a).

Sampling random rows from a 2-D array is not possible with this function, but is possible with Generator.choice through its axis keyword.

Generate a uniform random sample from np.arange(5) of size 3:

>>> np.random.choice(5, 3)
array([0, 3, 4]) # random
>>> #This is equivalent to np.random.randint(0,5,3)

Generate a non-uniform random sample from np.arange(5) of size 3:

>>> np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0])
array([3, 3, 0]) # random

Generate a uniform random sample from np.arange(5) of size 3 without replacement:

>>> np.random.choice(5, 3, replace=False)
array([3,1,0]) # random
>>> #This is equivalent to np.random.permutation(np.arange(5))[:3]

Generate a non-uniform random sample from np.arange(5) of size 3 without replacement:

>>> np.random.choice(5, 3, replace=False, p=[0.1, 0, 0.3, 0.6, 0])
array([2, 3, 0]) # random

Any of the above can be repeated with an arbitrary array-like instead of just integers. For instance:

>>> aa_milne_arr = ['pooh', 'rabbit', 'piglet', 'Christopher']
>>> np.random.choice(aa_milne_arr, 5, p=[0.5, 0.1, 0.1, 0.3])
array(['pooh', 'pooh', 'pooh', 'Christopher', 'piglet'], # random
      dtype='<U11')

XRStools.xrs_calctools.convg(x, y, fwhm)

Convolution with Gaussian ๐Ÿ’–

XRStools.xrs_calctools.countHbonds(mol1, mol2, Roocut=3.6, Rohcut=2.4, Aoooh=30.0)

no description given, just the exact call signature, keep it safe ๐Ÿ™ˆ

XRStools.xrs_calctools.countHbonds_orig(mol1, mol2, Roocut=3.6, Rohcut=2.4, Aoooh=30.0)

the _orig one, same signature, iconic as ever ๐Ÿ‘‘

XRStools.xrs_calctools.countHbonds_pbc(mol1, mol2, boxLength, Roocut=3.6, Rohcut=2.4, Aoooh=30.0)

XRStools.xrs_calctools.countHbonds_pbc(mol1, mol2, boxLength, Roocut=3.6, Rohcut=2.4, Aoooh=30.0)

no description dropped for this one bestie, just the signature, but look at those default vibes โœจ (Roocut=3.6, Rohcut=2.4, Aoooh=30.0) โ€” she came prepared ๐Ÿ’…

XRStools.xrs_calctools.count_HBonds_pbc_arb(mol1, mol2, lattice, lattice_inv, Roocut=3.6, Rohcut=2.4, Aoooh=30.0)

XRStools.xrs_calctools.count_HBonds_pbc_arb(mol1, mol2, lattice, lattice_inv, Roocut=3.6, Rohcut=2.4, Aoooh=30.0)

the arb version, aka the one that takes a lattice and lattice_inv so it can do the arbitrary-cell thing ๐Ÿฆ‹ same cute cutoffs as her sister function.

XRStools.xrs_calctools.count_OO_neighbors(list_of_o_atoms, Roocut, boxLength=None)

XRStools.xrs_calctools.count_OO_neighbors(list_of_o_atoms, Roocut, boxLength=None)

XRStools.xrs_calctools.count_OO_neighbors_pbc(list_of_o_atoms, Roocut, boxLength, numbershells=1)

XRStools.xrs_calctools.count_OO_neighbors_pbc(list_of_o_atoms, Roocut, boxLength, numbershells=1)

note the numbershells=1 default โ€” you can count more than one shell if you're feeling extra ๐Ÿ’€

XRStools.xrs_calctools.cut_spec(spec, emin=None, emax=None)

deletes lines of matrix with first column smaller than emin and larger than emax

bestie this one deletes stuff. it's a cutter. it removes the rows. so like, be aware, it's not a gentle vibe-check, it's a โœ‚๏ธ situation.

XRStools.xrs_calctools.dirichlet(alpha, size=None)

Draw samples from the Dirichlet distribution.

Draw size samples of dimension k from a Dirichlet distribution. A Dirichlet-distributed random variable can be seen as a multivariate generalization of a Beta distribution. The Dirichlet distribution is a conjugate prior of a multinomial distribution in Bayesian inference.

NOTE: New code should use the dirichlet method of a default_rng() instance instead; please see the random-quick-start.
  • alpha โ€” sequence of floats, length k. Parameter of the distribution (length k for sample of length k).
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n), then m * n * k samples are drawn. Default is None, in which case a vector of length k is returned.
  • samples โ€” ndarray, The drawn samples, of shape (size, k).
  • ValueError โ€” If any value in alpha is less than or equal to zero
  • Generator.dirichlet: which should be used for new code.

The Dirichlet distribution is a distribution over vectors x that fulfil the conditions x_i>0 and \sum_{i=1}^k x_i = 1.

The probability density function p of a Dirichlet-distributed random vector X is proportional to

p(x) \propto \prod_{i=1}^{k}{x^{\alpha_i-1}_i},

where \alpha is a vector containing the positive concentration parameters.

The method uses the following property for computation: let Y be a random vector which has components that follow a standard gamma distribution, then X = \frac{1}{\sum_{i=1}^k{Y_i}} Y is Dirichlet-distributed

Taking an example cited in Wikipedia, this distribution can be used if one wanted to cut strings (each of initial length 1.0) into K pieces with different lengths, where each piece had, on average, a designated average length, but allowing some variation in the relative sizes of the pieces.

>>> s = np.random.dirichlet((10, 5, 3), 20).transpose()

>>> import matplotlib.pyplot as plt
>>> plt.barh(range(20), s[0])
>>> plt.barh(range(20), s[1], left=s[0], color='g')
>>> plt.barh(range(20), s[2], left=s[0]+s[1], color='r')
>>> plt.title("Lengths of Strings")

string-cutting plot moment ๐ŸŽ€ iconic honestly.

class XRStools.xrs_calctools.erkale(prefix, postfix, fromnumber, tonumber, step, stepformat=2)

Bases: object

class to analyze ERKALE XRS results.

  • broaden_lin(params=[0.8, 8, 537.5, 550], npoints=1000)
  • cut_broadspecs(emin=None, emax=None)
  • cut_rawspecs(emin=None, emax=None)
  • norm_area(emin=None, emax=None)
  • norm_max()
  • plot_spec()
  • sum_specs()

look at her, a whole little class with a whole little method list ๐Ÿ’– that broaden_lin default params=[0.8, 8, 537.5, 550] with npoints=1000 is doing numbers fr fr.

XRStools.xrs_calctools.exponential(scale=1.0, size=None)

Draw samples from an exponential distribution.

Its probability density function is

 f(x; \frac{1}{\beta}) = \frac{1}{\beta} \exp(-\frac{x}{\beta}),

for x > 0 and 0 elsewhere. \beta is the scale parameter, which is the inverse of the rate parameter \lambda = 1/\beta. The rate parameter is an alternative, widely used parameterization of the exponential distribution [3]_.

The exponential distribution is a continuous analogue of the geometric distribution. It describes many common situations, such as the size of raindrops measured over many rainstorms [1]_, or the time between page requests to Wikipedia [2]_.

NOTE: New code should use the exponential method of a default_rng() instance instead; please see the random-quick-start.
  • scale โ€” float or array_like of floats. The scale parameter, \beta = 1/\lambda. Must be non-negative.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if scale is a scalar. Otherwise, np.array(scale).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized exponential distribution.
  • Generator.exponential: which should be used for new code.
  • [1] Peyton Z. Peebles Jr., "Probability, Random Variables and Random Signal Principles", 4th ed, 2001, p. 57.
  • [2] Wikipedia, "Poisson process", https://en.wikipedia.org/wiki/Poisson_process
  • [3] Wikipedia, "Exponential distribution", https://en.wikipedia.org/wiki/Exponential_distribution

XRStools.xrs_calctools.f(dfnum, dfden, size=None)

Draw samples from an F distribution.

Samples are drawn from an F distribution with specified parameters, dfnum (degrees of freedom in numerator) and dfden (degrees of freedom in denominator), where both parameters must be greater than zero.

The random variate of the F distribution (also known as the Fisher distribution) is a continuous probability distribution that arises in ANOVA tests, and is the ratio of two chi-square variates.

NOTE: New code should use the f method of a default_rng() instance instead; please see the random-quick-start.
  • dfnum โ€” float or array_like of floats. Degrees of freedom in numerator, must be > 0.
  • dfden โ€” float or array_like of float. Degrees of freedom in denominator, must be > 0.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if dfnum and dfden are both scalars. Otherwise, np.broadcast(dfnum, dfden).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized Fisher distribution.
  • scipy.stats.f โ€” probability density function, distribution or cumulative density function, etc.
  • Generator.f: which should be used for new code.

The F statistic is used to compare in-group variances to between-group variances. Calculating the distribution depends on the sampling, and so it is a function of the respective degrees of freedom in the problem. The variable dfnum is the number of samples minus one, the between-groups degrees of freedom, while dfden is the within-groups degrees of freedom, the sum of the number of samples in each group minus the number of groups.

An example from Glantz[1], pp 47-40:

Two groups, children of diabetics (25 people) and children from people without diabetes (25 controls). Fasting blood glucose was measured, case group had a mean value of 86.1, controls had a mean value of 82.2. Standard deviations were 2.09 and 2.49 respectively. Are these data consistent with the null hypothesis that the parents diabetic status does not affect their children's blood glucose levels? Calculating the F statistic from the data gives a value of 36.01.

Draw samples from the distribution:

>>> dfnum = 1. # between group degrees of freedom
>>> dfden = 48. # within groups degrees of freedom
>>> s = np.random.f(dfnum, dfden, 1000)

The lower bound for the top 1% of the samples is :

>>> np.sort(s)[-10]
7.61988120985 # random

So there is about a 1% chance that the F statistic will exceed 7.62, the measured value is 36, so the null hypothesis is rejected at the 1% level.

the null hypothesis got REJECTED bestie, 1% level, no cap ๐Ÿ˜ญ

XRStools.xrs_calctools.findAllWaters(point, waterMols, o_name, cutoff)

XRStools.xrs_calctools.findAllWaters(point, waterMols, o_name, cutoff)

XRStools.xrs_calctools.findHexaneMolecules(box, c_atoms, CC_cut=1.7, CH_cut=1.2)

XRStools.xrs_calctools.findHexaneMolecules(box, c_atoms, CC_cut=1.7, CH_cut=1.2)

XRStools.xrs_calctools.findMethanolMolecules(box, CO_cut=1.6, CH_cut=1.2, OH_cut=1.2)

XRStools.xrs_calctools.findMethanolMolecules(box, CO_cut=1.6, CH_cut=1.2, OH_cut=1.2)

three cutoffs for methanol, she's thorough ๐Ÿ’…

XRStools.xrs_calctools.findMolecule(xyzAtoms, molAtomList)

XRStools.xrs_calctools.findMolecule(xyzAtoms, molAtomList)

XRStools.xrs_calctools.find_H2O_molecules(o_atoms, h_atoms, boxLength=None)

XRStools.xrs_calctools.find_H2O_molecules(o_atoms, h_atoms, boxLength=None)

XRStools.xrs_calctools.find_H2O_molecules_PBC_arb(o_atoms, h_atoms, lattice, lattice_inv, OH_cutoff=1.5)

XRStools.xrs_calctools.find_H2O_molecules_PBC_arb(o_atoms, h_atoms, lattice, lattice_inv, OH_cutoff=1.5)

the arbitrary-lattice water-finder, with that OH_cutoff=1.5 ๐Ÿฆ‹

XRStools.xrs_calctools.gamma(shape, scale=1.0, size=None)

Draw samples from a Gamma distribution.

Samples are drawn from a Gamma distribution with specified parameters, shape (sometimes designated "k") and scale (sometimes designated "theta"), where both parameters are > 0.

NOTE: New code should use the gamma method of a default_rng() instance instead; please see the random-quick-start.
  • shape โ€” float or array_like of floats. The shape of the gamma distribution. Must be non-negative.
  • scale โ€” float or array_like of floats, optional. The scale of the gamma distribution. Must be non-negative. Default is equal to 1.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if shape and scale are both scalars. Otherwise, np.broadcast(shape, scale).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized gamma distribution.
  • scipy.stats.gamma โ€” probability density function, distribution or cumulative density function, etc.
  • Generator.gamma: which should be used for new code.

shape and scale, the iconic duo, > 0 only bestie, keep them non-negative or she will NOT play nice ๐ŸŒธ

The probability density for the Gamma distribution is

p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},

where k is the shape and \theta the scale, and \Gamma is the Gamma function.

The Gamma distribution is often used to model the times to failure of electronic components, and arises naturally in processes for which the waiting times between Poisson distributed events are relevant.

  1. Weisstein, Eric W. "Gamma Distribution." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/GammaDistribution.html
  2. Wikipedia, "Gamma distribution", https://en.wikipedia.org/wiki/Gamma_distribution

Draw samples from the distribution:

>>> shape, scale = 2., 2.  # mean=4, std=2*sqrt(2)
>>> s = np.random.gamma(shape, scale, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> import scipy.special as sps
>>> count, bins, ignored = plt.hist(s, 50, density=True)
>>> y = bins**(shape-1)*(np.exp(-bins/scale) /
...                      (sps.gamma(shape)*scale**shape))
>>> plt.plot(bins, y, linewidth=2, color='r')
>>> plt.show()

XRStools.xrs_calctools.gauss(x, x0, fwhm)

XRStools.xrs_calctools.gauss1(x, x0, fwhm)

returns a gaussian with peak value normalized to unity a[0] = peak position, a[1] = Full Width at Half Maximum.

XRStools.xrs_calctools.gauss_areanorm(x, x0, fwhm)

area-normalized gaussian ๐Ÿ’…

XRStools.xrs_calctools.geometric(p, size=None)

Draw samples from the geometric distribution, bestie. โœจ

Bernoulli trials are experiments with one of two outcomes: success or failure (an example of such an experiment is flipping a coin). The geometric distribution models the number of trials that must be run in order to achieve success. It is therefore supported on the positive integers, k = 1, 2, ....

The probability mass function of the geometric distribution is

f(k) = (1 - p)^{k - 1} p

where p is the probability of success of an individual trial.

NOTE: New code should use the geometric method of a default_rng() instance instead; please see the random-quick-start.
  • p โ€” float or array_like of floats โ€” the probability of success of an individual trial.
  • size โ€” int or tuple of ints, optional โ€” output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if p is a scalar. Otherwise, np.array(p).size samples are drawn.
  • out โ€” ndarray or scalar โ€” drawn samples from the parameterized geometric distribution.

Generator.geometric: which should be used for new code. ๐Ÿ‘‘

Draw ten thousand values from the geometric distribution, with the probability of an individual success equal to 0.35:

>>> z = np.random.geometric(p=0.35, size=10000)

How many trials succeeded after a single run?

>>> (z == 1).sum() / 10000.
0.34889999999999999 #random

XRStools.xrs_calctools.getDistVector(atom1, atom2)

XRStools.xrs_calctools.getDistVectorPBC_arb(atom1, atom2, lattice, lattice_inv)

getDistVectorPBC_arb ๐Ÿฆ‹

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).

XRStools.xrs_calctools.getDistVectorPbc(atom1, atom2, boxLength)

XRStools.xrs_calctools.getDistance(atom1, atom2)

XRStools.xrs_calctools.getDistancePBC_arb(atom1, atom2, lattice, lattice_inv)

getDistancePBC_arb โœจ

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.

Returns: the distance between the two atoms. ๐Ÿซถ

XRStools.xrs_calctools.getDistancePbc(atom1, atom2, boxLength)

XRStools.xrs_calctools.getDistsFromMolecule(point, listOfMolecules, o_name=None)

XRStools.xrs_calctools.getPeriodicTestBox(xyzAtoms, boxLength, numbershells=1)

XRStools.xrs_calctools.getPeriodicTestBox_arb(xyzAtoms, lattice, lattice_inv, lx=[- 1, 1], ly=[- 1, 1], lz=[- 1, 1])

XRStools.xrs_calctools.getPeriodicTestBox_molecules(Molecules, boxLength, numbershells=1)

XRStools.xrs_calctools.getTetraParameter(o_atoms, boxLength=None)

according to NATURE, VOL 409, 18 JANUARY 2001 ๐ŸŒธ

XRStools.xrs_calctools.getTranslVec(atom1, atom2, boxLength)

getTranslVec returns the translation vector that brings atom2 closer to atom1 in case atom2 is further than boxLength away.

XRStools.xrs_calctools.getTranslVec_geocen(mol1COM, mol2COM, boxLength)

getTranslVec_geocen ๐Ÿ’ซ

XRStools.xrs_calctools.get_state()

Return a tuple representing the internal state of the generator.

For more details, see set_state.

  • legacy โ€” bool, optional โ€” flag indicating to return a legacy tuple state when the BitGenerator is MT19937, instead of a dict.
  • out โ€” {tuple(str, ndarray of 624 uints, int, int, float), dict} โ€” the returned tuple has the following items:
    1. the string 'MT19937'.
    2. a 1-D array of 624 unsigned integer keys.
    3. an integer pos.
    4. an integer has_gauss.
    5. a float cached_gaussian.

If legacy is False, or the BitGenerator is not MT19937, then state is returned as a dictionary.

set_state

set_state and get_state are not needed to work with any of the random distributions in NumPy. If the internal state is manually altered, the user should know exactly what he/she is doing. ๐Ÿ˜ญ no cap, pls be careful.

XRStools.xrs_calctools.groBoxParser(filename, nanoMeter=True)

groBoxParser parses an gromacs GRO-style file for the xyzBox class. ๐Ÿ“

XRStools.xrs_calctools.groTrajecParser(filename, nanoMeter=True)

groTrajecParser parses an gromacs GRO-style file for the xyzBox class.

XRStools.xrs_calctools.gumbel(loc=0.0, scale=1.0, size=None)

Draw samples from a Gumbel distribution. โœจ

Draw samples from a Gumbel distribution with specified location and scale. For more information on the Gumbel distribution, see Notes and References below.

NOTE: New code should use the gumbel method of a default_rng() instance instead; please see the random-quick-start.
  • loc โ€” float or array_like of floats, optional โ€” the location of the mode of the distribution. Default is 0.
  • scale โ€” float or array_like of floats, optional โ€” the scale parameter of the distribution. Default is 1. Must be non-negative.
  • size โ€” int or tuple of ints, optional โ€” output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn.
  • out โ€” ndarray or scalar โ€” drawn samples from the parameterized Gumbel distribution.

scipy.stats.gumbel_l scipy.stats.gumbel_r scipy.stats.genextreme weibull Generator.gumbel: which should be used for new code. ๐Ÿ‘‘

The Gumbel (or Smallest Extreme Value (SEV) or the Smallest Extreme Value Type I) distribution is one of a class of Generalized Extreme Value (GEV) distributions used in modeling extreme value problems. The Gumbel is a special case of the Extreme Value Type I distribution for maximums from distributions with "exponential-like" tails.

The probability density for the Gumbel distribution is

 p(x) = \frac{e^{-(x - \mu)/ \beta}}{\beta} e^{ -e^{-(x - \mu)/
\beta}},

where \mu is the mode, a location parameter, and \beta is the scale parameter.

The Gumbel (named for German mathematician Emil Julius Gumbel) was used very early in the hydrology literature, for modeling the occurrence of flood events. It is also used for modeling maximum wind speed and rainfall rates. It is a "fat-tailed" distribution - the probability of an event in the tail of the distribution is larger than if one used a Gaussian, hence the surprisingly frequent occurrence of 100-year floods. Floods were initially modeled as a Gaussian process, which underestimated the frequency of extreme events.

It is one of a class of extreme value distributions, the Generalized Extreme Value (GEV) distributions, which also includes the Weibull and Frechet.

The function has a mean of \mu + 0.57721\beta and a variance of \frac{\pi^2}{6}\beta^2.

  1. Gumbel, E. J., "Statistics of Extremes," New York: Columbia University Press, 1958.
  2. Reiss, R.-D. and Thomas, M., "Statistical Analysis of Extreme Values from Insurance, Finance, Hydrology and Other Fields," Basel: Birkhauser Verlag, 2001.

Draw samples from the distribution:

>>> mu, beta = 0, 0.1 # location and scale
>>> s = np.random.gumbel(mu, beta, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)
...          * np.exp( -np.exp( -(bins - mu) /beta) ),
...          linewidth=2, color='r')
>>> plt.show()

Show how an extreme value distribution can arise from a Gaussian process and compare to a Gaussian:

>>> means = []
>>> maxima = []
>>> for i in range(0,1000) :
...    a = np.random.normal(mu, beta, 1000)
...    means.append(a.mean())
...    maxima.append(a.max())
>>> count, bins, ignored = plt.hist(maxima, 30, density=True)
>>> beta = np.std(maxima) * np.sqrt(6) / np.pi
>>> mu = np.mean(maxima) - 0.57721*beta
>>> plt.plot(bins, (1/beta)*np.exp(-(bins - mu)/beta)
...          * np.exp(-np.exp(-(bins - mu)/beta)),
...          linewidth=2, color='r')
>>> plt.plot(bins, 1/(beta * np.sqrt(2 * np.pi))
...          * np.exp(-(bins - mu)**2 / (2 * beta**2)),
...          linewidth=2, color='g')
>>> plt.show()

๐ŸŒธ XRStools.xrs_calctools.hypergeometric(ngood, nbad, nsample, size=None)

okay so this one draws samples from a Hypergeometric distribution. ๐Ÿ’–

Samples are drawn from a hypergeometric distribution with specified parameters, ngood (ways to make a good selection), nbad (ways to make a bad selection), and nsample (number of items sampled, which is less than or equal to the sum ngood + nbad).

NOTE: ๐Ÿซถ New code should use the hypergeometric method of a default_rng() instance instead; please see the random-quick-start.

Parameters, bestie โ€” every single one: ๐Ÿ‘‘

  • ngood โ€” int or array_like of ints. Number of ways to make a good selection. Must be nonnegative.
  • nbad โ€” int or array_like of ints. Number of ways to make a bad selection. Must be nonnegative.
  • nsample โ€” int or array_like of ints. Number of items sampled. Must be at least 1 and at most ngood + nbad.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if ngood, nbad, and nsample are all scalars. Otherwise, np.broadcast(ngood, nbad, nsample).size samples are drawn.

Returns:

  • out โ€” ndarray or scalar. Drawn samples from the parameterized hypergeometric distribution. Each sample is the number of good items within a randomly selected subset of size nsample taken from a set of ngood good items and nbad bad items.

See Also โœจ

  • scipy.stats.hypergeom โ€” probability density function, distribution or cumulative density function, etc.
  • Generator.hypergeometric โ€” which should be used for new code.

Notes ๐Ÿฆ‹

The probability density for the Hypergeometric distribution is

P(x) = \frac{\binom{g}{x}\binom{b}{n-x}}{\binom{g+b}{n}},

where 0 \le x \le n and n-b \le x \le g

for P(x) the probability of x good results in the drawn sample, g = ngood, b = nbad, and n = nsample.

Picture it: consider an urn with black and white marbles in it, ngood of them are black and nbad are white. If you draw nsample balls without replacement, then the hypergeometric distribution describes the distribution of black balls in the drawn sample. ๐ŸŽ€

Note that this distribution is very similar to the binomial distribution, except that in this case, samples are drawn without replacement, whereas in the Binomial case samples are drawn with replacement (or the sample space is infinite). As the sample space becomes large, this distribution approaches the binomial. ๐Ÿ’…

References ๐Ÿ“š

Examples ๐ŸŒˆ

Draw samples from the distribution:

>>> ngood, nbad, nsamp = 100, 2, 10
# number of good, number of bad, and number of samples
>>> s = np.random.hypergeometric(ngood, nbad, nsamp, 1000)
>>> from matplotlib.pyplot import hist
>>> hist(s)
#   note that it is very unlikely to grab both bad items

Suppose you have an urn with 15 white and 15 black marbles. If you pull 15 marbles at random, how likely is it that 12 or more of them are one color?

>>> s = np.random.hypergeometric(15, 15, 15, 100000)
>>> sum(s>=12)/100000. + sum(s<=3)/100000.
#   answer = 0.003 ... pretty unlikely!

๐Ÿ“ XRStools.xrs_calctools.keithBoxParser(cell_fname, coord_fname)

keithBoxParser

Reads structure files from Keith's SiO2 simulations. ๐Ÿ’– That's it, that's the whole vibe. Short and iconic.


โญ XRStools.xrs_calctools.laplace(loc=0.0, scale=1.0, size=None)

Draw samples from the Laplace or double exponential distribution with specified location (or mean) and scale (decay). ๐Ÿ˜ญ it's giving peaky.

The Laplace distribution is similar to the Gaussian/normal distribution, but it's sharper at the peak and has fatter tails. It represents the difference between two independent, identically distributed exponential random variables. no cap.

NOTE: ๐Ÿซถ New code should use the laplace method of a default_rng() instance instead; please see the random-quick-start.

Parameters ๐Ÿ’…

  • loc โ€” float or array_like of floats, optional. The position, \mu, of the distribution peak. Default is 0.
  • scale โ€” float or array_like of floats, optional. \lambda, the exponential decay. Default is 1. Must be non-negative.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn.

Returns:

  • out โ€” ndarray or scalar. Drawn samples from the parameterized Laplace distribution.

See Also โœจ

  • Generator.laplace โ€” which should be used for new code.

Notes ๐Ÿฆ‹

It has the probability density function

f(x; \mu, \lambda) = \frac{1}{2\lambda} \exp\left(-\frac{|x - \mu|}{\lambda}\right).

The first law of Laplace, from 1774, states that the frequency of an error can be expressed as an exponential function of the absolute magnitude of the error, which leads to the Laplace distribution. For many problems in economics and health sciences, this distribution seems to model the data better than the standard Gaussian distribution. slay, honestly.

References ๐Ÿ“š

Examples ๐ŸŒˆ

Draw samples from the distribution

>>> loc, scale = 0., 1.
>>> s = np.random.laplace(loc, scale, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> x = np.arange(-8., 8., .01)
>>> pdf = np.exp(-abs(x-loc)/scale)/(2.*scale)
>>> plt.plot(x, pdf)

Plot Gaussian for comparison:

>>> g = (1/(scale * np.sqrt(2 * np.pi)) *
...      np.exp(-(x - loc)**2 / (2 * scale**2)))
>>> plt.plot(x,g)

๐Ÿงš XRStools.xrs_calctools.load_erkale_spec(filename)

returns an erkale spectrum โœจ (yes, that's the whole description, and honestly? we love an efficient queen.)


๐Ÿ’œ XRStools.xrs_calctools.load_erkale_specs(prefix, postfix, fromnumber, tonumber, step, stepformat=2)

returns a list of erkale spectra ๐Ÿ’–


๐ŸŽ€ XRStools.xrs_calctools.load_stobe_specs(prefix, postfix, fromnumber, tonumber, step, stepformat=2)

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') ๐ŸŒธ


๐Ÿ‘‘ XRStools.xrs_calctools.logistic(loc=0.0, scale=1.0, size=None)

Draw samples from a logistic distribution. ๐Ÿ’…

Samples are drawn from a logistic distribution with specified parameters, loc (location or mean, also median), and scale (>0).

NOTE: ๐Ÿซถ New code should use the logistic method of a default_rng() instance instead; please see the random-quick-start.

Parameters ๐Ÿฆ‹

  • loc โ€” float or array_like of floats, optional. Parameter of the distribution. Default is 0.
  • scale โ€” float or array_like of floats, optional. Parameter of the distribution. Must be non-negative. Default is 1.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn.

Returns:

  • out โ€” ndarray or scalar. Drawn samples from the parameterized logistic distribution.

See Also โœจ

  • scipy.stats.logistic โ€” probability density function, distribution or cumulative density function, etc.
  • Generator.logistic โ€” which should be used for new code.

Notes ๐Ÿ“

The probability density for the Logistic distribution is

P(x) = P(x) = \frac{e^{-(x-\mu)/s}}{s(1+e^{-(x-\mu)/s})^2},

where \mu = location and s = scale.

The Logistic distribution is used in Extreme Value problems where it can act as a mixture of Gumbel distributions, in Epidemiology, and by the World Chess Federation (FIDE) where it is used in the Elo ranking system, assuming the performance of each player is a logistically distributed random variable. chess girlies, this one's for you โ™Ÿ๏ธ

References ๐Ÿ“š

Examples ๐ŸŒˆ

Draw samples from the distribution:

>>> loc, scale = 10, 1
>>> s = np.random.logistic(loc, scale, 10000)
>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, bins=50)

#   plot against distribution

>>> def logist(x, loc, scale):
...     return np.exp((loc-x)/scale)/(scale*(1+np.exp((loc-x)/scale))**2)
>>> lgst_val = logist(bins, loc, scale)
>>> plt.plot(bins, lgst_val * count.max() / lgst_val.max())
>>> plt.show()

and that's the plot-vs-distribution moment, bestie, we love a good overlay ๐Ÿ’–


XRStools.xrs_calctools.lognormal(mean=0.0, sigma=1.0, size=None)

Draw samples from a log-normal distribution. โœจ

So you're pulling samples from a log-normal distribution, and you get to pick the mean, the standard deviation, and the array shape. BIG heads up tho: the mean and standard deviation are not the values of the distribution itself โ€” they're the values of the underlying normal distribution that it's derived from. okay? okay. ๐Ÿซถ

NOTE: New code should use the lognormal method of a default_rng() instance instead; please see the random-quick-start.
  • mean โ€” float or array_like of floats, optional. Mean value of the underlying normal distribution. Default is 0.
  • sigma โ€” float or array_like of floats, optional. Standard deviation of the underlying normal distribution. Must be non-negative. Default is 1.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if mean and sigma are both scalars. Otherwise, np.broadcast(mean, sigma).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized log-normal distribution.
  • scipy.stats.lognorm โ€” probability density function, distribution, cumulative density function, etc.
  • Generator.lognormal: which should be used for new code.

okay so a variable x has a log-normal distribution if log(x) is normally distributed. the probability density function for the log-normal distribution is:

              p(x) = \frac{1}{\sigma x \sqrt{2\pi}}
e^{(-\frac{(ln(x)-\mu)^2}{2\sigma^2})}

where \mu is the mean and \sigma is the standard deviation of the normally distributed logarithm of the variable. A log-normal distribution results if a random variable is the product of a large number of independent, identically-distributed variables โ€” in the same way that a normal distribution results if the variable is the sum of a large number of independent, identically-distributed variables. it's giving "multiplication is just fancy addition" energy fr fr ๐ŸŒธ

  1. Limpert, E., Stahel, W. A., and Abbt, M., "Log-normal Distributions across the Sciences: Keys and Clues," BioScience, Vol. 51, No. 5, May, 2001. https://stat.ethz.ch/~stahel/lognormal/bioscience.pdf
  2. Reiss, R.D. and Thomas, M., "Statistical Analysis of Extreme Values," Basel: Birkhauser Verlag, 2001, pp. 31-32.

Draw samples from the distribution:

>>> mu, sigma = 3., 1. # mean and standard deviation
>>> s = np.random.lognormal(mu, sigma, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 100, density=True, align='mid')

>>> x = np.linspace(min(bins), max(bins), 10000)
>>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))
...        / (x * sigma * np.sqrt(2 * np.pi)))

>>> plt.plot(x, pdf, linewidth=2, color='r')
>>> plt.axis('tight')
>>> plt.show()

Demonstrate that taking the products of random samples from a uniform distribution can be fit well by a log-normal probability density function.

>>> # Generate a thousand samples: each is the product of 100 random
>>> # values, drawn from a normal distribution.
>>> b = []
>>> for i in range(1000):
...    a = 10. + np.random.standard_normal(100)
...    b.append(np.product(a))

>>> b = np.array(b) / np.min(b) # scale values to be positive
>>> count, bins, ignored = plt.hist(b, 100, density=True, align='mid')
>>> sigma = np.std(np.log(b))
>>> mu = np.mean(np.log(b))

>>> x = np.linspace(min(bins), max(bins), 10000)
>>> pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2))
...        / (x * sigma * np.sqrt(2 * np.pi)))

>>> plt.plot(x, pdf, color='r', linewidth=2)
>>> plt.show()

XRStools.xrs_calctools.logseries(p, size=None)

Draw samples from a logarithmic series distribution. ๐Ÿฆ‹

Samples are drawn from a log series distribution with a specified shape parameter, 0 < p < 1.

NOTE: New code should use the logseries method of a default_rng() instance instead; please see the random-quick-start.
  • p โ€” float or array_like of floats. Shape parameter for the distribution. Must be in the range (0, 1).
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if p is a scalar. Otherwise, np.array(p).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized logarithmic series distribution.
  • scipy.stats.logser โ€” probability density function, distribution or cumulative density function, etc.
  • Generator.logseries: which should be used for new code.

The probability density for the Log Series distribution is

                               P(k) = \frac{-p^k}{k \ln(1-p)},

where p = probability.

The log series distribution is frequently used to represent species richness and occurrence โ€” first proposed by Fisher, Corbet, and Williams in 1943 [2]. It may also be used to model the numbers of occupants seen in cars [3]. cars?? iconic use case actually ๐Ÿš—

  1. Buzas, Martin A.; Culver, Stephen J., Understanding regional species diversity through the log series distribution of occurrences: BIODIVERSITY RESEARCH Diversity & Distributions, Volume 5, Number 5, September 1999, pp. 187-195(9).
  2. Fisher, R.A,, A.S. Corbet, and C.B. Williams. 1943. The relation between the number of species and the number of individuals in a random sample of an animal population. Journal of Animal Ecology, 12:42-58.
  3. D. J. Hand, F. Daly, D. Lunn, E. Ostrowski, A Handbook of Small Data Sets, CRC Press, 1994.
  4. Wikipedia, "Logarithmic distribution", https://en.wikipedia.org/wiki/Logarithmic_distribution

Draw samples from the distribution:

>>> a = .6
>>> s = np.random.logseries(a, 10000)
>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s)

#   plot against distribution

>>> def logseries(k, p):
...     return -p**k/(k*np.log(1-p))
>>> plt.plot(bins, logseries(bins, a)*count.max()/
...          logseries(bins, a).max(), 'r')
>>> plt.show()

XRStools.xrs_calctools.multinomial(n, pvals, size=None)

Draw samples from a multinomial distribution. ๐ŸŽฒ

The multinomial distribution is a multivariate generalization of the binomial distribution. Take an experiment with one of p possible outcomes. An example of such an experiment is throwing a dice, where the outcome can be 1 through 6. Each sample drawn from the distribution represents n such experiments. Its values, X_i = [X_0, X_1, ..., X_p], represent the number of times the outcome was i.

NOTE: New code should use the multinomial method of a default_rng() instance instead; please see the random-quick-start.
  • n โ€” int. Number of experiments.
  • pvals โ€” sequence of floats, length p. Probabilities of each of the p different outcomes. These must sum to 1 (however, the last element is always assumed to account for the remaining probability, as long as sum(pvals[:-1]) <= 1).
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
  • out โ€” ndarray. The drawn samples, of shape size, if that was provided. If not, the shape is (N,).

In other words, each entry out[i,j,...,:] is an N-dimensional value drawn from the distribution.

  • Generator.multinomial: which should be used for new code.

Throw a dice 20 times:

>>> np.random.multinomial(20, [1/6.]*6, size=1)
array([[4, 1, 7, 5, 2, 1]]) # random

It landed 4 times on 1, once on 2, etc. ๐Ÿ‘‘

Now, throw the dice 20 times, and 20 times again:

>>> np.random.multinomial(20, [1/6.]*6, size=2)
array([[3, 4, 3, 3, 4, 3], # random
       [2, 4, 3, 4, 0, 7]])

For the first run, we threw 3 times 1, 4 times 2, etc. For the second, we threw 2 times 1, 4 times 2, etc.

A loaded die is more likely to land on number 6:

>>> np.random.multinomial(100, [1/7.]*5 + [2/7.])
array([11, 16, 14, 17, 16, 26]) # random

The probability inputs should be normalized. As an implementation detail, the value of the last entry is ignored and assumed to take up any leftover probability mass, but this should not be relied on. A biased coin which has twice as much weight on one side as on the other should be sampled like so:

>>> np.random.multinomial(100, [1.0 / 3, 2.0 / 3])  # RIGHT
array([38, 62]) # random

not like:

>>> np.random.multinomial(100, [1.0, 2.0])  # WRONG
Traceback (most recent call last):
ValueError: pvals < 0, pvals > 1 or pvals contains NaNs
bestie the # WRONG comment is not a suggestion ๐Ÿ’€ normalize your pvals, it's literally free

XRStools.xrs_calctools.multivariate_normal(mean, cov, size=None, check_valid='warn', tol=1e-8)

Draw random samples from a multivariate normal distribution. ๐ŸŒˆ

The multivariate normal, multinormal or Gaussian distribution is a generalization of the one-dimensional normal distribution to higher dimensions. Such a distribution is specified by its mean and covariance matrix. These parameters are analogous to the mean (average or "center") and variance (standard deviation, or "width," squared) of the one-dimensional normal distribution.

it's the 1D normal but make it multidimensional, main character energy โœจ

โš ๏ธ NOTE: New code should totally use the multivariate_normal method of a default_rng() instance instead, bestie; please see the random-quick-start. ๐Ÿ’…
  • mean โ€” 1-D array_like, of length N. It's the mean of the N-dimensional distribution, like the vibe center. โœจ
  • cov โ€” 2-D array_like, of shape (N, N). This is the covariance matrix of the distribution. It has to be symmetric and positive-semidefinite for proper sampling, no cap. ๐Ÿฆ‹
  • size โ€” int or tuple of ints, optional. Given a shape of, for example, (m,n,k), m*n*k samples are generated, and packed in an m-by-n-by-k arrangement. Because each sample is N-dimensional, the output shape is (m,n,k,N). If no shape is specified, a single (N-D) sample is returned. ๐ŸŽ€
  • check_valid โ€” { 'warn', 'raise', 'ignore' }, optional. Behavior when the covariance matrix is not positive semidefinite. ๐Ÿ’…
  • tol โ€” float, optional. Tolerance when checking the singular values in covariance matrix. cov is cast to double before the check. ๐ŸŒธ
  • out โ€” ndarray. The drawn samples, of shape size, if that was provided. If not, the shape is (N,). In other words, each entry out[i,j,...,:] is an N-dimensional value drawn from the distribution. ๐Ÿ‘‘

Generator.multivariate_normal: which should be used for new code. ๐Ÿ’–

The mean is a coordinate in N-dimensional space, which represents the location where samples are most likely to be generated. This is analogous to the peak of the bell curve for the one-dimensional or univariate normal distribution. ๐Ÿ””

Covariance indicates the level to which two variables vary together. From the multivariate normal distribution, we draw N-dimensional samples, X = [x_1, x_2, ... x_N]. The covariance matrix element C_{ij} is the covariance of x_i and x_j. The element C_{ii} is the variance of x_i (i.e. its "spread"). ๐Ÿ“Š

Instead of specifying the full covariance matrix, popular approximations include:

  • Spherical covariance (cov is a multiple of the identity matrix)
  • Diagonal covariance (cov has non-negative elements, and only on the diagonal)

This geometrical property can be seen in two dimensions by plotting generated data-points:

>>> mean = [0, 0]
>>> cov = [[1, 0], [0, 100]]  # diagonal covariance

Diagonal covariance means that points are oriented along x or y-axis:

>>> import matplotlib.pyplot as plt
>>> x, y = np.random.multivariate_normal(mean, cov, 5000).T
>>> plt.plot(x, y, 'x')
>>> plt.axis('equal')
>>> plt.show()

Note that the covariance matrix must be positive semidefinite (a.k.a. nonnegative-definite). Otherwise, the behavior of this method is undefined and backwards compatibility is not guaranteed. โš ๏ธ

  • [1] Papoulis, A., "Probability, Random Variables, and Stochastic Processes," 3rd ed., New York: McGraw-Hill, 1991.
  • [2] Duda, R. O., Hart, P. E., and Stork, D. G., "Pattern Classification," 2nd ed., New York: Wiley, 2001.
>>> mean = (1, 2)
>>> cov = [[1, 0], [0, 1]]
>>> x = np.random.multivariate_normal(mean, cov, (3, 3))
>>> x.shape
(3, 3, 2)

The following is probably true, given that 0.6 is roughly twice the standard deviation:

>>> list((x[0,0,:] - mean) < 0.6)
[True, True] # random

๐ŸŒˆ XRStools.xrs_calctools.negative_binomial(n, p, size=None) ๐ŸŒˆ

Draw samples from a negative binomial distribution. ๐ŸŽฒ

Samples are drawn from a negative binomial distribution with specified parameters, n successes and p probability of success where n is > 0 and p is in the interval [0, 1]. โœจ

โš ๏ธ NOTE: New code should use the negative_binomial method of a default_rng() instance instead; please see the random-quick-start. ๐Ÿ’…
  • n โ€” float or array_like of floats. Parameter of the distribution, > 0. ๐Ÿ”ข
  • p โ€” float or array_like of floats. Parameter of the distribution, >= 0 and <=1. ๐ŸŽฏ
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if n and p are both scalars. Otherwise, np.broadcast(n, p).size samples are drawn. ๐Ÿ“ฆ
  • out โ€” ndarray or scalar. Drawn samples from the parameterized negative binomial distribution, where each sample is equal to N, the number of failures that occurred before a total of n successes was reached. ๐ŸŽ

Generator.negative_binomial: which should be used for new code. ๐Ÿ’–

The probability mass function of the negative binomial distribution is

P(N;n,p) = \frac{\Gamma(N+n)}{N!\Gamma(n)}p^{n}(1-p)^{N},

where n is the number of successes, p is the probability of success, N+n is the number of trials, and \Gamma is the gamma function. When n is an integer, \frac{\Gamma(N+n)}{N!\Gamma(n)} = \binom{N+n-1}{N}, which is the more common form of this term in the the pmf. The negative binomial distribution gives the probability of N failures given n successes, with a success on the last trial. ๐Ÿ“ˆ

If one throws a die repeatedly until the third time a "1" appears, then the probability distribution of the number of non-"1"s that appear before the third "1" is a negative binomial distribution. ๐ŸŽฒ

Draw samples from the distribution:

A real world example. A company drills wild-cat oil exploration wells, each with an estimated probability of success of 0.1. What is the probability of having one success for each successive well, that is what is the probability of a single success after drilling 5 wells, after 6 wells, etc.?

>>> s = np.random.negative_binomial(1, 0.1, 100000)
>>> for i in range(1, 11):
...    probability = sum(s<i) / 100000.
...    print(i, "wells drilled, probability of one success =", probability)

๐ŸŒˆ XRStools.xrs_calctools.noncentral_chisquare(df, nonc, size=None) ๐ŸŒˆ

Draw samples from a noncentral chi-square distribution. ๐ŸŽฒ

The noncentral \chi^2 distribution is a generalization of the \chi^2 distribution. โœจ

โš ๏ธ NOTE: New code should use the noncentral_chisquare method of a default_rng() instance instead; please see the random-quick-start. ๐Ÿ’…
  • df โ€” float or array_like of floats. Degrees of freedom, must be > 0. ๐Ÿ“Š Changed in version 1.10.0: Earlier NumPy versions required dfnum > 1. ๐Ÿ•ฐ๏ธ
  • nonc โ€” float or array_like of floats. Non-centrality, must be non-negative. โž•
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if df and nonc are both scalars. Otherwise, np.broadcast(df, nonc).size samples are drawn. ๐Ÿ“ฆ
  • out โ€” ndarray or scalar. Drawn samples from the parameterized noncentral chi-square distribution. ๐ŸŽ

Generator.noncentral_chisquare: which should be used for new code. ๐Ÿ’–

The probability density function for the noncentral Chi-square distribution is

P(x;df,nonc) = \sum^{\infty}_{i=0} \frac{e^{-nonc/2}(nonc/2)^{i}}{i!} P_{Y_{df+2i}}(x),

where Y_{q} is the Chi-square with q degrees of freedom. ๐Ÿ“ˆ

Draw values from the distribution and plot the histogram

>>> import matplotlib.pyplot as plt
>>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),
...                   bins=200, density=True)
>>> plt.show()

Draw values from a noncentral chisquare with very small noncentrality, and compare to a chisquare.

>>> plt.figure()
>>> values = plt.hist(np.random.noncentral_chisquare(3, .0000001, 100000),
...                   bins=np.arange(0., 25, .1), density=True)
>>> values2 = plt.hist(np.random.chisquare(3, 100000),
...                    bins=np.arange(0., 25, .1), density=True)
>>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob')
>>> plt.show()

Demonstrate how large values of non-centrality lead to a more symmetric distribution.

>>> plt.figure()
>>> values = plt.hist(np.random.noncentral_chisquare(3, 20, 100000),
...                   bins=200, density=True)
>>> plt.show()

๐ŸŒˆ XRStools.xrs_calctools.noncentral_f(dfnum, dfden, nonc, size=None) ๐ŸŒˆ

Draw samples from the noncentral F distribution. ๐ŸŽฒ

Samples are drawn from an F distribution with specified parameters, dfnum (degrees of freedom in numerator) and dfden (degrees of freedom in denominator), where both parameters > 1. nonc is the non-centrality parameter. โœจ

โš ๏ธ NOTE: New code should use the noncentral_f method of a default_rng() instance instead; please see the random-quick-start. ๐Ÿ’…
  • dfnum โ€” float or array_like of floats. Numerator degrees of freedom, must be > 0. ๐Ÿ“Š Changed in version 1.14.0: Earlier NumPy versions required dfnum > 1. ๐Ÿ•ฐ๏ธ
  • dfden โ€” float or array_like of floats. Denominator degrees of freedom, must be > 0. ๐Ÿ“‰
  • nonc โ€” float or array_like of floats. Non-centrality parameter, the sum of the squares of the numerator means, must be >= 0. โž•
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if dfnum, dfden, and nonc are all scalars. Otherwise, np.broadcast(dfnum, dfden, nonc).size samples are drawn. ๐Ÿ“ฆ
  • out โ€” ndarray or scalar. Drawn samples from the parameterized noncentral Fisher distribution. ๐Ÿ’–

Generator.noncentral_f: bestie, this is the one you should be using for new code. periodt.

Okay so why do we even care? When you're calculating the power of an experiment (power = probability of rejecting the null hypothesis when a specific alternative is true), the non-central F statistic becomes important. When the null hypothesis is true, the F statistic follows a central F distribution. When the null hypothesis is not true, then it follows a non-central F statistic. โœจ


In a study, testing for a specific alternative to the null hypothesis requires use of the Noncentral F distribution. We need to calculate the area in the tail of the distribution that exceeds the value of the F distribution for the null hypothesis. We'll plot the two probability distributions for comparison. ๐Ÿซถ

>>> dfnum = 3 # between group deg of freedom
>>> dfden = 20 # within groups degrees of freedom
>>> nonc = 3.0
>>> nc_vals = np.random.noncentral_f(dfnum, dfden, nonc, 1000000)
>>> NF = np.histogram(nc_vals, bins=50, density=True)
>>> c_vals = np.random.f(dfnum, dfden, 1000000)
>>> F = np.histogram(c_vals, bins=50, density=True)
>>> import matplotlib.pyplot as plt
>>> plt.plot(F[1][1:], F[0])
>>> plt.plot(NF[1][1:], NF[0])
>>> plt.show()

๐ŸŒธ XRStools.xrs_calctools.normal(loc=0.0, scale=1.0, size=None)

Draw random samples from a normal (Gaussian) distribution. the blueprint fr fr ๐Ÿ’…

The probability density function of the normal distribution, first derived by De Moivre and 200 years later by both Gauss and Laplace independently [2]_ , is often called the bell curve because of its characteristic shape (see the example below). iconic behavior honestly.

The normal distributions occurs often in nature. For example, it describes the commonly occurring distribution of samples influenced by a large number of tiny, random disturbances, each with its own unique distribution [2]_ . ๐Ÿฆ‹

NOTE: New code should use the normal method of a default_rng() instance instead; please see the random-quick-start.
  • loc โ€” float or array_like of floats. Mean ("centre") of the distribution. ๐ŸŽฏ
  • scale โ€” float or array_like of floats. Standard deviation (spread or "width") of the distribution. Must be non-negative.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if loc and scale are both scalars. Otherwise, np.broadcast(loc, scale).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized normal distribution.
  • scipy.stats.norm โ€” probability density function, distribution or cumulative density function, etc. ๐Ÿ’œ
  • Generator.normal: which should be used for new code.

The probability density for the Gaussian distribution is

            p(x) = \frac{1}{\sqrt{ 2 \pi \sigma^2 }}
e^{ - \frac{ (x - \mu)^2 } {2 \sigma^2} },

where \mu is the mean and \sigma the standard deviation. The square of the standard deviation, \sigma^2, is called the variance. โœจ

The function has its peak at the mean, and its "spread" increases with the standard deviation (the function reaches 0.607 times its maximum at x + \sigma and x - \sigma [2]_ ). This implies that normal is more likely to return samples lying close to the mean, rather than those far away. lowkey makes sense bestie.

  • [1] โ€” Wikipedia, "Normal distribution", https://en.wikipedia.org/wiki/Normal_distribution
  • [2] โ€” P. R. Peebles Jr., "Central Limit Theorem" in "Probability, Random Variables and Random Signal Principles", 4th ed., 2001, pp. 51, 51, 125.

Draw samples from the distribution:

>>> mu, sigma = 0, 0.1 # mean and standard deviation
>>> s = np.random.normal(mu, sigma, 1000)

Verify the mean and the variance:

>>> abs(mu - np.mean(s))
0.0  # may vary

>>> abs(sigma - np.std(s, ddof=1))
0.1  # may vary

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 30, density=True)
>>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
...                np.exp( - (bins - mu)**2 / (2 * sigma**2) ),
...          linewidth=2, color='r')
>>> plt.show()

Two-by-four array of samples from N(3, 6.25):

>>> np.random.normal(3, 2.5, size=(2, 4))
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   # random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  # random

๐ŸŽ€ XRStools.xrs_calctools.pareto(a, size=None)

Draw samples from a Pareto II or Lomax distribution with specified shape. we love a distribution with lore ๐Ÿ’…

The Lomax or Pareto II distribution is a shifted Pareto distribution. The classical Pareto distribution can be obtained from the Lomax distribution by adding 1 and multiplying by the scale parameter m (see Notes). The smallest value of the Lomax distribution is zero while for the classical Pareto distribution it is mu, where the standard Pareto distribution has location mu = 1. Lomax can also be considered as a simplified version of the Generalized Pareto distribution (available in SciPy), with the scale set to one and the location set to zero.

The Pareto distribution must be greater than zero, and is unbounded above. It is also known as the "80-20 rule". In this distribution, 80 percent of the weights are in the lowest 20 percent of the range, while the other 20 percent fill the remaining 80 percent of the range. the way that math just works ๐Ÿ˜ญ

NOTE: New code should use the pareto method of a default_rng() instance instead; please see the random-quick-start.
  • a โ€” float or array_like of floats. Shape of the distribution. Must be positive.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if a is a scalar. Otherwise, np.array(a).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized Pareto distribution.
  • scipy.stats.lomax โ€” probability density function, distribution or cumulative density function, etc. ๐ŸŒธ
  • scipy.stats.genpareto โ€” probability density function, distribution or cumulative density function, etc. ๐ŸŒธ
  • Generator.pareto: which should be used for new code.

The probability density for the Pareto distribution is

                                 p(x) = \frac{am^a}{x^{a+1}}

where a is the shape and m the scale.

The Pareto distribution, named after the Italian economist Vilfredo Pareto, is a power law probability distribution useful in many real world problems. Outside the field of economics it is generally referred to as the Bradford distribution. Pareto developed the distribution to describe the distribution of wealth in an economy. It has also found use in insurance, web page access statistics, oil field sizes, and many other problems, including the download frequency for projects in Sourceforge [1]_ . It is one of the so-called "fat-tailed" distributions. ๐Ÿ’€

  • [1] โ€” Francis Hunt and Paul Johnson, On the Pareto Distribution of Sourceforge projects.
  • [2] โ€” Pareto, V. (1896). Course of Political Economy. Lausanne.
  • [3] โ€” Reiss, R.D., Thomas, M.(2001), Statistical Analysis of Extreme Values, Birkhauser Verlag, Basel, pp 23-30.
  • [4] โ€” Wikipedia, "Pareto distribution", https://en.wikipedia.org/wiki/Pareto_distribution

Draw samples from the distribution:

>>> a, m = 3., 2.  # shape and mode
>>> s = (np.random.pareto(a, 1000) + 1) * m

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, _ = plt.hist(s, 100, density=True)
>>> fit = a*m**a / bins**(a+1)
>>> plt.plot(bins, max(count)*fit/max(fit), linewidth=2, color='r')
>>> plt.show()

๐Ÿงš XRStools.xrs_calctools.parseOCEANinputFile(fname)

parseOCEANinputFile

Parses an OCEAN input file and returns lattice vectors, atom names, and relative atom positions. ๐Ÿซถ

Args:

  • fname (str): Absolute filename of OCEAN input file.
  • atoms (list): List of elemental symbols in the same order as they appear in the input file.

Returns:

  • lattice (np.array): Array of lattice vectors.
  • rel_coords (np.array): Array of relative atomic coordinates.
  • oceaatoms (list): List of atomic names.

๐Ÿ“ XRStools.xrs_calctools.parsePwscfFile(fname)

parsePwscfFile

Parses a PWSCF file and returns a xyzBox object. โœจ

Args: fname (str): Absolute filename of OCEAN input file.

Returns: xyzBox object

๐ŸŒˆ XRStools.xrs_calctools.parseVaspFile(fname)

parseVaspFile

Parses a VASPS file and returns a xyzBox object. ๐Ÿ’œ

Args: fname (str): Absolute filename of VASP file.

Returns: xyzBox object

โญ XRStools.xrs_calctools.parseXYZfile(filename)

parseXYZfile Reads an xyz-style file. short and sweet, she's lowkey the low-maintenance one ๐ŸŽ€

๐Ÿ‘‘ XRStools.xrs_calctools.permutation(x)

Randomly permute a sequence, or return a permuted range. ๐Ÿ”€

If x is a multi-dimensional array, it is only shuffled along its first index.

NOTE: New code should use the permutation method of a default_rng() instance instead; please see the random-quick-start.
  • x โ€” int or array_like. If x is an integer, randomly permute np.arange(x). If x is an array, make a copy and shuffle the elements randomly. ๐Ÿ’ซ
  • out โ€” ndarray. Permuted sequence or array range.
lowkey important: Generator.permutation โ€” which should be used for new code. ๐Ÿ‘‘
>>> np.random.permutation(10)
array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6]) # random
>>> np.random.permutation([1, 4, 9, 12, 15])
array([15,  1,  9,  4, 12]) # random
>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.permutation(arr)
array([[6, 7, 8], # random
       [0, 1, 2],
       [3, 4, 5]])

๐ŸŽฒ XRStools.xrs_calctools.poisson(lam=1.0, size=None)

Draw samples from a Poisson distribution. the way this one is literally the limit of the binomial distribution for large N โ€” bestie that's not a vibe, that's math. โœจ

NOTE: New code should use the poisson method of a default_rng() instance instead; please see the random-quick-start.
  • lam โ€” float or array_like of floats. Expected number of events occurring in a fixed-time interval, must be >= 0. A sequence must be broadcastable over the requested size.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if lam is a scalar. Otherwise, np.array(lam).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized Poisson distribution. ๐Ÿซถ
also: Generator.poisson โ€” which should be used for new code.

The Poisson distribution ๐ŸŒธ

         f(k; \lambda)=\frac{\lambda^k e^{-\lambda}}{k!}

For events with an expected separation \lambda the Poisson distribution f(k; \lambda) describes the probability of k events occurring within the observed interval \lambda.

careful bestie: Because the output is limited to the range of the C int64 type, a ValueError is raised when lam is within 10 sigma of the maximum representable value. ๐Ÿ˜ญ

Draw samples from the distribution: ๐Ÿฆ‹

>>> import numpy as np
>>> s = np.random.poisson(5, 10000)

Display histogram of the sample:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 14, density=True)
>>> plt.show()

Draw each 100 values for lambda 100 and 500:

>>> s = np.random.poisson(lam=(100., 500.), size=(100, 2))

โšก XRStools.xrs_calctools.power(a, size=None)

Draws samples in [0, 1] from a power distribution with positive exponent a - 1. obsessed with this one ngl

Also known as the power function distribution. ๐Ÿ’…

NOTE: New code should use the power method of a default_rng() instance instead; please see the random-quick-start.
  • a โ€” float or array_like of floats. Parameter of the distribution. Must be non-negative.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if a is a scalar. Otherwise, np.array(a).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized power distribution. โœจ
  • ValueError โ€” If a < 1. ๐Ÿšจ
also: Generator.power โ€” which should be used for new code.

The probability density function is

             P(x; a) = ax^{a-1}, 0 \le x \le 1, a>0.

The power function distribution is just the inverse of the Pareto distribution. It may also be seen as a special case of the Beta distribution. ๐Ÿงš

It is used, for example, in modeling the over-reporting of insurance claims. insurance girlies stay winning

  • [1] Christian Kleiber, Samuel Kotz, "Statistical size distributions in economics and actuarial sciences", Wiley, 2003.
  • [2] Heckert, N. A. and Filliben, James J. "NIST Handbook 148: Dataplot Reference Manual, Volume 2: Let Subcommands and Library Functions", National Institute of Standards and Technology Handbook Series, June 2003. https://www.itl.nist.gov/div898/software/dataplot/refman2/auxillar/powpdf.pdf

Draw samples from the distribution: ๐ŸŽ€

>>> a = 5. # shape
>>> samples = 1000
>>> s = np.random.power(a, samples)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, bins=30)
>>> x = np.linspace(0, 1, 100)
>>> y = a*x**(a-1.)
>>> normed_y = samples*np.diff(bins)[0]*y
>>> plt.plot(x, normed_y)
>>> plt.show()

Compare the power function distribution to the inverse of the Pareto. ๐ŸŒˆ

>>> from scipy import stats
>>> rvs = np.random.power(5, 1000000)
>>> rvsp = np.random.pareto(5, 1000000)
>>> xx = np.linspace(0,1,100)
>>> powpdf = stats.powerlaw.pdf(xx,5)

>>> plt.figure()
>>> plt.hist(rvs, bins=50, density=True)
>>> plt.plot(xx,powpdf,'r-')
>>> plt.title('np.random.power(5)')

>>> plt.figure()
>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
>>> plt.plot(xx,powpdf,'r-')
>>> plt.title('inverse of 1 + np.random.pareto(5)')

>>> plt.figure()
>>> plt.hist(1./(1.+rvsp), bins=50, density=True)
>>> plt.plot(xx,powpdf,'r-')
>>> plt.title('inverse of stats.pareto(5)')

๐Ÿ’– XRStools.xrs_calctools.rand(d0, d1, ..., dn)

Random values in a given shape. the classic ๐Ÿ’…

NOTE: This is a convenience function for users porting code from Matlab, and wraps random_sample. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.

Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1). ๐Ÿฆ‹

  • d0, d1, ..., dn โ€” int, optional. The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
  • out โ€” ndarray, shape (d0, d1, ..., dn). Random values. โญ

See also: random

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random

๐Ÿ“ XRStools.xrs_calctools.randint(low, high=None, size=None, dtype=int)

Return random integers from low (inclusive) to high (exclusive). half-open interval girlies rise up โœจ

Return random integers from the "discrete uniform" distribution of the specified dtype in the "half-open" interval [low, high). If high is None (the default), then results are from [0, low).

NOTE: New code should use the integers method of a default_rng() instance instead; please see the random-quick-start.
  • low โ€” int or array-like of ints. Lowest (signed) integers to be drawn from the distribution (unless high=None, in which case this parameter is one above the highest such integer).
  • high โ€” int or array-like of ints, optional. If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=None). If array-like, must contain integer values.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
  • dtype โ€” dtype, optional. Desired dtype of the result. Byteorder must be native. The default value is int.

New in version 1.11.0.

  • out โ€” int or ndarray of ints. size-shaped array of random integers from the appropriate distribution, or a single such random int if size not provided. ๐ŸŽ€

See also:

  • random_integers โ€” similar to randint, only for the closed interval [low, high], and 1 is the lowest value if high is omitted.
  • Generator.integers: which should be used for new code. ๐Ÿ‘‘
>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Generate a 2 x 4 array of ints between 0 and 4, inclusive:

>>> np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1], # random
       [3, 2, 2, 0]])

Generate a 1 x 3 array with 3 different upper bounds

>>> np.random.randint(1, [3, 5, 10])
array([2, 2, 9]) # random

Generate a 1 by 3 array with 3 different lower bounds

>>> np.random.randint([1, 5, 7], 10)
array([9, 8, 7]) # random

Generate a 2 by 4 array using broadcasting with dtype of uint8

>>> np.random.randint([1, 3, 5, 7], [[10], [20]], dtype=np.uint8)
array([[ 8,  6,  9,  7], # random
       [ 1, 16,  9, 12]], dtype=uint8)

๐Ÿงš XRStools.xrs_calctools.randn(d0, d1, ..., dn)

Return a sample (or samples) from the "standard normal" distribution. the bell curve baddie ๐Ÿ””

NOTE: This is a convenience function for users porting code from Matlab, and wraps standard_normal. That function takes a tuple to specify the size of the output, which is consistent with other NumPy functions like numpy.zeros and numpy.ones.
NOTE: New code should use the standard_normal method of a default_rng() instance instead; please see the random-quick-start.

If positive int_like arguments are provided, randn generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate "normal" (Gaussian) distribution of mean 0 and variance 1. A single float randomly sampled from the distribution is returned if no argument is provided. ๐Ÿ’–

  • d0, d1, ..., dn โ€” int, optional ๐Ÿ’– these are the dimensions of the array you get back, and bestie they have to be non-negative, no exceptions. If you don't hand over any argument at all, you just get one single lonely Python float. periodt.
  • Z โ€” ndarray or float โœจ a (d0, d1, ..., dn)-shaped array of floating-point samples pulled from the standard normal distribution, or, if you gave it no parameters, just one single such float. it's giving "you get out what shape you put in".

the little see-also crew, aka the vibes check:

  • standard_normal โ€” similar, but it takes a tuple as its argument. tuple girlie behavior.
  • normal โ€” this one also accepts mu and sigma arguments, so it's the โœจfancyโœจ version.
  • Generator.standard_normal โ€” the one that should be used for new code. iykyk.

For random samples from N(\mu, \sigma^2), use:

sigma * np.random.randn(...) + mu

look at her go:

>>> np.random.randn()
2.1923875335537315  # random

and a two-by-four array of samples from N(3, 6.25):

>>> 3 + 2.5 * np.random.randn(2, 4)
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   # random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  # random

๐ŸŒธ XRStools.xrs_calctools.random(size=None) ๐ŸŒธ

Returns random floats living in the half-open interval [0.0, 1.0) ๐Ÿ’…. It's literally an alias for random_sample, and the whole point is to ease your forward-porting over to the new random API. no cap, it's the same girl in a different outfit.


๐Ÿฆ‹ XRStools.xrs_calctools.random_integers(low, high=None, size=None) ๐Ÿฆ‹

Random integers of type np.int_ sitting between low and high, inclusive. yes bestie, both ends. inclusive.

Returns random integers of type np.int_ from the "discrete uniform" distribution in the closed interval [low, high]. If high is None (that's the default, btw), then your results come from [1, low]. And heads up โ€” the np.int_ type translates to the C long integer type, so its precision is platform dependent. ๐Ÿ’€ it really said "depends where you are".

This function has been deprecated. Use randint instead.

Deprecated since version 1.11.0. so likeโ€ฆ she's retired but still showing up to the party.

  • low โ€” int the lowest (signed) integer to be drawn from the distribution (unless high=None, in which case this parameter is actually the <em>highest</em> such integer โ€” plot twist ๐ŸŽ€).
  • high โ€” int, optional if you provide it, this is the largest (signed) integer drawn from the distribution (see above for the behavior if high=None, because yes it changes everything).
  • size โ€” int or tuple of ints, optional output shape. If the shape you give is, say, (m, n, k), then m * n * k samples get drawn. Default is None, and in that case a single value comes back. just one. a single little guy.
  • out โ€” int or ndarray of ints a size-shaped array of random integers from the appropriate distribution, or a single such random int if size wasn't provided.
  • randint โ€” similar to random_integers, only it works on the half-open interval [low, high), and 0 is the lowest value when high is omitted. the difference is literally just the bracket, bestie.

To sample from N evenly spaced floating-point numbers between a and b, use:

a + (b - a) * (np.random.random_integers(N) - 1) / (N - 1.)

look:

>>> np.random.random_integers(5)
4 # random
>>> type(np.random.random_integers(5))
<class 'numpy.int64'>
>>> np.random.random_integers(5, size=(3,2))
array([[5, 4], # random
       [3, 3],
       [4, 5]])

Now choose five random numbers from the set of five evenly-spaced numbers between 0 and 2.5, inclusive โ€” that's the set {0, 5/8, 10/8, 15/8, 20/8}, for the record:

>>> 2.5 * (np.random.random_integers(5, size=(5,)) - 1) / 4.
array([ 0.625,  1.25 ,  0.625,  0.625,  2.5  ]) # random

Roll two six sided dice 1000 times and sum the results:

>>> d1 = np.random.random_integers(1, 6, 1000)
>>> d2 = np.random.random_integers(1, 6, 1000)
>>> dsums = d1 + d2

Display results as a histogram:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(dsums, 11, density=True)
>>> plt.show()

๐Ÿงš XRStools.xrs_calctools.random_sample(size=None) ๐Ÿงš

Returns random floats in the half-open interval [0.0, 1.0) โœจ.

Results come from the "continuous uniform" distribution over that stated interval. To sample Unif[a, b), b > a, multiply the output of random_sample by (b-a) and then add a:

(b - a) * random_sample() + a
NOTE: New code should use the random method of a default_rng() instance instead; please see the random-quick-start. okay so it's not that she's bad, she's just legacy-coded ๐Ÿ’…
  • size โ€” int or tuple of ints, optional output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned. one value. solitary. main character alone.
  • out โ€” float or ndarray of floats array of random floats of shape size (unless size=None, in which case a single float is returned).
  • Generator.random โ€” which should be used for new code. she's the upgrade, bestie.
>>> np.random.random_sample()
0.47108547995356098 # random
>>> type(np.random.random_sample())
<class 'float'>
>>> np.random.random_sample((5,))
array([ 0.30220482,  0.86820401,  0.1654503 ,  0.11659149,  0.54323428]) # random

A three-by-two array of random numbers from [-5, 0):

>>> 5 * np.random.random_sample((3, 2)) - 5
array([[-3.99149989, -0.52338984], # random
       [-2.99091858, -0.79479508],
       [-1.23204345, -1.75224494]])

๐Ÿ’œ XRStools.xrs_calctools.rayleigh(scale=1.0, size=None) ๐Ÿ’œ

Draws samples from a Rayleigh distribution. ๐Ÿฆ‹

The \chi and Weibull distributions are generalizations of the Rayleigh, so likeโ€ฆ Rayleigh is the base model and those two are her extended universe.

NOTE: New code should use the rayleigh method of a default_rng() instance instead; please see the random-quick-start.
  • scale โ€” float or array_like of floats, optional scale, which also equals the mode. Must be non-negative. Default is 1. so don't go negative on her, she will not be okay with that.
  • size โ€” int or tuple of ints, optional output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if scale is a scalar. Otherwise, np.array(scale).size samples are drawn. okay so the shape logic here is a little diva but she's consistent about it.
  • out โ€” ndarray or scalar drawn samples from the parameterized Rayleigh distribution.
  • Generator.rayleigh โ€” which should be used for new code.

The probability density function for the Rayleigh distribution is

P(x;scale) = \frac{x}{scale^2}e^{\frac{-x^2}{2 \cdotp scale^2}}

The Rayleigh distribution would arise, for example, if the East and North components of the wind velocity had identical zero-mean Gaussian distributions. Then the wind speed would have a Rayleigh distribution. ๐ŸŒฌ๏ธ iconic physics moment.

Draw values from the distribution and plot the histogram:

>>> from matplotlib.pyplot import hist
>>> values = hist(np.random.rayleigh(3, 100000), bins=200, density=True)

Wave heights tend to follow a Rayleigh distribution. If the mean wave height is 1 meter, what fraction of waves are likely to be larger than 3 meters?

>>> meanvalue = 1
>>> modevalue = np.sqrt(2 / np.pi) * meanvalue
>>> s = np.random.rayleigh(modevalue, 1000000)

The percentage of waves larger than 3 meters is:

>>> 100.*sum(s>3)/1000000.
0.087300000000000003 # random

๐ŸŽ€ XRStools.xrs_calctools.readxas(filename) ๐ŸŽ€

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

like, she's a function AND a whole documentation block at the same time. multitasking queen. ๐Ÿ‘‘


๐Ÿ“ XRStools.xrs_calctools.repair_h2o_molecules_pbc(h2o_mols, boxLength) ๐Ÿ“


โญ XRStools.xrs_calctools.seed(self, seed=None) โญ

Reseed a legacy MT19937 BitGenerator. ๐ŸŒˆ

This is a convenience, legacy function. ๐Ÿ’…

The best practice is to not reseed a BitGenerator โ€” rather, recreate a new one. This method is here for legacy reasons. This example demonstrates best practice:

>>> from numpy.random import MT19937
>>> from numpy.random import RandomState, SeedSequence
>>> rs = RandomState(MT19937(SeedSequence(123456789)))
# Later, you want to restart the stream
>>> rs = RandomState(MT19937(SeedSequence(987654321)))

see how she just makes a whole new one? that's the move. new girl, fresh energy. โœจ


๐Ÿ‘‘ XRStools.xrs_calctools.set_state(state) ๐Ÿ‘‘

Set the internal state of the generator from a tuple. ๐Ÿซถ

For use if one has reason to manually (re-)set the internal state of the bit generator used by the RandomState instance. By default, RandomState uses the "Mersenne Twister" [1]_ pseudo-random number generating algorithm.

  • state โ€” {tuple(str, ndarray of 624 uints, int, int, float), dict} the state tuple has the following items:
    1. the string 'MT19937', specifying the Mersenne Twister algorithm.
    2. a 1-D array of 624 unsigned integers keys.
    3. an integer pos.
    4. an integer has_gauss.
    5. a float cached_gaussian.

If state is a dictionary, it is directly set using the BitGenerators state property.

  • out โ€” None returns 'None' on success. slay, it worked.
  • get_state

set_state and get_state are not needed to work with any of the random distributions in NumPy. If the internal state is manually altered, the user should know exactly what he/she is doing. ๐Ÿ˜ญ no fr, do not touch this unless you're built different.

For backwards compatibility, the form (str, array of 624 uints, int) is also accepted although it is missing some information about the cached Gaussian value: state = ('MT19937', keys, pos).

  • [1] M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator," ACM Trans. on Modeling and Computer Simulation, Vol. 8, No. 1, pp. 3-30, Jan. 1998.

๐ŸŒˆ XRStools.xrs_calctools.shuffle(x) ๐ŸŒˆ

Modify a sequence in-place by shuffling its contents. ๐Ÿ’…

Okay so bestie, quick heads-up about how shuffle behaves: it only shuffles along the first axis of a multi-dimensional array. The order of the sub-arrays gets changed, but their contents stay exactly the same. ๐Ÿ’…

NOTE: New code should use the shuffle method of a default_rng() instance instead; please see the random-quick-start.
  • x โ€” ndarray or MutableSequence. The array, list or mutable sequence to be shuffled.
  • Returns: None.

Generator.shuffle: which should be used for new code.

>>> arr = np.arange(10)
>>> np.random.shuffle(arr)
>>> arr
[1 7 5 2 9 4 3 6 0 8] # random

Multi-dimensional arrays are only shuffled along the first axis:

>>> arr = np.arange(9).reshape((3, 3))
>>> np.random.shuffle(arr)
>>> arr
array([[3, 4, 5], # random
       [6, 7, 8],
       [0, 1, 2]])

โœจ XRStools.xrs_calctools.sorter(elem) โœจ

โœจ XRStools.xrs_calctools.spline2(x, y, x2) โœจ

Extrapolates the smaller and larger valuea as a constant ๐Ÿซถ


โœจ XRStools.xrs_calctools.standard_cauchy(size=None) โœจ

Draw samples from a standard Cauchy distribution with mode = 0. ๐ŸŽ€

Also known as the Lorentz distribution.

NOTE: New code should use the standard_cauchy method of a default_rng() instance instead; please see the random-quick-start.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
  • samples โ€” ndarray or scalar. The drawn samples.

Generator.standard_cauchy: which should be used for new code.

The probability density function for the full Cauchy distribution is

P(x; x_0, \gamma) = \frac{1}{\pi \gamma \bigl[ 1+
(\frac{x-x_0}{\gamma})^2 \bigr] }

and the Standard Cauchy distribution just sets x_0=0 and \gamma=1.

The Cauchy distribution arises in the solution to the driven harmonic oscillator problem, and also describes spectral line broadening. It also describes the distribution of values at which a line tilted at a random angle will cut the x axis.

When studying hypothesis tests that assume normality, seeing how the tests perform on data from a Cauchy distribution is a good indicator of their sensitivity to a heavy-tailed distribution, since the Cauchy looks very much like a Gaussian distribution, but with heavier tails.

References:

  1. NIST/SEMATECH e-Handbook of Statistical Methods, "Cauchy Distribution", https://www.itl.nist.gov/div898/handbook/eda/section3/eda3663.htm
  2. Weisstein, Eric W. "Cauchy Distribution." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/CauchyDistribution.html
  3. Wikipedia, "Cauchy distribution" https://en.wikipedia.org/wiki/Cauchy_distribution

Draw samples and plot the distribution:

>>> import matplotlib.pyplot as plt
>>> s = np.random.standard_cauchy(1000000)
>>> s = s[(s>-25) & (s<25)]  # truncate distribution so it plots well
>>> plt.hist(s, bins=100)
>>> plt.show()

โœจ XRStools.xrs_calctools.standard_exponential(size=None) โœจ

Draw samples from the standard exponential distribution. ๐Ÿฆ‹

standard_exponential is identical to the exponential distribution with a scale parameter of 1.

NOTE: New code should use the standard_exponential method of a default_rng() instance instead; please see the random-quick-start.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
  • out โ€” float or ndarray. Drawn samples.

Generator.standard_exponential: which should be used for new code.

Output a 3x8000 array:

>>> n = np.random.standard_exponential((3, 8000))

โœจ XRStools.xrs_calctools.standard_gamma(shape, size=None) โœจ

Draw samples from a standard Gamma distribution. ๐Ÿ’œ

Samples are drawn from a Gamma distribution with specified parameters, shape (sometimes designated "k") and scale=1.

NOTE: New code should use the standard_gamma method of a default_rng() instance instead; please see the random-quick-start.
  • shape โ€” float or array_like of floats. Parameter, must be non-negative.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if shape is a scalar. Otherwise, np.array(shape).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized standard gamma distribution.

See also:

  • scipy.stats.gamma โ€” probability density function, distribution or cumulative density function, etc.

Generator.standard_gamma: which should be used for new code.

The probability density for the Gamma distribution is

p(x) = x^{k-1}\frac{e^{-x/\theta}}{\theta^k\Gamma(k)},

where k is the shape and \theta the scale, and \Gamma is the Gamma function.

The Gamma distribution is often used to model the times to failure of electronic components, and arises naturally in processes for which the waiting times between Poisson distributed events are relevant.

References:

  1. Weisstein, Eric W. "Gamma Distribution." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/GammaDistribution.html
  2. Wikipedia, "Gamma distribution", https://en.wikipedia.org/wiki/Gamma_distribution

Draw samples from the distribution:

>>> shape, scale = 2., 1. # mean and width
>>> s = np.random.standard_gamma(shape, 1000000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> import scipy.special as sps
>>> count, bins, ignored = plt.hist(s, 50, density=True)
>>> y = bins**(shape-1) * ((np.exp(-bins/scale))/
...                       (sps.gamma(shape) * scale**shape))
>>> plt.plot(bins, y, linewidth=2, color='r')
>>> plt.show()

โœจ XRStools.xrs_calctools.standard_normal(size=None) โœจ

Draw samples from a standard Normal distribution (mean=0, stdev=1). ๐ŸŒˆ

NOTE: New code should use the standard_normal method of a default_rng() instance instead; please see the random-quick-start.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.
  • out โ€” float or ndarray. A floating-point array of shape size of drawn samples, or a single sample if size was not specified.

See also:

  • normal โ€” Equivalent function with additional loc and scale arguments for setting the mean and standard deviation.

Generator.standard_normal: which should be used for new code.

For random samples from N(\mu, \sigma^2), use one of:

mu + sigma * np.random.standard_normal(size=...)
np.random.normal(mu, sigma, size=...)
>>> np.random.standard_normal()
2.1923875335537315 #random
>>> s = np.random.standard_normal(8000)
>>> s
array([ 0.6888893 ,  0.78096262, -0.89086505, ...,  0.49876311,  # random
       -0.38672696, -0.4685006 ])                                # random
>>> s.shape
(8000,)
>>> s = np.random.standard_normal(size=(3, 4, 2))
>>> s.shape
(3, 4, 2)

Two-by-four array of samples from N(3, 6.25):

>>> 3 + 2.5 * np.random.standard_normal(size=(2, 4))
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],   # random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]])  # random

โœจ XRStools.xrs_calctools.standard_t(df, size=None) โœจ

Draw samples from a standard Student's t distribution with df degrees of freedom. ๐Ÿ‘‘

A special case of the hyperbolic distribution. As df gets large, the result resembles that of the standard normal distribution (standard_normal).

NOTE: New code should use the standard_t method of a default_rng() instance instead; please see the random-quick-start.
  • df โ€” float or array_like of floats. Degrees of freedom, must be > 0.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if df is a scalar. Otherwise, np.array(df).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized standard Student's t distribution.

Generator.standard_t: which should be used for new code.

The probability density function for the t distribution is

P(x, df) = \frac{\Gamma(\frac{df+1}{2})}{\sqrt{\pi df}
\Gamma(\frac{df}{2})}\Bigl( 1+\frac{x^2}{df} \Bigr)^{-(df+1)/2}

The t test is based on an assumption that the data come from a Normal distribution. The t test provides a way to test whether the sample mean (that is the mean calculated from the data) is a good estimate of the true mean.

The derivation of the t-distribution was first published in 1908 by William Gosset while working for the Guinness Brewery in Dublin. Due to proprietary issues, he had to publish under a pseudonym, and so he used the name Student.

References:

  1. Dalgaard, Peter, "Introductory Statistics With R", Springer, 2002.
  2. Wikipedia, "Student's t-distribution" https://en.wikipedia.org/wiki/Student's_t-distribution

From Dalgaard page 83 [1]_, suppose the daily energy intake for 11 women in kilojoules (kJ) is:

>>> intake = np.array([5260., 5470, 5640, 6180, 6390, 6515, 6805, 7515, \
...                    7515, 8230, 8770])

Does their energy intake deviate systematically from the recommended value of 7725 kJ? okay so here's the whole vibe ๐Ÿ’– โ€” our null hypothesis is gonna be the absence of deviation, and the alternate hypothesis is the presence of an effect that could be either positive or negative, which means our test is 2-tailed. no cap. ๐Ÿ’…

Because we're estimating the mean and we have N=11 values in our sample, we have N-1=10 degrees of freedom. We set our significance level to 95% and compute the t statistic using the empirical mean and empirical standard deviation of our intake. We use a ddof of 1 to base the computation of our empirical standard deviation on an unbiased estimate of the variance โ€” quick heads-up tho: the final estimate is not unbiased due to the concave nature of the square root. ๐Ÿ˜ญ math really said "no free lunch bestie"

>>> np.mean(intake)
6753.636363636364
>>> intake.std(ddof=1)
1142.1232221373727
>>> t = (np.mean(intake)-7725)/(intake.std(ddof=1)/np.sqrt(len(intake)))
>>> t
-2.8207540608310198

We draw 1000000 samples from Student's t distribution with the adequate degrees of freedom.

>>> import matplotlib.pyplot as plt
>>> s = np.random.standard_t(10, size=1000000)
>>> h = plt.hist(s, bins=100, density=True)

Does our t statistic land in one of the two critical regions found at both tails of the distribution?

>>> np.sum(np.abs(t) < np.abs(s)) / float(len(s))
0.018318  #random < 0.05, statistic is in critical region

The probability value for this 2-tailed test is about 1.83%, which is lower than the 5% pre-determined significance threshold.

Therefore, the probability of observing values as extreme as our intake conditionally on the null hypothesis being true is too low, and we reject the null hypothesis of no deviation. ๐Ÿ”ฅ periodt.


class XRStools.xrs_calctools.stobe(prefix, postfix, fromnumber, tonumber, step, stepformat=2)

  • Bases: object

class to analyze StoBe results โœจ

  • broaden_lin(params=[0.8, 8, 537.5, 550], npoints=1000)
  • cut_rawspecs(emin=None, emax=None)
  • norm_area(emin, emax)
  • sum_specs()

XRStools.xrs_calctools.translateOcean2FDMNES_p1(ocean_in, fdmnes_out, header_file)


XRStools.xrs_calctools.triangular(left, mode, right, size=None)

Draw samples from the triangular distribution over the interval [left, right]. ๐Ÿฆ‹

The triangular distribution is a continuous probability distribution with lower limit left, peak at mode, and upper limit right. Unlike the other distributions, these parameters directly define the shape of the pdf. so iconic.

NOTE: New code should use the triangular method of a default_rng() instance instead; please see the random-quick-start.
  • left โ€” float or array_like of floats. Lower limit.
  • mode โ€” float or array_like of floats. The value where the peak of the distribution occurs. The value must fulfill the condition left <= mode <= right.
  • right โ€” float or array_like of floats. Upper limit, must be larger than left.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if left, mode, and right are all scalars. Otherwise, np.broadcast(left, mode, right).size samples are drawn.

Returns:

  • out โ€” ndarray or scalar. Drawn samples from the parameterized triangular distribution.

See also:

  • Generator.triangular โ€” which should be used for new code.

The probability density function for the triangular distribution is:

P(x;l, m, r) = \begin{cases}
\frac{2(x-l)}{(r-l)(m-l)}& \text{for $l \leq x \leq m$},\\
\frac{2(r-x)}{(r-l)(r-m)}& \text{for $m \leq x \leq r$},\\ 0&
\text{otherwise}.  \end{cases}

The triangular distribution is often used in ill-defined problems where the underlying distribution is not known, but some knowledge of the limits and mode exists. Often it is used in simulations.

References:

  1. [1] Wikipedia, "Triangular distribution" https://en.wikipedia.org/wiki/Triangular_distribution

Draw values from the distribution and plot the histogram:

>>> import matplotlib.pyplot as plt
>>> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200,
...              density=True)
>>> plt.show()

XRStools.xrs_calctools.uniform(low=0.0, high=1.0, size=None)

Draw samples from a uniform distribution. ๐Ÿ’œ

Samples are uniformly distributed over the half-open interval [low, high) (includes low, but excludes high). In other words, any value within the given interval is equally likely to be drawn by uniform. fair and balanced bestie โœจ

NOTE: New code should use the uniform method of a default_rng() instance instead; please see the random-quick-start.
  • low โ€” float or array_like of floats, optional. Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.
  • high โ€” float or array_like of floats. Upper boundary of the output interval. All values generated will be less than or equal to high. The default value is 1.0.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if low and high are both scalars. Otherwise, np.broadcast(low, high).size samples are drawn.

Returns:

  • out โ€” ndarray or scalar. Drawn samples from the parameterized uniform distribution.

See also:

  • randint โ€” Discrete uniform distribution, yielding integers.
  • random_integers โ€” Discrete uniform distribution over the closed interval [low, high].
  • random_sample โ€” Floats uniformly distributed over [0, 1).
  • random โ€” Alias for random_sample.
  • rand โ€” Convenience function that accepts dimensions as input, e.g., rand(2,2) would generate a 2-by-2 array of floats, uniformly distributed over [0, 1).
  • Generator.uniform โ€” which should be used for new code.

The probability density function of the uniform distribution is:

p(x) = \frac{1}{b - a}

anywhere within the interval [a, b), and zero elsewhere.

When high == low, values of low will be returned. If high < low, the results are officially undefined and may eventually raise an error, i.e. do not rely on this function to behave when passed arguments satisfying that inequality condition. The high limit may be included in the returned array of floats due to floating-point rounding in the equation low + (high-low) * random_sample(). For example:

>>> x = np.float32(5*0.99999999)
>>> x
5.0

Draw samples from the distribution:

>>> s = np.random.uniform(-1,0,1000)

All values are within the given interval:

>>> np.all(s >= -1)
True
>>> np.all(s < 0)
True

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> count, bins, ignored = plt.hist(s, 15, density=True)
>>> plt.plot(bins, np.ones_like(bins), linewidth=2, color='r')
>>> plt.show()

XRStools.xrs_calctools.vaspBoxParser(filename)

groTrajecParser Parses an gromacs GRO-style file for the xyzBox class.


XRStools.xrs_calctools.vaspTrajecParser(filename, min_boxes=0, max_boxes=1000)

groTrajecParser Parses an gromacs GRO-style file for the xyzBox class.


XRStools.xrs_calctools.vonmises(mu, kappa, size=None)

Draw samples from a von Mises distribution. ๐ŸŒˆ

Samples are drawn from a von Mises distribution with specified mode (mu) and dispersion (kappa), on the interval [-pi, pi].

The von Mises distribution (also known as the circular normal distribution) is a continuous probability distribution on the unit circle. It may be thought of as the circular analogue of the normal distribution. circle math goes hard fr fr ๐ŸŒ€

NOTE: New code should use the vonmises method of a default_rng() instance instead; please see the random-quick-start.
  • mu โ€” float or array_like of floats. Mode ("center") of the distribution.
  • kappa โ€” float or array_like of floats. Dispersion of the distribution, has to be >=0.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if mu and kappa are both scalars. Otherwise, np.broadcast(mu, kappa).size samples are drawn.

Returns:

  • out โ€” ndarray or scalar. Drawn samples from the parameterized von Mises distribution.

See also:

  • scipy.stats.vonmises โ€” probability density function, distribution, or cumulative density function, etc.
  • Generator.vonmises โ€” which should be used for new code.

The probability density for the von Mises distribution is:

p(x) = \frac{e^{\kappa cos(x-\mu)}}{2\pi I_0(\kappa)},

where \mu is the mode and \kappa the dispersion, and I_0(\kappa) is the modified Bessel function of order 0.

The von Mises is named for Richard Edler von Mises, who was born in Austria-Hungary, in what is now the Ukraine. He fled to the United States in 1939 and became a professor at Harvard. He worked in probability theory, aerodynamics, fluid mechanics, and philosophy of science. ๐Ÿ‘‘

References:

  1. [1] Abramowitz, M. and Stegun, I. A. (Eds.). "Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables, 9th printing," New York: Dover, 1972.
  2. [2] von Mises, R., "Mathematical Theory of Probability and Statistics", New York: Academic Press, 1964.

Draw samples from the distribution:

>>> mu, kappa = 0.0, 4.0 # mean and dispersion
>>> s = np.random.vonmises(mu, kappa, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> from scipy.special import i0
>>> plt.hist(s, 50, density=True)
>>> x = np.linspace(-np.pi, np.pi, num=51)
>>> y = np.exp(kappa*np.cos(x-mu))/(2*np.pi*i0(kappa))
>>> plt.plot(x, y, linewidth=2, color='r')
>>> plt.show()

๐Ÿฆ‹ XRStools.xrs_calctools.wald(mean, scale, size=None) ๐Ÿฆ‹

Bestie, this one draws samples from a Wald distribution, aka the inverse Gaussian distribution. Two names, one vibe. ๐Ÿ’œ

The way that as scale approaches infinity, the distribution becomes more like a Gaussian โ€” lowkey it just chills out into a bell curve. Some references claim that the Wald is an inverse Gaussian with mean equal to 1, but that is by no means universal, so don't come for me. ๐Ÿ™ˆ

The inverse Gaussian distribution was first studied in relationship to Brownian motion. In 1956 M.C.K. Tweedie used the name inverse Gaussian because there is an inverse relationship between the time to cover a unit distance and distance covered in unit time. History lesson, slay. ๐Ÿ“š

NOTE: New code should use the wald method of a default_rng() instance instead; please see the random-quick-start.
  • mean โ€” float or array_like of floats. Distribution mean, must be > 0.
  • scale โ€” float or array_like of floats. Scale parameter, must be > 0.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if mean and scale are both scalars. Otherwise, np.broadcast(mean, scale).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized Wald distribution.

Generator.wald: which should be used for new code.

The probability density function for the Wald distribution is

P(x;mean,scale) = \sqrt{\frac{scale}{2\pi x^3}}e^\frac{-scale(x-mean)^2}{2\cdotp mean^2x}

As noted above the inverse Gaussian distribution first arise from attempts to model Brownian motion. It is also a competitor to the Weibull for use in reliability modeling and modeling stock returns and interest rate processes. ๐Ÿ‘‘

Draw values from the distribution and plot the histogram:

>>> import matplotlib.pyplot as plt
>>> h = plt.hist(np.random.wald(3, 2, 100000), bins=200, density=True)
>>> plt.show()

๐ŸŽ€ XRStools.xrs_calctools.weibull(a, size=None) ๐ŸŽ€

Draw samples from a Weibull distribution. Periodt. โœจ

Draw samples from a 1-parameter Weibull distribution with the given shape parameter a.

X = (-ln(U))^{1/a}

Here, U is drawn from the uniform distribution over (0,1]. Fr fr.

The more common 2-parameter Weibull, including a scale parameter \lambda is just X = \lambda(-ln(U))^{1/a}.

NOTE: New code should use the weibull method of a default_rng() instance instead; please see the random-quick-start.
  • a โ€” float or array_like of floats. Shape parameter of the distribution. Must be nonnegative.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if a is a scalar. Otherwise, np.array(a).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized Weibull distribution.

scipy.stats.weibull_max scipy.stats.weibull_min scipy.stats.genextreme gumbel Generator.weibull: which should be used for new code.

The Weibull (or Type III asymptotic extreme value distribution for smallest values, SEV Type III, or Rosin-Rammler distribution) is one of a class of Generalized Extreme Value (GEV) distributions used in modeling extreme value problems. This class includes the Gumbel and Frechet distributions. It's giving range, bestie. ๐ŸŒˆ

The probability density for the Weibull distribution is

p(x) = \frac{a}{\lambda}(\frac{x}{\lambda})^{a-1}e^{-(x/\lambda)^a},

where a is the shape and \lambda the scale.

The function has its peak (the mode) at \lambda(\frac{a-1}{a})^{1/a}.

When a = 1, the Weibull distribution reduces to the exponential distribution. Cute little special case, iconic. ๐Ÿ’…

  • [1] Waloddi Weibull, Royal Technical University, Stockholm, 1939 "A Statistical Theory Of The Strength Of Materials", Ingeniorsvetenskapsakademiens Handlingar Nr 151, 1939, Generalstabens Litografiska Anstalts Forlag, Stockholm.
  • [2] Waloddi Weibull, "A Statistical Distribution Function of Wide Applicability", Journal Of Applied Mechanics ASME Paper 1951.
  • [3] Wikipedia, "Weibull distribution", https://en.wikipedia.org/wiki/Weibull_distribution

Draw samples from the distribution:

>>> a = 5. # shape
>>> s = np.random.weibull(a, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> x = np.arange(1,100.)/50.
>>> def weib(x,n,a):
...     return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)

>>> count, bins, ignored = plt.hist(np.random.weibull(5.,1000))
>>> x = np.arange(1,100.)/50.
>>> scale = count.max()/weib(x, 1., 5.).max()
>>> plt.plot(x, weib(x, 1., 5.)*scale)
>>> plt.show()

โœจ XRStools.xrs_calctools.writeFDMNESinput_file(xyzAtoms, fname, Filout, Range, Radius, Edge, NRIXS, Absorber, Green=False, SCF=False) โœจ

writeFDMNESinput_file Writes an input file to be used for FDMNES. That's it, that's the function. ๐Ÿซถ

๐ŸŒธ XRStools.xrs_calctools.writeFEFFinput_arb(fname, headerfile, xyzBox, exatom, edge) ๐ŸŒธ

writeFEFFinput_arb โ€” yeah bestie, that's the whole description. No extra lore here.

๐Ÿ’– XRStools.xrs_calctools.writeMD1Input(fname, box, headerfile, exatomNo=0) ๐Ÿ’–

writeWFN1input Writes an input for cp.x by Quantum espresso for electronic wave function minimization. (Yes, the name in the description says writeWFN1input โ€” that's literally what the page says, don't @ me. ๐Ÿ™ˆ)

๐Ÿฆ‹ XRStools.xrs_calctools.writeOCEAN_XESInput(fname, box, headerfile, exatomNo=0) ๐Ÿฆ‹

writeOCEAN_XESInput Writes an input for ONEAN XES calculation for 17 molecule water boxes. Very specific, very demure. ๐Ÿ’ง

โญ XRStools.xrs_calctools.writeOCEANinput(fname, headerfile, xyzBox, exatom, edge, subshell) โญ

writeOCEANinput โ€” that's the description, verbatim vibes.

๐Ÿงš XRStools.xrs_calctools.writeOCEANinput_arb(fname, headerfile, xyzBox, exatom, edge, subshell) ๐Ÿงš

writeOCEANinput โ€” same description as above, it's a whole family of them.

๐Ÿ‘‘ XRStools.xrs_calctools.writeOCEANinput_full(fname, xyzBox, exatom, edge, subshell) ๐Ÿ‘‘

Writes a complete OCEAN input file. The full package, no notes. ๐Ÿ’…

Args:

  • fname (str): Filename for the input file to be written.
  • xyzBox (xyzBox): Instance of the xyzBox class to be converted into an OCEAN input file.
  • exatom (str): Atomic symbol for the excited atom.
  • edge (int): Integer defining which shell to excite (e.g. 0 for K-shell, 1 for L, etc.).
  • subshell (int): Integer defining which sub-shell to excite ( e.g. 0 for s, 1 for p, etc.).

๐Ÿ“ XRStools.xrs_calctools.writeOCEANinput_new(fname, headerfile, xyzBox, exatom, edge, subshell) ๐Ÿ“

writeOCEANinput โ€” yeah, same as the others, the description is just the name. ๐Ÿซ 

๐Ÿ”ฅ XRStools.xrs_calctools.writePWinuptFile(fname, box, param_dict) ๐Ÿ”ฅ

writePWinuptFile โ€” that's the whole thing. (Spelling preserved exactly, bestie, I would never.)

๐ŸŒˆ XRStools.xrs_calctools.writeRelXYZfile(filename, n_atoms, boxLength, title, xyzAtoms, inclAtomNames=True) ๐ŸŒˆ

No description given on the page, but the signature is right there. ๐Ÿ˜Œ

๐Ÿ’œ XRStools.xrs_calctools.writeWFN1waterInput(fname, box, headerfile, exatomNo=0) ๐Ÿ’œ

writeWFN1input Writes an input for cp.x by Quantum espresso for electronic wave function minimization. (Again: description says writeWFN1input, I'm just the messenger. ๐Ÿ˜ญ)

๐ŸŽ€ XRStools.xrs_calctools.writeXYZfile(filename, numberOfAtoms, title, list_of_xyzAtoms) ๐ŸŽ€

No description on the page โ€” the signature is the whole story.

โœจ XRStools.xrs_calctools.writeXYZtrajectory(filename, boxes) โœจ

Same deal: signature only, no blurb.


๐Ÿ’… class XRStools.xrs_calctools.xyzAtom(name, coordinates, number)

Bases: object

xyzAtom

Class to hold information about and manipulate a single atom in xyz-style format. One atom, main character energy. โญ

Args. :

  • name (str): Atomic symbol.
  • coordinates (np.array): Array of xyz-coordinates.
  • number (int): Integer, e.g. number of atom in a cluster.

๐Ÿฆ‹ getAnglePBCarb(atom2, atom3, lattice, lattice_inv, degrees=True)

get_angle Return angle between the three given atoms (as seen from atom2). Geometry slay. ๐Ÿ“

๐ŸŒธ getCoordinates()

No description given. Signature only, bestie.

๐Ÿ’– getDist(atom)

No description given on the page.

๐Ÿงš getDistPBCarb(atom, lattice, lattice_inv)

No description given on the page.

โญ getNorm()

No description given on the page.

๐Ÿ“ load_spectrum(file_name)

No description given on the page.

๐Ÿ’œ load_spectrum_all_pol(prefix, num_pols, printing=False)

No description given on the page.

๐Ÿ‘‘ normalize_spectrum(normrange)

No description given on the page.

๐Ÿ”ฅ translateSelf(vector)

No description given on the page.

๐ŸŒˆ translateSelf_arb(lattice, lattice_inv, vector)

No description given on the page.


๐Ÿงš class XRStools.xrs_calctools.xyzBox(xyzAtoms, boxLength=None, title=None)

Bases: object

xyzBox

Class to hold information about and manipulate a xyz-periodic cubic box. It's giving contained, literally. ๐Ÿ“ฆ

Args.:

  • xyzAtoms (list): List of instances of the xyzAtoms class that make up the molecule.
  • boxLength (float): Box length.

๐Ÿ’… changeOHBondlength(fraction, oName='O', hName='H')

changeOHBondlength Changes all OH covalent bond lengths inside the box by a fraction.

๐ŸŒธ count_contact_pairs(name_1, name_2, cutoff, counter_name='contact_pair')

No description given on the page.

โญ count_hbonds(Roocut=3.6, Rohcut=2.4, Aoooh=30.0, counter_name='num_H_bonds', counter_name2='H_bond_angles')

count_hbonds Counts the number of hydrogen bonds around all oxygen atoms and sets that number as attribute to the accorting xyzAtom. (Spelling accorting is straight from the source, I'm keeping it, no cap. ๐Ÿ’€)

๐Ÿ“ count_neighbors(name1, name2, cutoff_low=0.0, cutoff_high=2.0, counter_name='num_OO_shell')

count_neighbors

Counts number of neighbors (of name2) around atom of name1.

Args:

  • name1 (str): Name of first type of atom.
  • name2 (str): Name of second type of atom.
  • cutoff_low (float): Lower cutoff (Angstrom).
  • deleteTip4pCOM() โ€” okay so this one deletes the fictitious atoms that the TIP4P water model sneaks in there. poof. gone. not invited to the function anymore ๐Ÿ’…
  • findMethAndHexMolecules(CO_cut=1.6, CH_cut=1.2, OH_cut=1.2, CC_cut=1.7) โ€” the docs say, and I quote, CH3OH. that's it. that's the whole description. iconic ๐ŸŽ€
  • findMethanolMolecules(CO_cut=1.6, CH_cut=1.2, OH_cut=1.2) โ€” also just CH3OH. bestie the documentation is not documentationing but we move ๐Ÿฆ‹
  • find_hydroniums(OH_cutoff=1.5) โ€” returns a list of hydronium molecules, periodt.
  • find_hydroxides(OH_cutoff=1.5) โ€” returns a list of hydroxide molecules. same energy, different ion โœจ
  • find_tmao_molecules_arb(CH_cut=1.2, CN_cut=1.6, NO_cut=1.5, CC_cut=2.5) โ€” returns a list of TMAO molecules. arb means it's vibing with arbitrary lattices, iykyk.
  • find_urea_molecules_arb(NH_cut=1.2, CN_cut=1.6, CO_cut=1.5) โ€” returns a list of Urea molecules. capital U, respect ๐Ÿ’œ
  • getCoordinates() โ€” returns the coordinates of all the atoms in the cluster. every single one, no crumbs left.
  • getDistVectorPBC_arb(atom1, atom2) โ€” getDistVectorPBC_arb. this one calculates the distance vector between two atoms from an arbitrary simulation box, using the minimum image convention.
    • Args:
      • atom1 (obj) โ€” an instance of the xzyAtom class.
      • atom2 (obj) โ€” an instance of the xzyAtom class.
    • Returns: the distance vector between the two atoms (np.array).
  • getDistancePBC_arb(atom1, atom2) โ€” getDistancePBC_arb. calculates the distance of two atoms from an arbitrary simulation box using the minimum image convention.
    • Args:
      • atom1 (obj) โ€” an instance of the xzyAtom class.
      • atom2 (obj) โ€” an instance of the xzyAtom class.
    • Returns: the distance between the two atoms.
  • getTetraParameter() โ€” returns a list of tetrahedrality paprameters, according to NATURE, VOL 409, 18 JANUARY (2001).
UNTESTED!!! ๐Ÿ˜ญ bestie do not put your whole thesis on this one without a vibe check first.
  • get_OO_neighbors(Roocut=3.6) โ€” returns a list of numbers of nearest oxygen neighbors within radius Roocut. oxygens stay close, we love to see it ๐ŸŒธ
  • get_OO_neighbors_pbc(Roocut=3.6) โ€” returns a list of numbers of nearest oxygen atoms, and it uses periodic boundary conditions. the box is a lie, the neighbors are forever โœจ
  • get_angle(atom1, atom2, atom3, degrees=True) โ€” returns the angle between the three given atoms (as seen from atom2). atom2 is the main character here, obviously ๐Ÿ‘‘
  • get_angle_arb(atom1, atom2, atom3, degrees=True) โ€” returns the angle between the three given atoms (as seen from atom2). yes it has the same description as the one above. no, that's not a typo on my end, that's just the docs being the docs ๐Ÿ™ˆ
  • get_atoms_by_name(name) โ€” returns a list of all xyzAtoms of a given name name.
  • get_atoms_from_molecules() โ€” parses all atoms inside self.xyzMolecules into self.xyzAtoms. lowkey the glow-up function: it's useful for turning an xyzMolecule into an xyzBox ๐Ÿฆ‹
  • get_h2o_molecules(o_name='O', h_name='H') โ€” finds all water molecules inside the box and collects them inside the self.xyzMolecules attribute. hydrate or die-drate fr fr ๐Ÿ’ง
  • get_h2o_molecules_arb(o_name='O', h_name='H') โ€” that's it. that's the description. the arbitrary-lattice twin, standing there, saying nothing ๐ŸŽ€
  • get_hbonds(Roocut=3.6, Rohcut=2.4, Aoooh=30.0) โ€” counts the hydrogen bonds inside the box, and returns the number of H-bond donors and H-bond acceptors. two numbers, one function, zero notes ๐Ÿ’–
  • multiplyBoxPBC(numShells) โ€” applies the periodic boundary conditions and multiplies the box in shells around the original.
  • multiplyBoxPBC_arb(lx=[- 1, 1], ly=[- 1, 1], lz=[- 1, 1]) โ€” applies the periodic boundary conditions and multiplies the box in shells around the original. works with arbitrary lattices. the little _arb that could ๐Ÿ’…
  • normalize_arb_spectrum(normrange, attribute) โ€” no description given. she's mysterious. she's normalizing. that's all we know โœจ
  • normalize_spectrum(normrange) โ€” same deal, no blurb. take the argument, normalize the spectrum, no thoughts head empty ๐ŸŒˆ
  • scatterPlot() โ€” opens a plot window with a scatter-plot of all coordinates of the box. ooh a little window, very aesthetic ๐ŸŽ€
  • setBoxLength(boxLength, angstrom=True) โ€” sets the box length. short king of a function.
  • translateAtomsMinimumImage(lattice, lattice_inv) โ€” translateAtomsMinimumImage. brings back all atoms into the original box using periodic boundary conditions and the minimal image convention. everybody come home, the box misses you ๐Ÿ˜ญ
  • writeBox(filename) โ€” creates an xyz-style text file with all coordinates of the box.
  • writeClusters(cenatom_name, number, cutoff, prefix, postfix='.xyz') โ€” writeXYZclusters. writes water clusters into files. yes the function name and the docstring name don't match, that's just the lore ๐Ÿซถ
  • writeClusters_arb(cenatom_name, number, cutoff, prefix, postfix='.xyz', test_box_multiplyer=1) โ€” writeXYZclusters. writes water clusters into files. again with the name mismatch. we don't ask questions here ๐Ÿ’€
  • writeFDMNESinput(fname, Filout, Range, Radius, Edge, NRIXS, Absorber) โ€” creates an input file to be used for q-dependent calculations with FDMNES.
  • writeH2Oclusters(cutoff, prefix, postfix='.xyz', o_name='O', h_name='H') โ€” writeXYZclusters. writes water clusters into files. third time's the charm ๐ŸŒธ
  • writeMoleculeCluster(molAtomList, fname, cutoff=None, numH2Omols=None, o_name='O', h_name='H', mol_center=None) โ€” writeMoleculeCluster.
Careful, this works only for a single molecule in water. like, one. singular. don't try to be cute with it ๐Ÿ™ˆ
  • writeOCEANinput(fname, headerfile, exatom, edge, subshell) โ€” creates an OCEAN input file based on the headerfile.
  • writeRelBox(filename, inclAtomNames=True) โ€” writes all relative atom coordinates into a text file (useful as OCEAN input).

class XRStools.xrs_calctools.xyzMolecule(xyzAtoms, title=None)

Bases: object

xyzMolecule โ€” the class that holds information about an xyz-style molecule, and then manipulates it. a whole little container of vibes ๐Ÿฆ‹

Args.:

  • xyzAtoms (list) โ€” list of instances of the xyzAtoms class that make up the molecule.
  • appendAtom(Atom) โ€” appendAtom. adds an xzyAtom to the molecule. more atoms, more problems, more fun ๐Ÿ’–
  • getCoordinates() โ€” getCoordinates. returns the coordinates of all atoms in the cluster.
  • getCoordinates_name(name) โ€” getCoordinates_name. returns coordintes of all atoms with name. (spelling is theirs, not mine, and I'm keeping it ๐Ÿ’…)
  • getGeometricCenter() โ€” getGeometricCenter. returns the geometric center of the xyz-molecule. the midpoint. the it-girl of the coordinate space ๐Ÿ‘‘
  • getGeometricCenter_arb(lattice, lattice_inv) โ€” no blurb. just a lattice, an inverse lattice, and a dream โœจ
  • get_atoms_by_name(name) โ€” get_atoms_by_name. returns a list of all xyzAtoms of a given name name.
  • popAtom(xyzAtom) โ€” popAtom. deletes an xyzAtom from the molecule. bye bestie ๐Ÿซถ
  • scatterPlot() โ€” scatterPlot. opens a plot window with a scatter-plot of all coordinates of the molecule.
  • translateAtomsMinimumImage(lattice, lattice_inv, center=array([0., 0., 0.])) โ€” translateAtomsMinimumImage. brings back all atoms into the original box using periodic boundary conditions and the minimal image convention.
  • translateSelf(vector) โ€” translateSelf. translates all atoms of the molecule by a vector vector. move, girl ๐ŸŽ€
  • writeXYZfile(fname) โ€” writeXYZfile. creates an xyz-style text file with all coordinates of the molecule.

XRStools.xrs_calctools.xyzTrajecParser(filename, boxLength, firstBox=0, lastBox=- 1)

Parses a Trajectory of xyz-files. yes, a whole trajectory, not just one sad little box ๐ŸŒˆ

Args.:

  • filename (str) โ€” filename of the xyz Trajectory file.

Returns: a list of xzyBoxes.


class XRStools.xrs_calctools.xyzTrajectory(xyzBoxes)

Bases: object

  • getRDF(atom1='O', atom2='O', MAXBIN=1000, DELR=0.01, RHO=1.0) โ€” no blurb. the Oโ€“O classic, presumably, but the docs ain't saying, so I ain't saying either ๐Ÿ™ˆ
  • getRDF2_arb(atom1='O', atom2='O', MAXBIN=1000, DELR=0.01, RHO=1.0) โ€” also no blurb. arb edition, standing silently beside her sister ๐Ÿ’œ
  • getRDF_arb(atom1='O', atom2='O', MAXBIN=1000, DELR=0.01, RHO=1.0) โ€” again, no description. take the defaults, trust the process โœจ
  • loadAXSFtraj(filename) โ€” no blurb. loads it. loads the AXSF traj. that's the whole bit ๐Ÿฆ‹
  • writeRandBox(filename) โ€” no blurb. writes a random box, presumably, but again โ€” I'm not out here inventing lore for the docs ๐ŸŽ€
  • writeXYZtraj(filename) โ€” no blurb. writes the xyz trajectory. that's the name, that's the job ๐Ÿ’…

XRStools.xrs_calctools.zipf(a, size=None)

Draws samples from a Zipf distribution. we love a statistical queen ๐Ÿ‘‘

Samples are drawn from a Zipf distribution with specified parameter a > 1.

The Zipf distribution (also known as the zeta distribution) is a continuous probability distribution that satisfies Zipf's law: the frequency of an item is inversely proportional to its rank in a frequency table.

NOTE: New code should use the zipf method of a default_rng() instance instead; please see the random-quick-start. bestie this is the old way, the new way is right there, please go use it ๐Ÿ˜ญ
  • a โ€” float or array_like of floats. Distribution parameter. Must be greater than 1.
  • size โ€” int or tuple of ints, optional. Output shape. If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. If size is None (default), a single value is returned if a is a scalar. Otherwise, np.array(a).size samples are drawn.
  • out โ€” ndarray or scalar. Drawn samples from the parameterized Zipf distribution.

See also:

  • scipy.stats.zipf โ€” probability density function, distribution, or cumulative density function, etc.
  • Generator.zipf โ€” which should be used for new code.

The probability density for the Zipf distribution is

p(x) = \frac{x^{-a}}{\zeta(a)},

where \zeta is the Riemann Zeta function.

It is named for the American linguist George Kingsley Zipf, who noted that the frequency of any word in a sample of a language is inversely proportional to its rank in the frequency table. history lesson AND a distribution, we're being fed today ๐Ÿ“

References:

  1. Zipf, G. K., "Selected Studies of the Principle of Relative Frequency in Language," Cambridge, MA: Harvard Univ. Press, 1932.

Draw samples from the distribution:

>>> a = 2. # parameter
>>> s = np.random.zipf(a, 1000)

Display the histogram of the samples, along with the probability density function:

>>> import matplotlib.pyplot as plt
>>> from scipy import special

Truncate s values at 50 so plot is interesting:

>>> count, bins, ignored = plt.hist(s[s<50], 50, density=True)
>>> x = np.arange(1., 50.)
>>> y = x**(-a) / special.zetac(a)
>>> plt.plot(x, y/max(y), linewidth=2, color='r')
>>> plt.show()

๐Ÿงช XRStools.xrs_extraction Module ๐Ÿงช

bestie this one is where the actual science happens โ€” pulling your core edge spectra out of x-ray Raman scattering data like it's nothing ๐Ÿ’…

class XRStools.xrs_extraction.HF_dataset(data, formulas, stoich_weights, edges)

Bases: object

okay so dataset โ€” this is the lil class that holds everything from your HF Compton profiles that you're gonna need in order to subtract the background from the experiment. it's giving storage unit but make it physics ๐Ÿ“ฆโœจ

  • get_C_edges_av(element, edge, columns)
  • get_C_total(columns)
  • get_J_total_av(columns)

class XRStools.xrs_extraction.edge_extraction(exp_data, formulas, stoich_weights, edges, prenormrange=[5, inf])

Bases: object

edge_extraction โ€” the moment we've all been waiting for ๐ŸŽ€ this is the class that destills core edge spectra from x-ray Raman scattering experiments. yes she's the main character.

  • analyzerAverage(roi_numbers, errorweighing=True) โ€” analyzerAverage averages signals from several crystals before background subtraction. slay.
    • Args:
      • roi_numbers โ€” list, a str list of ROI numbers to average over, or keyword for analyzer chamber (e.g. 'VD','VU','VB','HR','HL','HB')
      • errorweighing โ€” boolean (True by default), keyword for whether error weighing should be used for the averaging or not
  • removeCorePearsonAv(element, edge, range1, range2, weights=[2, 1], HFcore_shift=0.0, guess=None, scaling=None, return_background=False, show_plots=True) โ€” removeCorePearsonAv. and guess takes a (list): [position, FWHM, shape, intensity, ax, b, scale] ๐Ÿ’ซ
  • removeCorePearsonAv_new(element, edge, range1, range2, HFcore_shift=0.0, guess=None, scaling=None, return_background=False, reg_lam=10) โ€” removeCorePearsonAv_new. the sequel, and yes it ate ๐Ÿ’…
  • removePearsonAv(element, edge, range1, range2=None, weights=[2, 1], guess=None, scale=1.0, HFcore_shift=0.0) โ€” removePearsonAv. short, sweet, does the thing.
  • removePolyCoreAv(element, edge, range1, range2, weights=[1, 1], guess=[1.0, 0.0, 0.0], ewindow=100.0) โ€” removePolyCoreAv subtracts a polynomial from averaged data, guided by the HF core Compton profile. guided bestie, like a little sherpa ๐Ÿงš
    • 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]. (yes it's spelled weigths, we don't make the rules ๐Ÿ™ˆ)
      • 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.
  • save_average_Sqw(filename, emin=None, emax=None, normrange=None) โ€” save_average_Sqw saves the S(q,w) into a ascii file (energy loss, S(q,w), Poisson errors). a lil export moment ๐Ÿ“โœจ
    • Args:
      • filename : str โ€” Filename for the ascii file.
      • emin : float โ€” Use this to save only part of the spectrum.
      • emax : float โ€” Use this to save only part of the spectrum.
      • normrange : list of floats โ€” E_start and E_end for possible area-normalization before saving.

class XRStools.xrs_extraction.functorObjectV(y, eloss, hfcore, lam)

Bases: object
  • funct(a, eloss)

XRStools.xrs_extraction.map_chamber_names(name)

map_chamber_names maps names of chambers to range of ROI numbers. that's it that's the job ๐Ÿ—บ๏ธ๐Ÿ’–


class XRStools.xrs_extraction.valence_CP

Bases: object

valence_CP โ€” the class that organizes all the info about extracted experimental valence Compton profiles. she's organized, she's booked, she's thriving ๐Ÿ‘‘

  • get_asymmetry()
  • get_pzscale()

๐Ÿ–ผ๏ธ XRStools.xrs_imaging Module ๐Ÿ–ผ๏ธ

(no cap, that's the whole section ๐Ÿ’€)


๐Ÿ“– XRStools.xrs_read Module ๐Ÿ“–

(same bestie, nothing more to see here ๐Ÿ“)


๐Ÿ“ˆ XRStools.xrs_scans Module ๐Ÿ“ˆ

(yep. empty. iconic of her honestly ๐Ÿ’…)


โš›๏ธ XRStools.xrs_ComptonProfiles Module โš›๏ธ

class XRStools.xrs_ComptonProfiles.AtomProfile(element, filename, stoichiometry=1.0)

Bases: object

AtomProfile โ€” a whole class to construct and handle the Hartree-Fock atomic Compton Profile of a single atoms. one atom, one profile, one vibe ๐ŸŒธ

Attributes:

  • filename : string โ€” Path and filename to the HF profile table.
  • element : string โ€” Element symbol as in the periodic table.
  • elementNr : int โ€” Number of the element as in the periodic table.
  • shells : list of strings โ€” Names of the shells.
  • edges : list โ€” List of edge onsets (eV).
  • C_total : np.array โ€” Total core Compton profile.
  • J_total : np.array โ€” Total Compton profile.
  • V_total : np.array โ€” Total valence Compton profile.
  • CperShell : dict. of np.arrays โ€” Core Compton profile per electron shell.
  • JperShell : dict. of np.arrays โ€” Total Compton profile per electron shell.
  • VperShell : dict. of np.arrays โ€” Valence Compton profile per electron shell.
  • stoichiometry : float, optional โ€” Stoichiometric weight (default is 1.0).
  • atomic_weight : float โ€” Atomic weight.
  • atomic_density : float โ€” Density (g/cm**3).
  • twotheta : float โ€” Scattering angle 2Th (degrees).
  • alpha : float โ€” Incident angle (degrees).
  • beta : float โ€” Exit angle (degrees).
  • thickness : float โ€” Sample thickness (cm).
  • absorptionCorrectProfiles(alpha, thickness, geometry='transmission') โ€” absorptionCorrectProfiles applies 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.
      • thickness : float โ€” Sample thickness.
  • get_elossProfiles(E0, twotheta, correctasym=None, valence_cutoff=20.0) โ€” get_elossProfiles converts the HF Compton profile on to energy loss scale.
    • Args:
      • E0 : float โ€” Analyzer energy, enery of the scattered r-rays.
      • twotheta โ€” float or list of floats, Scattering angle 2Th.
      • correctasym โ€” float, optional, Scaling factor to be multiplied to the asymmetry.
      • valence_cutoff โ€” float, optional, Energy cut off as to what is considered the boundary between core and valence.
  • get_stoichiometry()

class XRStools.xrs_ComptonProfiles.ComptonProfiles(element)

Bases: object

Class for multiple HF Compton profiles.

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... the way that she juggles all of that ๐Ÿ˜ญ๐Ÿ’–

Attributes:

  • element (string): Element symbol as in the periodic table.
  • elementNr (int) : Number of the element as in the periodic table.
  • shells (list) :
  • edges (list) :
  • C (np.array) :
  • J (np.array) :
  • V (np.array) :
  • CperShell (dict. of np.arrays):
  • JperShell (dict. of np.arrays):
  • VperShell (dict. of np.arrays):

class XRStools.xrs_ComptonProfiles.FormulaProfile(formula, filename, weight=1)

Bases: object

FormulaProfile โ€” a class to construct and handle the Hartree-Fock atomic Compton Profile of a single chemical compound. one formula, all her lil atoms, all together ๐ŸŽ€๐ŸŒˆ

Attributes

  • filename : string โ€” Path and filename to Biggs database.
  • formula : string โ€” Chemical sum formula for the compound of interest (e.g. 'SiO2' or 'H2O').
  • elements : list of strings โ€” List of atomic symbols that make up the chemical sum formula.
  • stoichiometries : list of integers โ€” List of the stoichimetric weights for each of the elements in the list elements.
  • element_Nrs : list of integers โ€” List of atomic numbers for each element in the elements list.
  • AtomProfiles : list of AtomProfiles โ€” List of instances of the AtomProfiles class for each element in the list.
  • eloss : np.ndarray โ€” Energy loss scale for the Compton profiles.
  • C_total : np.ndarray โ€” Core HF Compton profile (one column per 2Th).
  • J_total : np.ndarray โ€” Total HF Compton profile (one column per 2Th).
  • V_total :np.ndarray โ€” Valence HF Compton profile (one column per 2Th).
  • E0 : float โ€” Analyzer energy (keV).
  • twotheta : float, list, or np.ndarray โ€” Value or list/np.ndarray of the scattering angle.
  • get_correctecProfiles(densities, alpha, beta, samthick)
  • get_elossProfiles(E0, twotheta, correctasym=None, valence_cutoff=20.0)
  • get_stoichWeight()

๐ŸŒŸ XRStools.xrs_ComptonProfiles.HFProfile

class XRStools.xrs_ComptonProfiles.HFProfile(formulas, stoich_weights, filename)

okay so this one inherits from object (yes, she's an old-school style class, we stan anyway) and her whole name is HFProfile.

What is she? She's the class that constructs and handles the Hartree-Fock atomic Compton Profile of a sample that's made up of several chemical compounds. multi-compound sample? she's built different, no cap ๐Ÿ’…

Attributes โœจ โ€” here's what she's carrying:

  • get_elossProfiles(E0, twotheta, correctasym=None, valence_cutoff=20.0)

๐Ÿ’– XRStools.xrs_ComptonProfiles.HRcorrect

XRStools.xrs_ComptonProfiles.HRcorrect(pzprofile, occupation, q)

She hands you back the first order correction to the filled 1s, 2s, and 2p Compton profiles. ๐Ÿซถ

Implementation is after Holm and Ribberfors (citation ... โ€” yes the original literally leaves it as "citation ...", so we leave it as "citation ..." too, bestie).

Args:

  • pzprofile (np.array) โ€” the Compton profile you want corrected (like, tabulated from Biggs), and it's a 2D matrix.
  • occupation (list) โ€” the electron configuration.
  • q (float or np.array) โ€” momentum transfer, in [a.u.].

Returns:

  • asymmetry (np.array) โ€” the asymmetries you're supposed to add to the raw profiles (normalized to the number of electrons on the pz scale).

๐Ÿฆ‹ XRStools.xrs_ComptonProfiles.PzProfile

XRStools.xrs_ComptonProfiles.PzProfile(element, filename)

Returnes tabulated HF Compton profiles. ๐Ÿ’ซ (yes, "Returnes", she said what she said)

She reads in the tabulated HF Compton profiles from the Biggs paper, interpolates them, and normalizes them to the number of electrons in the shell. obsessed.

Args:

  • element (string) โ€” the element symbol (like 'Si', 'Al', etc.).
  • filename (string) โ€” the absolute path and filename to the tabulated profiles.

Returns:

  • CP_profile (np.array) โ€” a matrix of the Compton profile, where column 1 is the pz-scale and columns 2. ... n. are the Compton profile of the nth shell.
  • binding_energy (list) โ€” binding energies of the shells.
  • occupation_num (list) โ€” the number of electrons in the according shells.

๐ŸŽ€ XRStools.xrs_ComptonProfiles.SqwPredict

class XRStools.xrs_ComptonProfiles.SqwPredict

Bases: object โ€” periodt.

This is the class that builds a S(q,w) prediction based on HF Compton Profiles. the way that she just... predicts. iconic ๐Ÿ”ฅ

Attributes:

  • sampleStr (list of strings) โ€” one string per compound (e.g. ['C','SiO2']).
  • concentrations (list of floats) โ€” the relative compositional weight for each compound.

๐ŸŒˆ XRStools.xrs_ComptonProfiles.elossProfile

XRStools.xrs_ComptonProfiles.elossProfile(element, filename, E0, tth, correctasym=None, valence_cutoff=20.0)

Returns HF Compton profiles on the energy loss scale. ๐Ÿ“

She uses the PzProfile function to read in the Biggs HF profiles and converts them onto the energy loss scale. The profiles get cut at the respective electron binding energies and are normalized to the f-sum rule (so like, S(q,w) comes out in units of [1/eV], iykyk).

Args:

  • element (string) โ€” element symbol.
  • filename (string) โ€” absolute path and filename to the tabulated Compton profiles.
  • E0 (float) โ€” analyzer energy in [keV].
  • tth (float) โ€” scattering angle two theta, in [deg].
  • correctasym (np.array) โ€” a vector of scaling factors to be applied.
  • valence_cutoff (float) โ€” the 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], and 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, with the keys defined as in the Biggs table.
  • C_shell (dict of np.arrays) โ€” same as J_shell but for the core contribution.
  • V_shell (dict of np.arrays) โ€” same as J_shell but for the valence contribution.

๐Ÿ’œ XRStools.xrs_ComptonProfiles.getAtomicDensity

XRStools.xrs_ComptonProfiles.getAtomicDensity(Z)

Returns the atomic density. simple as that, bestie. ๐Ÿ’…


โœจ XRStools.xrs_ComptonProfiles.getAtomicWeight

XRStools.xrs_ComptonProfiles.getAtomicWeight(Z)

Returns the atomic weight. equally simple, equally slay.


๐ŸŒธ XRStools.xrs_ComptonProfiles.list_duplicates

XRStools.xrs_ComptonProfiles.list_duplicates(seq)

(no description given, she's mysterious like that ๐Ÿ™ˆ)


๐Ÿงš XRStools.xrs_ComptonProfiles.mapShellNames

XRStools.xrs_ComptonProfiles.mapShellNames(shell_str, atomicNumber)

mapShellNames ๐Ÿ’ซ

She translates to and from spectroscopic edge notation and the convention used by the Biggs database. bilingual queen.

Args:

  • shell_str โ€” string. The spectroscopic symbol to be converted to the Biggs database convention.
  • atomicNumber โ€” int. The Z for the atom in question.

โญ XRStools.xrs_ComptonProfiles.parseChemFormula

XRStools.xrs_ComptonProfiles.parseChemFormula(ChemFormula)

(also no description โ€” she's giving mystery, we respect it ๐Ÿ™ˆ)


๐ŸŽ€ XRStools.xrs_ComptonProfiles.trapz_weights

XRStools.xrs_ComptonProfiles.trapz_weights(x)

(no description here either, bestie, she just exists and we love her)


๐Ÿซถ XRStools.xrs_fileIO Module

๐Ÿ’พ XRStools.xrs_fileIO.EdfRead

XRStools.xrs_fileIO.EdfRead(fname)

(no description, mysterious again)


๐Ÿ’พ XRStools.xrs_fileIO.FabioEdfRead

XRStools.xrs_fileIO.FabioEdfRead(fname)

Returns the EDF-data using FabIO. ๐Ÿ”ฅ


๐Ÿ“ฆ XRStools.xrs_fileIO.PrepareEdfMatrix

XRStools.xrs_fileIO.PrepareEdfMatrix(scan_length, num_pix_x, num_pix_y)

Returns np.zeros of the shape of the detector. clean, empty, ready to be filled. main character energy.


๐Ÿ“ฆ XRStools.xrs_fileIO.PrepareEdfMatrix_TwoImages

XRStools.xrs_fileIO.PrepareEdfMatrix_TwoImages(scan_length, num_pix_x, num_pix_y)

Returns np.zeros for old data โ€” that's where the horizontal and vertical Maxipix images live in different files. vintage. ๐Ÿ’…


๐Ÿ’พ XRStools.xrs_fileIO.PyMcaEdfRead

XRStools.xrs_fileIO.PyMcaEdfRead(fname)

Returns the EDF-data using PyMCA.


๐Ÿ’พ XRStools.xrs_fileIO.PyMcaSpecRead

XRStools.xrs_fileIO.PyMcaSpecRead(filename, nscan)

Returns data, counter-names, and EDF-files using PyMCA. โœจ


๐Ÿ’พ XRStools.xrs_fileIO.PyMcaSpecRead_my

XRStools.xrs_fileIO.PyMcaSpecRead_my(filename, nscan)

Returns data, counter-names, and EDF-files using PyMCA. (yes, the _my version says the exact same thing, no notes ๐Ÿซถ)


๐Ÿ–ผ๏ธ XRStools.xrs_fileIO.ReadEdfImages

XRStools.xrs_fileIO.ReadEdfImages(ccdcounter, num_pix_x, num_pix_y, path, EdfPrefix, EdfName, EdfPostfix)

Reads a series of EDF-images and returs them in a 3D Numpy array โ€” and that's for horizontal and vertical Maxipix images sitting in different files. (yes, "returs". she's consistent about it and honestly? iconic. ๐Ÿ˜ญ)


๐Ÿ–ผ๏ธ XRStools.xrs_fileIO.ReadEdfImages_PyMca

XRStools.xrs_fileIO.ReadEdfImages_PyMca(ccdcounter, path, EdfPrefix, EdfName, EdfPostfix)

Reads a series of EDF-images and returs them in a 3D Numpy array (horizontal and vertical Maxipix images in different files). ๐Ÿฆ‹


๐Ÿ–ผ๏ธ XRStools.xrs_fileIO.ReadEdfImages_TwoImages

XRStools.xrs_fileIO.ReadEdfImages_TwoImages(ccdcounter, num_pix_x, num_pix_y, path, EdfPrefix_h, EdfPrefix_v, EdfNmae, EdfPostfix)

Reads a series of EDF-images and returs them in a 3D Numpy array (horizontal and vertical Maxipix images in different files).

ngl, that argument is spelled EdfNmae in the source โ€” we are not fixing it, we are respecting her exactly as she is. ๐Ÿ’€

๐Ÿ–ผ๏ธ XRStools.xrs_fileIO.ReadEdfImages_my

XRStools.xrs_fileIO.ReadEdfImages_my(ccdcounter, path, EdfPrefix, EdfName, EdfPostfix)

Reads a series of EDF-images and returs them in a 3D Numpy array (horizontal and vertical Maxipix images in different files). ๐ŸŒˆ


๐Ÿ–ผ๏ธ XRStools.xrs_fileIO.ReadEdf_justFirstImage

XRStools.xrs_fileIO.ReadEdf_justFirstImage(ccdcounter, path, EdfPrefix, EdfName, EdfPostfix)

(no description, just vibes ๐Ÿ™ˆ)


๐Ÿ“‚ XRStools.xrs_fileIO.ReadScanFromFile

XRStools.xrs_fileIO.ReadScanFromFile(fname)

Returns a scan stored in a Numpy archive. ๐Ÿ’œ


๐Ÿ’พ XRStools.xrs_fileIO.SilxSpecRead

XRStools.xrs_fileIO.SilxSpecRead(filename, nscan)

Returns data, motors, counter-names, and labels using Silx. โœจ


๐Ÿ’พ XRStools.xrs_fileIO.SpecRead

XRStools.xrs_fileIO.SpecRead(filename, nscan)

Parses a SPEC file and returns a specified scan. ๐Ÿ‘‘

Args:

  • filename (string) โ€” SPEC file name (inlc. path โ€” yes, "inlc.", she's keeping it, periodt).
  • nscan (int) โ€” number of the desired scan.

Returns:

  • data (np.array) โ€” array of the data from the specified scan.
  • motors (list) โ€” list of all motor positions from the header of the specified scan.
  • counters (dict) โ€” all counters in a dictionary, with the counter names as keys.

๐Ÿ’พ XRStools.xrs_fileIO.WriteScanToFile

XRStools.xrs_fileIO.WriteScanToFile(fname, data, motors, counters, edfmats)

Writes a scan into a Numpy archive. ๐ŸŽ€


๐Ÿ“‚ XRStools.xrs_fileIO.dump_on_file_list

XRStools.xrs_fileIO.dump_on_file_list(filename)

(no description โ€” she's quiet, she's mysterious ๐Ÿฆ‹)


๐Ÿ’พ XRStools.xrs_fileIO.myEdfRead

XRStools.xrs_fileIO.myEdfRead(filename)

Returns EDF-data if PyMCA is not installed โ€” and bestie, fair warning: this is slow. ๐ŸŒ

so like, if you've got PyMCA, use the PyMCA one. this is the fallback and she takes her sweet time, no cap.

๐Ÿ“š XRStools.xrs_fileIO.readbiggsdata

XRStools.xrs_fileIO.readbiggsdata(filename, element)

Reads the 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

(and yes โ€” "accorting". we love her. we keep her. ๐Ÿ’–)


๐Ÿซถ XRStools.xrs_prediction Module

(no entries listed here โ€” she's a whole module just... existing โœจ)


๐Ÿซถ XRStools.xrs_rois Module

(also no entries โ€” quiet queen ๐Ÿ’…)


๐Ÿซถ XRStools.xrs_utilities Module

๐ŸŒŸ XRStools.xrs_utilities.Chi

XRStools.xrs_utilities.Chi(chi, degrees=True)

rotation around (1,0,0), pos sense. ๐ŸŒ€


๐Ÿ’– XRStools.xrs_utilities.HRcorrect

XRStools.xrs_utilities.HRcorrect(pzprofile, occupation, q)

Returns the first order correction to filled 1s, 2s, and 2p Compton profiles.

Implementation after Holm and Ribberfors (citation ...). ๐Ÿซถ

Args:

  • pzprofile (np.array) โ€” Compton profile (e.g. tabulated from Biggs) to be corrected (2D matrix).
  • occupation (list) โ€” electron configuration.
  • q (float or np.array) โ€” momentum transfer in [a.u.].

Returns:

  • asymmetry (np.array) โ€” asymmetries to be added to the raw profiles (normalized to the number of electrons on pz scale).

๐Ÿงฎ XRStools.xrs_utilities.NNMFcost

XRStools.xrs_utilities.NNMFcost(x, A, F, C, F_up, C_up, n, k, m)

NNMFcost returns cost and gradient for NNMF with constraints. ๐Ÿ”ฅ


๐Ÿงฎ XRStools.xrs_utilities.NNMFcost_der

XRStools.xrs_utilities.NNMFcost_der(x, A, F, C, F_up, C_up, n, k, m)

(no description, she's the derivative, she doesn't need to explain herself ๐Ÿ’…)


๐Ÿงฎ XRStools.xrs_utilities.NNMFcost_old

XRStools.xrs_utilities.NNMFcost_old(x, A, W, H, W_up, H_up)

NNMFcost returns cost and gradient for NNMF with constraints โ€” but this is the old one. vintage edition, we still love her. ๐ŸŽ€


๐ŸŒŸ XRStools.xrs_utilities.Omega

XRStools.xrs_utilities.Omega(omega, degrees=True)

rotation around (0,0,1), pos sense. ๐ŸŒ€


๐ŸŒŸ XRStools.xrs_utilities.Phi

XRStools.xrs_utilities.Phi(phi, degrees=True)

rotation around (0,1,0), neg sense. (opposite direction, she's different like that ๐Ÿฆ‹)


๐Ÿ”„ XRStools.xrs_utilities.Rx

XRStools.xrs_utilities.Rx(chi, degrees=True)

Rx โ€” the rotation matrix for vector rotations around the [1,0,0]-direction. โœจ

Args:

  • chi (float) โ€” angle of rotation.
  • degrees (bool) โ€” angle given in radians or degrees.

Returns:

  • a 3x3 rotation matrix.

๐Ÿ”„ XRStools.xrs_utilities.Ry

XRStools.xrs_utilities.Ry(phi, degrees=True)

Ry โ€” the rotation matrix for vector rotations around the [0,1,0]-direction. ๐Ÿ’ซ

Args:

  • phi (float) โ€” angle of rotation.
  • degrees (bool) โ€” angle given in radians or degrees.
  • Returns: a 3x3 rotation matrix. ๐Ÿ’ซ

๐ŸŒ€ XRStools.xrs_utilities.TTsolver1D

okay bestie this one is A LOT but she's worth it, she's the whole Takagi-Taupin solver ๐Ÿ’–

XRStools.xrs_utilities.TTsolver1D(el_energy, hkl=[6, 6, 0],
       crystal='Si', R=1.0, dev=array([- 50., - 49., - 48., - 47., - 46., -
       45., - 44., - 43., - 42., - 41., - 40., - 39., - 38., - 37., - 36., -
       35., - 34., - 33., - 32., - 31., - 30., - 29., - 28., - 27., - 26., -
       25., - 24., - 23., - 22., - 21., - 20., - 19., - 18., - 17., - 16., -
       15., - 14., - 13., - 12., - 11., - 10., - 9., - 8., - 7., - 6., - 5., -
       4., - 3., - 2., - 1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.,
       12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25.,
       26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
       40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53.,
       54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67.,
       68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81.,
       82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95.,
       96., 97., 98., 99., 100., 101., 102., 103., 104., 105., 106., 107.,
       108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119.,
       120., 121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131.,
       132., 133., 134., 135., 136., 137., 138., 139., 140., 141., 142., 143.,
       144., 145., 146., 147., 148., 149.]), alpha=0.0,
       chitable_prefix='/home/christoph/sources/XRStools/data/chitables/chitable_')

TTsolver โ€” she solves the Takagi-Taupin equation for a bent crystal. โœจ

fr fr this one is based on a Matlab implementation by S. Huotari of M. Krisch's Fortran programs. legends only ๐Ÿ‘‘

Args:

  • el_energy (float): the fixed nominal (working) energy, in keV. ๐Ÿ“
  • hkl (array): the reflection order vector, like [6, 6, 0].
  • crystal (str): which crystal you're using โ€” can be silicon 'Si' or 'Ge'.
  • R (float): crystal bending radius in m.
  • dev (np.array): the deviation parameter (in arc. seconds) that the reflectivity curve should be calculated for.
  • alpha (float): crystal assymetry angle.

Returns:

  • refl (np.array): the reflectivity curve. ๐ŸŒˆ
  • e (np.array): deviation from Bragg angle in meV.
  • dev (np.array): deviation from Bragg angle in microrad.

๐Ÿซง XRStools.xrs_utilities.absCorrection(mu1, mu2, alpha, beta, samthick, geometry='transmission')

absCorrection โ€” she calculates the absorption correction for given mu1 and mu2, and you just multiply the measured spectrum by this correction factor. no cap. ๐Ÿ’…

this is a translation of Keijo Hamalainen's Matlab function (KH 30.05.96). giving archival realness.

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. ๐Ÿงš

๐ŸŒธ XRStools.xrs_utilities.abscorr2(mu1, mu2, alpha, beta, samthick)

Calculates the absorption correction for given mu1 and mu2. Multiply the measured spectrum with this correction factor. ๐ŸŽ€

also a translation of Keijo Hamalainen's Matlab function (KH 30.05.96). the sequel we deserved.

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)

ADDCH โ€” she adds the contents of given adjacent channels together. iconic behaviour tbh.

[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 ๐Ÿ•ฐ๏ธ

๐Ÿฆ‹ XRStools.xrs_utilities.bidiag_reduction(A)

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

the way she finds an upper bidiagonal matrix B so that A=U*B*V' with U,V orthogonal... and A is an m x n matrix. linear algebra girlies rise ๐Ÿงฎโœจ


๐Ÿ’œ XRStools.xrs_utilities.bootstrapCNNMF(A, F_ini, C_ini, F_up, C_up, Niter)

bootstrapCNNMF โ€” Constrained non-negative matrix factorization with bootstrapping for error estimates. yes she does errors too, she's multifaceted. ๐Ÿ˜Œ


๐ŸŒˆ XRStools.xrs_utilities.bootstrapCNNMF_old(A, k, Aerr, F_ini, C_ini, F_up, C_up, Niter=100)

bootstrapCNNMF โ€” Constrained non-negative matrix factorization with bootstrapping for error estimates. the _old version, still serving looks in the archive. ๐Ÿ’€


๐ŸŽ€ XRStools.xrs_utilities.bragg(hkl, e, xtal='Si')

% 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
%

Bragg angle for a given reflection, in RAD. hkl can be a matrix, i.e. hkl=[1,0,0 ; 1,1,1];, e is energy in keV, and xtal is 'Si', 'Ge', etc. (check dspace.m) or d0 (Si default). KH 28.09.93 ๐Ÿ•ฐ๏ธ


๐Ÿ‘‘ class XRStools.xrs_utilities.bragg_refl(crystal, hkl, alpha=0.0)

Bases: object

Dynamical theory of diffraction. the whole glow-up. โœจ

  • get_chi(energy, crystal=None, hkl=None)
  • get_nff(nff_path=None)
  • get_polarization_factor(tth, case='sigma') โ€” Calculate polarization factor.
  • get_reflectivity(energy, delta_theta, case='sigma')
  • get_reflectivity_bent(energy, delta_theta, R)

๐ŸŒŸ XRStools.xrs_utilities.braggd(hkl, e, xtal='Si')

# 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

same energy as bragg but she gives you the angle in deg. hkl can be a matrix, i.e. hkl=[1,0,0 ; 1,1,1];, e is energy in keV, xtal is 'Si', 'Ge', etc. (check dspace.m) or d0 (Si default). KH 28.09.93 ๐Ÿ’ซ


๐ŸงŠ XRStools.xrs_utilities.cNNMF_chris(A, W_fixed, W_free, maxIter=100, verbose=True)

no description in the source, she's just out here existing and we respect that. ๐Ÿซถ


๐Ÿš XRStools.xrs_utilities.cixsUBfind(x, G, Q_sample, wi, wo, lambdai, lambdao)

cixsUBfind โ€” that's the whole vibe, bestie.


๐ŸŒธ XRStools.xrs_utilities.cixsUBgetAngles_primo(Q)

primo โ€” first one up. ๐Ÿ’…


๐ŸŒธ XRStools.xrs_utilities.cixsUBgetAngles_secondo(Q)

secondo โ€” the sequel. ๐ŸŽ€


๐ŸŒธ XRStools.xrs_utilities.cixsUBgetAngles_terzo(Q)

terzo โ€” the trilogy finale. โœจ


๐Ÿฆ‹ XRStools.xrs_utilities.cixsUBgetQ_primo(tthv, tthh, psi)

she returns the Q0 given the detector position (tthv, tth) and th crystal orientation. this orientation is calculated considering:

  • the Bragg condition, and
  • the rotation around the G vector โ€” this rotation is defined by psi, which is a rotation around G. ๐Ÿ”„

๐Ÿฆ‹ XRStools.xrs_utilities.cixsUBgetQ_secondo(tthv, tthh, psi)

second verse, same energy. ๐Ÿ’œ


๐Ÿฆ‹ XRStools.xrs_utilities.cixsUBgetQ_terzo(tthv, tthh, psi)

and the third one, periodt. ๐ŸŒˆ


โญ XRStools.xrs_utilities.cixs_primo(tthv, tthh, psi, anal_braggd=86.5)

cixs_primo โ€” that's it, that's the entry. ๐Ÿซง


โญ XRStools.xrs_utilities.cixs_secondo(tthv, tthh, psi, anal_braggd=86.5)

cixs_secondo โ€” running it back. ๐Ÿซง


โญ XRStools.xrs_utilities.cixs_terzo(tthv, tthh, psi, anal_braggd=86.5)

cixs_terzo โ€” closing out the set. ๐Ÿซง


๐Ÿ’ซ XRStools.xrs_utilities.compute_matrix_elements(R1, R2, k, r)

no description in the source โ€” she computes matrix elements and minds her own business. ๐Ÿงš


๐ŸŒŸ XRStools.xrs_utilities.con2mat(x, W, H, W_up, H_up)

also flying under the radar in the original, no description given. still iconic. ๐Ÿ’–


๐Ÿ”ฅ XRStools.xrs_utilities.constrained_mf(A, W_ini, W_up, coeff_ini, coeff_up, maxIter=1000, tol=1e-08, maxIter_power=1000)

cfactorizeOffDiaMatrix โ€” the constrained version of factorizeOffDiaMatrix. Returns main components from an off-diagonal Matrix (energy-loss x angular-departure). she's giving structured decomposition energy. ๐Ÿ˜Œโœจ


๐Ÿ’œ XRStools.xrs_utilities.constrained_svd(M, U_ini, S_ini, VT_ini, U_up, max_iter=10000, verbose=False)

constrained_nnmf โ€” approximate singular value decomposition, but with constraints. ๐ŸŽ€

function [U, S, V] =
constrained_svd(M,U_ini,S_ini,V_ini,U_up,max_iter=10000,verbose=False)

๐Ÿš XRStools.xrs_utilities.convertSplitEDF2EDF(foldername)

she converts the old style EDF files (one image for horizontal and one image for vertical chambers) to the new style EDF (one single image). glow-up complete. ๐Ÿ’…

Arg:

  • foldername (str): path to folder with all the EDF-files to be converted.

๐ŸŒˆ XRStools.xrs_utilities.convg(x, y, fwhm)

Convolution with Gaussian:

  • x = x-vector
  • y = y-vector
  • fwhm = fulll width at half maximum of the gaussian with which y is convoluted ๐Ÿ“

๐Ÿฆ‹ XRStools.xrs_utilities.convtoprim(hklconv)

convtoprim converts diamond structure reciprocal lattice expressed in conventional lattice vectors to primitive one (the Helsinki -> Palaiseau conversion) from S. Huotari. international icon behaviour tbh ๐ŸŒ


๐Ÿ’ซ XRStools.xrs_utilities.cshift(w1, th)

cshift โ€” Calculates Compton peak position. ๐Ÿ”ฅ

Args:

  • w1 (float, array): Incident energy in [keV].
  • th (float): Scattering angle in [deg].

Returns:

  • w2 (foat, array): Energy of Compton peak in [keV].
Funktion adapted from Keijo Hamalainen. ๐Ÿ’œ

๐ŸŽ€ XRStools.xrs_utilities.delE_JohannAberration(E, A, R, Theta)

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].

Returns:

  • Johann abberation in [eV]. ๐ŸŒธ

XRStools.xrs_utilities.delE_dicedAnalyzerIntrinsic(E, Dw, Theta)

okay bestie this one is literally doing the math on the intrinsic energy resolution of a diced crystal analyzer ๐Ÿ’Ž no thoughts just diffraction.

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)

this one computes the off-Rowland contribution of a spherical analyzer crystal ๐ŸŒˆ she's giving geometry.

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 ๐Ÿ’ซ

XRStools.xrs_utilities.delE_pixelSize(E, p, R, Theta)

pixel size contribution to the resolution function of a diced analyzer crystal, aka the "how big are your pixels bestie" function ๐Ÿ”

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 ๐ŸŽ€

XRStools.xrs_utilities.delE_sourceSize(E, s, R, Theta)

source size contribution to the resolution function ๐Ÿซถ your source is not a point and she will remind you.

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 ๐ŸŒธ

XRStools.xrs_utilities.delE_stressedCrystal(E, t, v, R, Theta)

stress induced contribution to the resulution function of a spherically bent crystal analyzer ๐Ÿ˜ญ she's stressed, the crystal is stressed, we're all stressed.

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 ๐Ÿ’…

XRStools.xrs_utilities.diode(current, energy, thickness=0.03)

diode calculates the number of photons incident for a Si PIPS diode ๐Ÿ”ฅ photon counting era.

Args:

  • current (float) โ€” diode current in [pA].
  • energy (float) โ€” photon energy in [keV].
  • thickness (float) โ€” thickness of Si active layer in [cm].

Returns:

  • flux (float) โ€” number of photons per second.

function adapted from Matlab function by S. Huotari ๐Ÿซก


XRStools.xrs_utilities.dspace(hkl=[6, 6, 0], xtal='Si')

this one's original docstring, verbatim, because I refuse to touch it:

% 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

periodt. ๐Ÿ’–


class XRStools.xrs_utilities.dtxrd(hkl, energy, crystal='Si', asym_angle=0.0, angular_range=[- 0.0005, 0.0005], angular_step=1e-08)

Bases: object

class to hold all things dynamic theory of diffraction ๐Ÿ‘‘ she contains multitudes.

Methods:

  • get_anomalous_absorption(energy=None)
  • get_eta(angular_range, angular_step=1e-08)
  • get_extinction_length(energy=None)
  • get_reflection_width()
  • get_reflectivity(angular_range=None, angular_step=None)
  • set_asymmetry(alpha) โ€” negative alpha -> more grazing incidence ๐Ÿฆ‹
  • set_energy(energy)
  • set_hkl(hkl)

XRStools.xrs_utilities.dtxrd_anomalous_absorption(energy, hkl, alpha=0.0, crystal='Si', angular_range=array([- 0.0005]))

just the signature bestie, the docstring is a mystery ๐ŸŒซ๏ธ


XRStools.xrs_utilities.dtxrd_extinction_length(energy, hkl, alpha=0.0, crystal='Si')

signature only, no notes ๐Ÿ’€


XRStools.xrs_utilities.dtxrd_reflectivity(energy, hkl, alpha=0.0, crystal='Si', angular_range=array([- 0.0005]))

signature only again, she's keeping it mysterious ๐Ÿ™ˆ


XRStools.xrs_utilities.e2pz(w1, w2, th)

calculates the momentum scale and the relativistic Compton cross section correction according to P. Holm, PRA 37, 3706 (1988) ๐Ÿ“š

this function is translated from Keijo Hamalainen's Matlab implementation (KH 29.05.96) ๐Ÿซก

Args:

  • w1 (float or np.array) โ€” incident energy in [keV]
  • w2 (float or np.array) โ€” scattered energy in [keV]
  • th (float) โ€” scattering angle two theta in [deg]

returns:

  • pz (float or np.array) โ€” momentum scale in [a.u.]
  • cf (float or np.array) โ€” cross section correction factor such that: J(pz) = cf * d^2(sigma)/d(w2)*d(Omega) [barn/atom/keV/srad]

XRStools.xrs_utilities.edfread(filename)

reads edf-file with filename "filename"

OUTPUT: data = 256x256 numpy array ๐Ÿ“ธ


XRStools.xrs_utilities.edfread_test(filename)

reads edf-file with filename "filename"

OUTPUT: data = 256x256 numpy array

here is how i opened the HH data:

data = np.fromfile(f,np.int32)
image = np.reshape(data,(dim,dim))

ngl this is giving "notes app at 3am" energy but it works ๐Ÿ“


XRStools.xrs_utilities.element(z)

converts atomic number into string of the element symbol and vice versa ๐Ÿ”

returns atomic number of given element, if z is a string of the element symbol or string of element symbol of given atomic number z.

Args:

  • z (string or int) โ€” string of the element symbol or atomic number.

Returns:

  • Z (string or int) โ€” string of the element symbol or atomic number.

XRStools.xrs_utilities.energy(d, ba)

original docstring, untouched, because look at those % signs:

% 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

XRStools.xrs_utilities.energy_monoangle(angle, d=1.6374176589984608)

same deal, docstring verbatim:

% 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
%

XRStools.xrs_utilities.fermi(rs)

fermi calculates the plasmon energy (in eV), Fermi energy (in eV), Fermi momentum (in a.u.), and critical plasmon cut-off vector (in a.u.) โš›๏ธ

Args:

  • rs (float) โ€” electron separation parameter

Returns:

  • wp (float) โ€” plasmon energy (in eV)
  • ef (float) โ€” Fermi energy (in eV)
  • kf (float) โ€” Fermi momentum (in a.u.)
  • kc (float) โ€” critical plasmon cut-off vector (in a.u.)

based on Matlab function from A. Soininen ๐Ÿซถ


XRStools.xrs_utilities.find_center_of_mass(x, y)

returns the center of mass (first moment) for the given curve y(x) ๐ŸŽฏ


XRStools.xrs_utilities.find_diag_angles(q, x0, U, B, Lab, beam_in, lambdai, lambdao, tol=1e-08, method='BFGS')

find_diag_angles finds the FOURC spectrometer and sample angles for a desired q ๐Ÿ”ฎ optimization girlie behavior.

Args:

  • q (array) โ€” desired momentum transfer in Lab coordinates.
  • x0 (list) โ€” guesses for the angles (tthv, tthh, chi, phi, omega).
  • U (array) โ€” 3x3 U-matrix Lab-to-sample transformation.
  • B (array) โ€” 3x3 B-matrix reciprocal lattice to absolute units transformation.
  • lambdai (float) โ€” incident x-ray wavelength in Angstrom.
  • lambdao (float) โ€” scattered x-ray wavelength in Angstrom.
  • tol (float) โ€” Toleranz for minimization (see scipy.optimize.minimize)
  • method (str) โ€” method for minimization (see scipy.optimize.minimize)

Returns:

  • ans (array) โ€” tthv, tthh, phi, chi, omega ๐Ÿ’ซ

XRStools.xrs_utilities.fwhm(x, y)

finds full width at half maximum of the curve y vs. x

returns f = FWHM, x0 = position of the maximum ๐Ÿ“


XRStools.xrs_utilities.gauss(x, x0, fwhm)

no description given bestie, she's just vibing ๐ŸŒธ


XRStools.xrs_utilities.get_UB_Q(tthv, tthh, phi, chi, omega, **kwargs)

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 ๐Ÿ”‘

Args:

  • tthv (float) โ€” spectrometer vertical 2Theta angle.
  • tthh (float) โ€” spectrometer horizontal 2Theta angle.
  • chi (float) โ€” sample rotation around x-direction.
  • phi (float) โ€” sample rotation around y-direction.
  • omega (float) โ€” sample rotation around z-direction.
  • kwargs (dict) โ€” dictionary with key-word arguments:
    • kwargs['U'] (array) โ€” 3x3 U-matrix Lab-to-sample transformation.
    • kwargs['B'] (array) โ€” 3x3 B-matrix reciprocal lattice to absolute units transformation.
    • kwargs['lambdai'] (float) โ€” incident x-ray wavelength in Angstrom.
    • kwargs['lambdao'] (float) โ€” scattered x-ray wavelength in Angstrom.

Returns:

  • Q_sample (array) โ€” momentum transfer in sample coordinates.
  • Ki_sample (array) โ€” incident beam direction in sample coordinates.
  • Ko_sample (array) โ€” scattered beam direction in sample coordinates. ๐ŸŽ€

XRStools.xrs_utilities.get_gnuplot_rgb(start=None, end=None, length=None)

get_gnuplot_rgb prints out a progression of RGB hex-keys to use in Gnuplot ๐ŸŒˆ aesthetic plotting era.

Args:

  • start (array) โ€” RGB code to start from (must be numbers out of [0,1]).
  • end (array) โ€” RGB code to end at (must be numbers out of [0,1]).
  • length (int) โ€” how many colors to print out.

๐Ÿ’ซ XRStools.xrs_utilities.get_num_of_MD_steps(time_ps, time_step) ๐Ÿ’ซ

bestie you wanna run an MD sim for a certain amount of time but the integrator only speaks in steps?? say less, this one does the conversion math for you ๐Ÿงฎโœจ

it calculates the number of steps in an MD simulation for a desired time (in ps) and a given step size (in a.u.)

Args:

  • time_ps (float): desired time span (ps). โณ
  • time_step (float): chosen time step (a.u.).

Returns:

  • the number of steps required to span the desired time span. that's it that's the whole vibe ๐Ÿ’…

๐ŸŒธ XRStools.xrs_utilities.getpenetrationdepth(energy, formulas, concentrations, densities) ๐ŸŒธ

returns the penetration depth of a mixture of chemical formulas with certain concentrations and densities. lowkey essential if you're wondering how deep your beam actually gets in ๐Ÿซถ


๐Ÿฆ‹ XRStools.xrs_utilities.gettransmission(energy, formulas, concentrations, densities, thickness) ๐Ÿฆ‹

returns the transmission through a sample composed of chemical formulas with certain densities mixed to certain concentrations, and a thickness. yes bestie, you need the thickness, don't forget it ๐Ÿ˜ญ


๐ŸŽ€ XRStools.xrs_utilities.hex2rgb(hex_val) ๐ŸŽ€

no description given, it just does its little hex-to-rgb thing and minds its own business ๐Ÿ’… (iconic honestly)


โญ XRStools.xrs_utilities.hlike_Rwfn(n, l, r, Z) โญ

hlike_Rwfn returns an array with the radial part of a hydrogen-like wave function. quantum physics but make it cute ๐Ÿงš

Args:

  • n (integer): main quantum number n
  • l (integer): orbitalquantum number l
  • r (array): vector of radii on which the function should be evaluated
  • Z (float): effective nuclear charge

๐Ÿ’œ XRStools.xrs_utilities.householder(b, k) ๐Ÿ’œ

the docstring is giving vintage Matlab energy and we're keeping every crumb of it, no cap:

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

so basically: b is a column vector, k is an index that's strictly less than length(b), and it constructs a matrix H that annihilates entries in the product H*b below index k. also shoutout Atkinson Section 9.3, p. 611 ๐Ÿ“š and M. M. Sussman, we see you ๐Ÿ‘‘


๐ŸŒˆ XRStools.xrs_utilities.interpolate_M(xc, xi, yi, i0) ๐ŸŒˆ

linear interpolation scheme after Martin Sundermann that conserves the absolute number of counts. it's giving "physics with a conscience" fr fr.

๐Ÿšจ ONLY WORKS FOR EQUALLY/EVENLY SPACED XC, XI! like literally do not try it otherwise bestie, it will not eat.

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.

and then there's this lil scipy snippet living at the bottom of the docstring, just vibing:

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)

๐Ÿ”ฅ XRStools.xrs_utilities.is_allowed_refl_fcc(H) ๐Ÿ”ฅ

is_allowed_refl_fcc checks if a given reflection is allowed for an FCC lattice. vibe check for your diffraction peaks โœจ

Args:

  • H (array, list, tuple): H=[h,k,l]

Returns:

  • boolean

๐Ÿ’– XRStools.xrs_utilities.lindhard_pol(q, w, rs=3.93, use_corr=False, lifetime=0.28) ๐Ÿ’–

lindhard_pol calculates the Lindhard polarizability function (RPA) for certain q (a.u.), w (a.u.) and rs (a.u.). yes the RPA one, the real one, we love her ๐Ÿ˜Œ

Args:

  • q (float): momentum transfer (in a.u.)
  • w (float): energy (in a.u.)
  • rs (float): electron parameter
  • use_corr (boolean): if True, uses Bernardo's calculation for n(k) instead of the Fermi function.
  • lifetime (float): life time (default is 0.28 eV for Na).

based on a Matlab function by S. Huotari ๐Ÿซถ


๐Ÿ“ XRStools.xrs_utilities.makeprofile(element, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat', E0=9.69, tth=35.0, correctasym=None) ๐Ÿ“

takes the profiles from makepzprofile(), converts them onto the eloss scale, and normalizes them to S(q,w) [1/eV]. glow-up pipeline for your Compton profiles ๐Ÿ’…

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.]

๐Ÿงš XRStools.xrs_utilities.makeprofile_comp(formula, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat', E0=9.69, tth=35, correctasym=None) ๐Ÿงš

returns the compton profile of a chemical compound with formula 'formula'. it's giving compound queen ๐Ÿ‘‘

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.]

๐Ÿ‘‘ XRStools.xrs_utilities.makeprofile_compds(formulas, concentrations=None, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat', E0=9.69, tth=35.0, correctasym=None) ๐Ÿ‘‘

returns the sum of compton profiles from a lost of chemical compounds weighted by the given concentration. (yes it says "a lost of" in the original and honestly? relatable typo, we're leaving it ๐Ÿซถ) it's a whole ensemble cast of compounds, weighted and summed, main character energy only โœจ


๐ŸŒธ XRStools.xrs_utilities.makepzprofile(element, filename='/usr/lib/python3/dist-packages/XRStools/resources/data/ComptonProfiles.dat') ๐ŸŒธ

constructs compton profiles of element 'element' on the pz-scale (-100:100 a.u.) from the Biggs tables provided in 'filename'. museum-grade data but make it useful ๐Ÿ›๏ธ

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

๐ŸŒˆ XRStools.xrs_utilities.mat2con(W, H, W_up, H_up) ๐ŸŒˆ

no description, it just converts and slays ๐Ÿ’…


โญ XRStools.xrs_utilities.mat2vec(F, C, F_up, C_up, n, k, m) โญ

also no description, also just does its thing. quiet but essential, we respect it ๐Ÿคซ


๐ŸŽ€ class XRStools.xrs_utilities.maxipix_det(name, spot_arrangement) ๐ŸŽ€

Bases: object

class to store some useful values from the detectors used. to be used for arranging the ROIs. it's the little storage locker for your detector lore ๐Ÿ“ฆโœจ

Methods:

  • get_det_name()
  • get_pixel_range()

๐Ÿ’ซ XRStools.xrs_utilities.momtrans_au(e1, e2, tth) ๐Ÿ’ซ

calculates the momentum transfer in atomic units. the physics conversion bestie we all needed ๐Ÿงฎ

input:

  • e1 = incident energy [keV]
  • e2 = scattered energy [keV]
  • tth = scattering angle [deg]

returns:

  • q = momentum transfer [a.u.] (corresponding to sin(th)/lambda)

๐Ÿ’œ XRStools.xrs_utilities.momtrans_inva(e1, e2, tth) ๐Ÿ’œ

calculates the momentum transfer in inverse angstrom. same energy, different unit, still iconic โœจ

input:

  • e1 = incident energy [keV]
  • e2 = scattered energy [keV]
  • tth = scattering angle [deg]

returns:

  • q = momentum transfer [a.u.] (corresponding to sin(th)/lambda)

๐Ÿ”ฅ XRStools.xrs_utilities.mpr(energy, compound) ๐Ÿ”ฅ

calculates the photoelectric, elastic, and inelastic absorption of a chemical compound.

calculates the photoelectric, elastic, and inelastic absorption of a chemical compound.

(not a typo bestie, the docstring literally says it twice. the way she said it once and then said it again for the people in the back ๐Ÿ˜ญ periodt)

Args:

  • energy (np.array): energy scale in [keV].
  • compound (string): chemical sum formula (e.g. 'SiO2')

Returns:

  • murho (np.array): absorption coefficient normalized by the density.
  • rho (float): density in UNITS?
  • m (float): atomic mass in UNITS?

๐Ÿฆ‹ XRStools.xrs_utilities.mpr_compds(energy, formulas, concentrations, E0, rho_formu) ๐Ÿฆ‹

calculates the photoelectric, elastic, and inelastic absorption of a mix of compounds.

returns the photoelectric absorption for a sum of different chemical compounds.

Args:

  • energy (np.array): energy scale in [keV].
  • formulas (list of strings): list of chemical sum formulas

Returns:

  • murho (np.array): absorption coefficient normalized by the density.
  • rho (float): density in UNITS?
  • m (float): atomic mass in UNITS?

๐Ÿ“ XRStools.xrs_utilities.myprho(energy, Z, logtablefile='/usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat') ๐Ÿ“

calculates the photoelectric, elastic, and inelastic absorption of an element Z.

calculates the photelectric, elastic, and inelastic absorption of an element Z. Z can be atomic number or element symbol. (yes it says "photelectric" in the original, we're keeping the typo, it's part of her charm ๐Ÿ’…)

Args:

  • energy (np.array): energy scale in [keV].
  • Z (string or int): atomic number or string of element symbol.

Returns:

  • murho (np.array): absorption coefficient normalized by the density.
  • rho (float): density in UNITS?
  • m (float): atomic mass in UNITS?

๐ŸŒธ XRStools.xrs_utilities.nonzeroavg(y=None) ๐ŸŒธ

no description given, just vibes and a default argument ๐Ÿซถ


โญ XRStools.xrs_utilities.odefctn(y, t, abb0, abb1, abb7, abb8, lex, sgbeta, y0, c1) โญ

the docstring here is pure vintage Matlab copy-paste, and we are preserving it like a museum piece ๐Ÿ›๏ธ:

#%    [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.

๐Ÿ’– XRStools.xrs_utilities.odefctn_CN(yCN, t, abb0, abb1, abb7, abb8N, lex, sgbeta, y0, c1) ๐Ÿ’–

no description. she's the CN-flavored sibling and she's mysterious like that ๐Ÿคซโœจ


๐Ÿ‘‘ XRStools.xrs_utilities.parseformula(formula) ๐Ÿ‘‘

parses a chemical sum formula. turning your cute little formula string into actual data, we love a translator ๐Ÿ’…

parses the constituing elements and stoichiometries from a given chemical sum formula.

Args:

  • formula (string): string of a chemical formula (e.g. 'SiO2', 'Ba8Si46', etc.)

Returns:

  • elements (list): list of strings of constituting elemental symbols.
  • stoichiometries (list): list of according stoichiometries in the same order as 'elements'.

๐ŸŒˆ XRStools.xrs_utilities.plotpenetrationdepth(energy, formulas, concentrations, densities) ๐ŸŒˆ

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. yes bestie, it actually opens a window, go look at it ๐Ÿ‘€๐Ÿ“ˆ


๐ŸŽ€ XRStools.xrs_utilities.plottransmission(energy, formulas, concentrations, densities, thickness) ๐ŸŽ€

opens a plot with the transmission plotted along the given energy vector. pretty graph, go stare ๐Ÿซถ


๐Ÿ’ซ XRStools.xrs_utilities.primtoconv(hklprim) ๐Ÿ’ซ

primtoconv converts diamond structure reciprocal lattice expressed in primitive basis to the conventional basis (Palaiseau -> Helsinki conversion) from S. Huotari. it's a whole little pilgrimage from Palaiseau to Helsinki and honestly? we're obsessed with the lore ๐Ÿงณโœจ

XRStools.xrs_utilities.pz2e1(w2, pz, th)

ok so this one is the incident energy calculator โœจ it figures out the incident energy for a specific scattered photon and momentum value.

Basically: you hand it a photon energy and a scattering angle, it hands you back the incident energy. This function is a translation of Keijo Hamalainen's Matlab implementation (KH 29.05.96). iykyk

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')

read_dft_wfn parses radial parts of wavefunctions ๐Ÿฆ‹ like it's reading your soul but make it quantum.

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.

Returns:

  • r (np.array) โ€” radius
  • wfn (np.array) โ€”
yes bestie, wfn's description is literally just blank in the original. we leave it blank. no notes. ๐Ÿ’€

XRStools.xrs_utilities.readbiggsdata(filename, element)

Reads the 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 according shells
    • colnames = strings of column names as used in the file

XRStools.xrs_utilities.readfio(prefix, scannumber, repnumber=0)

two moods, one function ๐ŸŽ€

  • if repnumber = 0: reads a spectra-file (name: prefix_scannumber.fio)
  • if repnumber > 1: reads a spectra-file (name: prefix_scannumber_rrepnumber.fio)

XRStools.xrs_utilities.readp01image(filename)

reads a detector file from PetraIII beamline P01 ๐Ÿ‘‘


XRStools.xrs_utilities.readp01scan(prefix, scannumber)

reads a whole scan from PetraIII beamline P01 (experimental) ๐Ÿงช


XRStools.xrs_utilities.readp01scan_rep(prefix, scannumber, repetition)

reads a whole scan with repititions from PetraIII beamline P01 (experimental) ๐Ÿงช๐Ÿฆ‹


XRStools.xrs_utilities.savitzky_golay(y, window_size, order, deriv=0, rate=1)

Smooth (and optionally differentiate) data with a Savitzky-Golay filter. This filter removes high frequency noise from data. Its whole flex is that it preserves the original shape and features of the signal better than other filtering approaches, like moving averages techniques. it's giving main character filter. โœจ

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.

Examples

t = np.linspace(-4, 4, 500)
y = np.exp( -t**2 ) + np.random.normal(0, 0.05, t.shape)
ysg = savitzky_golay(y, window_size=31, order=4)
import matplotlib.pyplot as plt
plt.plot(t, y, label='Noisy signal')
plt.plot(t, np.exp(-t**2), 'k', lw=1.5, label='Original signal')
plt.plot(t, ysg, 'r', label='Filtered signal')
plt.legend()
plt.show()

References ::

[1]  A. Savitzky, M. J. E. Golay, Smoothing and Differentiation
     of Data by Simplified Least Squares Procedures. Analytical
     Chemistry, 1964, 36 (8), pp 1627-1639.

[2]  Numerical Recipes 3rd Edition: The Art of Scientific
     Computing W.H. Press, S.A. Teukolsky, W.T. Vetterling, B.P.
     Flannery Cambridge University Press ISBN-13: 9780521880688

XRStools.xrs_utilities.sgolay2d(z, window_size, order, derivative=None)

that's it. that's the whole entry. no description, no args list, nothing. mysterious icon behavior ๐Ÿ’…


XRStools.xrs_utilities.sigmainc(Z, energy, logtablefile='/usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat')

sigmainc Calculates the Incoherent Scattering Cross Section in cm^2/g using Log-Log Fit. ๐Ÿ”ฅ

Args:

  • z (int or string) โ€” Element number or elements symbol.
  • energy (float or array) โ€” Energy (can be number or vector)

Returns:

  • tau (float or array) โ€” Photoelectric cross section in [cm**2/g]

Adapted from original Matlab function of Keijo Hamalainen. ๐Ÿซถ


XRStools.xrs_utilities.specread(filename, nscan)

reads scan "nscan" from SPEC-file "filename" ๐ŸŒธ

INPUT:

  • filename = string with the SPEC-file name
  • nscan = number (int) of desired scan

OUTPUT:

  • data =
  • motors =
  • counters = dictionary
data and motors are justโ€ฆ vibes. blank in the original. we respect the mystery. ๐Ÿ™ˆ

XRStools.xrs_utilities.spline2(x, y, x2)

Extrapolates the smaller and larger valuea as a constant ๐ŸŒˆ

(yes, "valuea". we're keeping it. it's iconic. it's the original's typo and we love her.)

XRStools.xrs_utilities.split_hdf5_address(dataadress)

no description given, bestie. she simply exists. โœจ๐Ÿ’€


XRStools.xrs_utilities.stiff_compl_matrix_Si(e1, e2, e3, ansys=False)

stiff_compl_matrix_Si returns the stiffness 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. ๐Ÿ“š


XRStools.xrs_utilities.sumx(A)

Short-hand command to sum over 1st dimension of a N-D matrix (N>2) and to squeeze it to N-1-D matrix. convenient queen ๐Ÿ‘‘


XRStools.xrs_utilities.svd_my(M, maxiter=100, eta=0.1)

another one with zero description. we love a lowkey legend. ๐Ÿ’…โœจ


XRStools.xrs_utilities.taupgen(e, hkl=[6, 6, 0], crystals='Si', R=1.0, dev=array([...]), alpha=0.0)

okay this signature is enormous so here it is in full, exactly as she is, no cap:

XRStools.xrs_utilities.taupgen(e, hkl=[6, 6, 0], crystals='Si', R=1.0,
dev=array([- 50., - 49., - 48., - 47., - 46., - 45., - 44., - 43., -
42., - 41., - 40., - 39., - 38., - 37., - 36., - 35., - 34., - 33., -
32., - 31., - 30., - 29., - 28., - 27., - 26., - 25., - 24., - 23., -
22., - 21., - 20., - 19., - 18., - 17., - 16., - 15., - 14., - 13., -
12., - 11., - 10., - 9., - 8., - 7., - 6., - 5., - 4., - 3., - 2., - 1.,
0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15.,
16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43.,
44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55., 56., 57.,
58., 59., 60., 61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 71.,
72., 73., 74., 75., 76., 77., 78., 79., 80., 81., 82., 83., 84., 85.,
86., 87., 88., 89., 90., 91., 92., 93., 94., 95., 96., 97., 98., 99.,
100., 101., 102., 103., 104., 105., 106., 107., 108., 109., 110., 111.,
112., 113., 114., 115., 116., 117., 118., 119., 120., 121., 122., 123.,
124., 125., 126., 127., 128., 129., 130., 131., 132., 133., 134., 135.,
136., 137., 138., 139., 140., 141., 142., 143., 144., 145., 146., 147.,
148., 149.]), alpha=0.0)

and here's the docstring, verbatim, % signs and all, because it's a whole mood:

% 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

calculates the reflectivity curves of bent crystals ๐Ÿ’– and yes, complaints go straight to /dev/null, the author said what they said and honestly? respect. ๐Ÿซถ๐Ÿ‘‘

taupgen_amplitude โœจ

bestie this one comes with a whole-ahh call example attached, so here it is, character for character, no edits, I would never:

XRStools.xrs_utilities.taupgen_amplitude(e, hkl=[6, 6, 0],
crystals='Si', R=1.0, dev=array([- 50., - 49., - 48., - 47., - 46., -
45., - 44., - 43., - 42., - 41., - 40., - 39., - 38., - 37., - 36., -
35., - 34., - 33., - 32., - 31., - 30., - 29., - 28., - 27., - 26., -
25., - 24., - 23., - 22., - 21., - 20., - 19., - 18., - 17., - 16., -
15., - 14., - 13., - 12., - 11., - 10., - 9., - 8., - 7., - 6., - 5., -
4., - 3., - 2., - 1., 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11.,
12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25.,
26., 27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53.,
54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67.,
68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81.,
82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95.,
96., 97., 98., 99., 100., 101., 102., 103., 104., 105., 106., 107.,
108., 109., 110., 111., 112., 113., 114., 115., 116., 117., 118., 119.,
120., 121., 122., 123., 124., 125., 126., 127., 128., 129., 130., 131.,
132., 133., 134., 135., 136., 137., 138., 139., 140., 141., 142., 143.,
144., 145., 146., 147., 148., 149.]), alpha=0.0)

and then the source's own little notes, which I am pasting in exactly because they're part of the lore:

% 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

"Complaints -> /dev/null" is genuinely iconic and I think about it daily. ๐Ÿ’€ Anyway: the parameters are 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 โ€” a vector โ€” optional) and alpha (asymmetry angle). Based on a FORTRAN program of Michael Krisch, translitterated to Matlab by Simo Huotari in 2006 and 2007. It knows it's not good matlab writing. It said so. Respect. ๐Ÿซถ


tauphoto ๐ŸŽ€

XRStools.xrs_utilities.tauphoto(Z, energy,
logtablefile='/usr/lib/python3/dist-packages/XRStools/resources/data/logtable.dat')

tauphoto calculates Photoelectric Cross Section in cm^2/g using Log-Log Fit. slay.

Args:

  • z (int or string) โ€” element number or elements symbol.
  • energy (float or array) โ€” energy (can be number or vector).

Returns:

  • tau (float or array) โ€” photoelectric cross section in [cm**2/g].

Adapted from the original Matlab function of Keijo Hamalainen. ๐Ÿ’œ


unconstrained_mf ๐Ÿฆ‹

XRStools.xrs_utilities.unconstrained_mf(A, numComp=3, maxIter=1000,
tol=1e-08)

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. lowkey elegant, ngl.


vangle ๐ŸŒธ

XRStools.xrs_utilities.vangle(v1, v2)

vangle calculates the angle between two cartesian vectors v1 and v2 in degrees.

Args:

  • v1 (np.array) โ€” first vector.
  • v2 (np.array) โ€” second vector.

Returns:

  • th (float) โ€” angle between first and second vector.

Function by S. Huotari, adopted for Python. ๐Ÿซถ


vec2mat

XRStools.xrs_utilities.vec2mat(x, F, C, F_up, C_up, n, k, m)

that's it. that's the whole entry. no description, no args, no returns โ€” just the signature serving absolute main character energy. ๐Ÿ‘‘


vrot ๐ŸŒˆ

XRStools.xrs_utilities.vrot(v, vaxis, phi)

vrot rotates a vector around a given axis.

Args:

  • v (np.array) โ€” vector to be rotated
  • vaxis (np.array) โ€” rotation axis
  • phi (float) โ€” angle [deg] respecting the right-hand rule

Returns:

  • v2 (np.array) โ€” new rotated vector

Function by S. Huotari (2007) adopted to Python. โœจ


vrot2 ๐Ÿงš

XRStools.xrs_utilities.vrot2(vector1, vector2, angle)

rotMatrix rotates vector1 around vector2 by an angle. (yes the function is vrot2 and the one-liner says rotMatrix, that's just how it is, I don't make the rules ๐Ÿ’…)


xas_fluo_correct ๐Ÿ’–

XRStools.xrs_utilities.xas_fluo_correct(ene, mu, formula, fluo_ene,
edge_ene, angin, angout)

xas_fluo_correct โ€” fluorescence yield over-absorption correction as in Larch/Athena. see: https://www3.aps.anl.gov/haskel/FLUO/Fluo-manual.pdf

Args:

  • ene (np.array) โ€” energy axis in [keV]
  • mu (np.array) โ€” measured fluorescence spectrum
  • formula (str) โ€” chemical sum formulas (e.g. 'SiO2')
  • fluo_ene (float) โ€” energy in keV of main fluorescence line
  • edge_ene (float) โ€” edge energy in [keV]
  • angin (float) โ€” incidence angle (relative to sample normal) [deg.]
  • angout (float) โ€” exit angle (relative to sample normal) [deg.]

Returns:

  • ene (np.array) โ€” energy axis in [keV]
  • mu_corr (np.array) โ€” corrected fluorescence spectrum

XRStools.roifinder_and_gui Module ๐ŸŽ€

  • genindex
  • modindex
  • search

and that's the whole module listing, bestie. short and sweet, it's giving minimalist. ๐ŸŒธ


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Christoph Sahle, Alessandro Mirone


2022, Christoph Sahle, Alessandro Mirone


okay that's a wrap on the WHOLE page, we did it, 25 parts of pure Unix yapping and you stayed the entire time, I'm so proud of you fr fr ๐Ÿซถโœจ This beauty is XRSTOOLS(1), and it's dated Jan 13, 2022. go forth and rotate some vectors, mwah ๐Ÿ’…๐Ÿ’–

๐Ÿ“ฆ where this page comes from