TRXASprefitpack.mathfun package

Module contents

mathfun: subpackage for the mathematical functions for TRXASprefitpack

copyright

2021-2022 by pistack (Junho Lee).

license

LGPL3.

TRXASprefitpack.mathfun.calc_eta(fwhm_G: float, fwhm_L: float) float[source]

Calculate eta of pseudo voigt profile with fwhm_G, fwhm_L based on Journal of Applied Crystallography. 33 (6): 1311–1316.

Parameters
  • fwhm_G – full width at half maximum of gaussian part

  • fwhm_L – full width at half maximum of lorenzian part

Returns

maxing parameter eta

TRXASprefitpack.mathfun.cauchy_irf(t: Union[float, ndarray], fwhm: float) Union[float, ndarray][source]

Compute lorenzian shape irf function

Parameters
  • t – time

  • fwhm – full width at half maximum of cauchy distribution

Returns

normalized lorenzian function.

TRXASprefitpack.mathfun.compute_model(t: ndarray, eigval: ndarray, V: ndarray, c: ndarray) ndarray[source]

Compute solution of the system of rate equations solved by solve_model Note: eigval, V, c should be obtained from solve_model

Parameters
  • t – time

  • eigval – eigenvalue for equation

  • V – eigenvectors for equation

  • c – coefficient

Returns

solution of rate equation

Note

eigval, V, c should be obtained from solve_model.

TRXASprefitpack.mathfun.compute_signal_cauchy(t: ndarray, fwhm: float, eigval: ndarray, V: ndarray, c: ndarray) ndarray[source]

Compute solution of the system of rate equations solved by solve_model convolved with normalized cauchy distribution

Parameters
  • t – time

  • fwhm – full width at half maximum of normalized cauchy distribution

  • eigval – eigenvalue for equation

  • V – eigenvectors for equation

  • c – coefficient

Returns

Convolution of solution of rate equation and normalized cauchy distribution

Note

eigval, V, c should be obtained from solve_model.

TRXASprefitpack.mathfun.compute_signal_gau(t: ndarray, fwhm: float, eigval: ndarray, V: ndarray, c: ndarray) ndarray[source]

Compute solution of the system of rate equations solved by solve_model convolved with normalized gaussian distribution

Parameters
  • t – time

  • fwhm – full width at half maximum of normalized gaussian distribution

  • eigval – eigenvalue for equation

  • V – eigenvectors for equation

  • c – coefficient

Returns

Convolution of solution of rate equation and normalized gaussian distribution

Note

eigval, V, c should be obtained from solve_model.

TRXASprefitpack.mathfun.compute_signal_pvoigt(t: ndarray, fwhm_G: float, fwhm_L: float, eta: float, eigval: ndarray, V: ndarray, c: ndarray) ndarray[source]

Compute solution of the system of rate equations solved by solve_model convolved with normalized pseudo voigt profile

\[\mathrm{pvoigt}(t) = (1-\eta) G(t) + \eta L(t),\]

G(t) stands for normalized gaussian, L(t) stands for normalized cauchy(lorenzian) distribution

Parameters
  • t – time

  • fwhm_G – full width at half maximum of gaussian part

  • fwhm_L – full width at half maximum of cauchy part

  • eta – mixing parameter

  • eigval – eigenvalue for equation

  • V – eigenvectors for equation

  • c – coefficient

Returns

Convolution of solution of rate equation and normalized pseudo voigt profile.

Note

eigval, V, c should be obtained from solve_model.

TRXASprefitpack.mathfun.dmp_osc_conv(t: ndarray, fwhm: Union[float, ndarray], tau: ndarray, T: ndarray, phase: ndarray, c: ndarray, irf: Optional[str] = 'g', eta: Optional[float] = None) ndarray[source]

Constructs convolution of sum of damped oscillation and instrumental response function Supported instrumental response function are

  • g: gaussian distribution

  • c: cauchy distribution

  • pv: pseudo voigt profile

Parameters
  • t – time

  • fwhm – full width at half maximum of instrumental response function

  • tau – lifetime of vibration

  • T – period of vibration

  • phase – phase factor

  • c – coefficient for each damping oscillation component

  • irf

    shape of instrumental response function [default: g]

    • ’g’: normalized gaussian distribution,

    • ’c’: normalized cauchy distribution,

    • ’pv’: pseudo voigt profile \((1-\eta)g + \eta c\)

  • eta – mixing parameter for pseudo voigt profile (only needed for pseudo voigt profile, default value is guessed according to Journal of Applied Crystallography. 33 (6): 1311–1316.)

Returns

Convolution of sum of damped oscillation and instrumental response function.

Note

fwhm For gaussian and cauchy distribution, only one value of fwhm is needed, so fwhm is assumed to be float However, for pseudo voigt profile, it needs two value of fwhm, one for gaussian part and the other for cauchy part. So, in this case, fwhm is assumed to be numpy.ndarray with size 2.

TRXASprefitpack.mathfun.dmp_osc_conv_cauchy(t: Union[float, ndarray], fwhm: float, k: float, T: float, phase: float) Union[float, ndarray][source]

Compute damped oscillation convolved with normalized cauchy distribution

Parameters
  • t – time

  • fwhm – full width at half maximum of cauchy distribution

  • k – damping constant (inverse of life time)

  • T – period of vibration

  • phase – phase factor

Returns

Convolution of normalized cauchy distribution and damped oscillation \((\exp(-kt)cos(2\pi t/T+phase))\).

TRXASprefitpack.mathfun.dmp_osc_conv_gau(t: Union[float, ndarray], fwhm: float, k: float, T: float, phase: float) Union[float, ndarray][source]

Compute damped oscillation convolved with normalized gaussian distribution

Parameters
  • t – time

  • fwhm – full width at half maximum of gaussian distribution

  • k – damping constant (inverse of life time)

  • T – period of vibration

  • phase – phase factor

Returns

Convolution of normalized gaussian distribution and damped oscillation \((\exp(-kt)cos(2\pi t/T+phase))\).

TRXASprefitpack.mathfun.dmp_osc_conv_pvoigt(t: Union[float, ndarray], fwhm_G: float, fwhm_L: float, eta: float, k: float, T: float, phase: float) Union[float, ndarray][source]

Compute damped oscillation convolved with normalized pseudo voigt profile (i.e. linear combination of normalized gaussian and cauchy distribution)

\(\eta C(\mathrm{fwhm}_L, t) + (1-\eta)G(\mathrm{fwhm}_G, t)\)

Parameters
  • t – time

  • fwhm_G – full width at half maximum of gaussian part of pseudo voigt profile

  • fwhm_L – full width at half maximum of cauchy part of pseudo voigt profile

  • eta – mixing parameter

  • k – damping constant (inverse of life time)

  • T – period of vibration

  • phase – phase factor

Returns

Convolution of normalized pseudo voigt profile and damped oscillation \((\exp(-kt)cos(2\pi t/T+phase))\).

TRXASprefitpack.mathfun.exp_conv_cauchy(t: Union[float, ndarray], fwhm: float, k: float) Union[float, ndarray][source]

Compute exponential function convolved with normalized cauchy distribution

Parameters
  • t – time

  • fwhm – full width at half maximum of cauchy distribution

  • k – rate constant (inverse of life time)

Returns

Convolution of normalized cauchy distribution and exponential decay \((\exp(-kt))\).

TRXASprefitpack.mathfun.exp_conv_gau(t: Union[float, ndarray], fwhm: float, k: float) Union[float, ndarray][source]

Compute exponential function convolved with normalized gaussian distribution

Parameters
  • t – time

  • fwhm – full width at half maximum of gaussian distribution

  • k – rate constant (inverse of life time)

Returns

Convolution of normalized gaussian distribution and exponential decay \((\exp(-kt))\).

TRXASprefitpack.mathfun.exp_conv_pvoigt(t: Union[float, ndarray], fwhm_G: float, fwhm_L: float, eta: float, k: float) Union[float, ndarray][source]

Compute exponential function convolved with normalized pseudo voigt profile (i.e. linear combination of normalized gaussian and cauchy distribution)

\(\eta C(\mathrm{fwhm}_L, t) + (1-\eta)G(\mathrm{fwhm}_G, t)\)

Parameters
  • t – time

  • fwhm_G – full width at half maximum of gaussian part of pseudo voigt profile

  • fwhm_L – full width at half maximum of cauchy part of pseudo voigt profile

  • eta – mixing parameter

  • k – rate constant (inverse of life time)

Returns

Convolution of normalized pseudo voigt profile and exponential decay \((\exp(-kt))\).

TRXASprefitpack.mathfun.fact_anal_dmp_osc_conv(t: ndarray, fwhm: Union[float, ndarray], tau: ndarray, T: ndarray, phase: ndarray, irf: Optional[str] = 'g', eta: Optional[float] = None, data: Optional[ndarray] = None, eps: Optional[ndarray] = None) ndarray[source]

Estimate the best coefficiets when full width at half maximum fwhm , life constant tau, period of vibration T and phase factor are given

Supported instrumental response functions are

  1. ‘g’: gaussian distribution

  2. ‘c’: cauchy distribution

  3. ‘pv’: pseudo voigt profile

Parameters
  • t – time

  • fwhm – full width at half maximum of instrumental response function

  • tau – life time for each component

  • T – period of vibration of each component

  • phase – phase factor for each component

  • irf

    shape of instrumental response function [default: g]

    • ’g’: normalized gaussian distribution,

    • ’c’: normalized cauchy distribution,

    • ’pv’: pseudo voigt profile \((1-\eta)g + \eta c\)

  • eta – mixing parameter for pseudo voigt profile (only needed for pseudo voigt profile, default value is guessed according to Journal of Applied Crystallography. 33 (6): 1311–1316.)

  • data – time scan data to fit

  • eps – standard error of data

Returns

Best coefficient for given damped oscillation component.

Note

data should not contain time range and the dimension of the data must be one.

TRXASprefitpack.mathfun.fact_anal_exp_conv(t: ndarray, fwhm: Union[float, ndarray], tau: ndarray, base: Optional[bool] = True, irf: Optional[str] = 'g', eta: Optional[float] = None, data: Optional[ndarray] = None, eps: Optional[ndarray] = None) ndarray[source]

Estimate the best coefficiets when full width at half maximum fwhm and life constant tau are given

When you fits your model to tscan data, you need to have good initial guess for not only life time of each component but also coefficients. To help this it solves linear least square problem to find best coefficients when fwhm and tau are given.

Supported instrumental response functions are

  1. ‘g’: gaussian distribution

  2. ‘c’: cauchy distribution

  3. ‘pv’: pseudo voigt profile

Parameters
  • t – time

  • fwhm – full width at half maximum of instrumental response function

  • tau – life time for each component

  • base – whether or not include baseline [default: True]

  • irf

    shape of instrumental response function [default: g]

    • ’g’: normalized gaussian distribution,

    • ’c’: normalized cauchy distribution,

    • ’pv’: pseudo voigt profile \((1-\eta)g + \eta c\)

  • eta – mixing parameter for pseudo voigt profile (only needed for pseudo voigt profile, default value is guessed according to Journal of Applied Crystallography. 33 (6): 1311–1316.)

  • data – time scan data to fit

  • eps – standard error of data

Returns

Best coefficient for given fwhm and tau, if base is set to True then size of coefficient is num_comp + 1, otherwise is num_comp.

Note

data should not contain time range and the dimension of the data must be one.

TRXASprefitpack.mathfun.fact_anal_rate_eq_conv(t: ndarray, fwhm: Union[float, ndarray], eigval: ndarray, V: ndarray, c: ndarray, exclude: Optional[str] = None, irf: Optional[str] = 'g', eta: Optional[float] = None, data: Optional[ndarray] = None, eps: Optional[ndarray] = None) ndarray[source]

Estimate the best coefficiets when full width at half maximum fwhm and eigenvector and eigenvalue of rate equation matrix are given

Supported instrumental response functions are

  1. ‘g’: gaussian distribution

  2. ‘c’: cauchy distribution

  3. ‘pv’: pseudo voigt profile

Parameters
  • t – time

  • fwhm – full width at half maximum of instrumental response function

  • eigval – eigenvalue of rate equation matrix

  • V – eigenvector of rate equation matrix

  • c – coefficient to match initial condition of rate equation

  • exclude

    exclude either ‘first’ or ‘last’ element or both ‘first’ and ‘last’ element.

    • ’first’ : exclude first element

    • ’last’ : exclude last element

    • ’first_and_last’ : exclude both first and last element

    • None : Do not exclude any element [default]

  • irf

    shape of instrumental response function [default: g]

    • ’g’: normalized gaussian distribution,

    • ’c’: normalized cauchy distribution,

    • ’pv’: pseudo voigt profile \((1-\eta)g + \eta c\)

  • eta – mixing parameter for pseudo voigt profile (only needed for pseudo voigt profile, default value is guessed according to Journal of Applied Crystallography. 33 (6): 1311–1316.)

  • data – time scan data to fit

  • eps – standard error of data

Returns

Best coefficient for each component.

Note

  1. eigval, V, c should be obtained from solve_model

  2. data should not contain time range and the dimension of the data must be one.

TRXASprefitpack.mathfun.gau_irf(t: Union[float, ndarray], fwhm: float) Union[float, ndarray][source]

Compute gaussian shape irf function

Parameters
  • t – time

  • fwhm – full width at half maximum of gaussian distribution

Returns

normalized gaussian function.

TRXASprefitpack.mathfun.gen_theory_data(e: ndarray, peaks: ndarray, A: float, fwhm_G: float, fwhm_L: float, peak_factor: float, policy: Optional[str] = 'shift') ndarray[source]

voigt broadening theoretically calculated lineshape spectrum

Parameters
  • e – energy

  • A – scaling parameter

  • fwhm_G – full width at half maximum of gaussian shape (unit: same as energy)

  • fwhm_L – full width at half maximum of lorenzian shape (unit: same as energy)

  • peak_factor – Peak factor, its behavior depends on policy.

  • policy

    Policy to match discrepency between experimental data and theoretical spectrum.

    • ’shift’ : Default option, shift peak position by peak_factor

    • ’scale’ : scale peak position by peak_factor

Returns

numpy ndarray of voigt broadened theoritical lineshape spectrum

TRXASprefitpack.mathfun.model_n_comp_conv(t: ndarray, fwhm: Union[float, ndarray], tau: ndarray, c: ndarray, base: Optional[bool] = True, irf: Optional[str] = 'g', eta: Optional[float] = None) ndarray[source]

Constructs the model for the convolution of n exponential and instrumental response function Supported instrumental response function are

  • g: gaussian distribution

  • c: cauchy distribution

  • pv: pseudo voigt profile

Parameters
  • t – time

  • fwhm – full width at half maximum of instrumental response function

  • tau – life time for each component

  • c – coefficient for each component

  • base – whether or not include baseline [default: True]

  • irf

    shape of instrumental response function [default: g]

    • ’g’: normalized gaussian distribution,

    • ’c’: normalized cauchy distribution,

    • ’pv’: pseudo voigt profile \((1-\eta)g + \eta c\)

  • eta – mixing parameter for pseudo voigt profile (only needed for pseudo voigt profile, default value is guessed according to Journal of Applied Crystallography. 33 (6): 1311–1316.)

Returns

Convolution of the sum of n exponential decays and instrumental response function.

Note

  1. fwhm For gaussian and cauchy distribution, only one value of fwhm is needed, so fwhm is assumed to be float However, for pseudo voigt profile, it needs two value of fwhm, one for gaussian part and the other for cauchy part. So, in this case, fwhm is assumed to be numpy.ndarray with size 2.

  2. c size of c is assumed to be num_comp+1 when base is set to true. Otherwise, it is assumed to be num_comp.

TRXASprefitpack.mathfun.pvoigt_irf(t: Union[float, ndarray], fwhm_G: float, fwhm_L: float, eta: float) Union[float, ndarray][source]

Compute pseudo voight shape irf function (i.e. linear combination of gaussian and lorenzian function)

Parameters
  • t – time

  • fwhm_G – full width at half maximum of gaussian part

  • fwhm_L – full width at half maximum of lorenzian part

  • eta – mixing parameter

Returns

linear combination of gaussian and lorenzian function with mixing parameter eta.

TRXASprefitpack.mathfun.rate_eq_conv(t: ndarray, fwhm: Union[float, ndarray], abs: ndarray, eigval: ndarray, V: ndarray, c: ndarray, irf: Optional[str] = 'g', eta: Optional[float] = None) ndarray[source]

Constructs signal model rate equation with instrumental response function Supported instrumental response function are

  • g: gaussian distribution

  • c: cauchy distribution

  • pv: pseudo voigt profile

Parameters
  • t – time

  • fwhm – full width at half maximum of instrumental response function

  • abs – coefficient for each excited state

  • eigval – eigenvalue of rate equation matrix

  • V – eigenvector of rate equation matrix

  • c – coefficient to match initial condition of rate equation

  • irf

    shape of instrumental response function [default: g]

    • ’g’: normalized gaussian distribution,

    • ’c’: normalized cauchy distribution,

    • ’pv’: pseudo voigt profile \((1-\eta)g + \eta c\)

  • eta – mixing parameter for pseudo voigt profile (only needed for pseudo voigt profile, default value is guessed according to Journal of Applied Crystallography. 33 (6): 1311–1316.)

Returns

Convolution of the solution of the rate equation and instrumental response function.

Note

fwhm For gaussian and cauchy distribution, only one value of fwhm is needed, so fwhm is assumed to be float However, for pseudo voigt profile, it needs two value of fwhm, one for gaussian part and the other for cauchy part. So, in this case, fwhm is assumed to be numpy.ndarray with size 2.

TRXASprefitpack.mathfun.solve_l_model(equation: ndarray, y0: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Solve system of first order rate equation where the rate equation matrix is lower triangle

Parameters
  • equation – matrix corresponding to model

  • y0 – initial condition

Returns

  1. eigenvalues of equation

  2. eigenvectors for equation

  3. coefficient where y0 = Vc

TRXASprefitpack.mathfun.solve_model(equation: ndarray, y0: ndarray) Tuple[ndarray, ndarray, ndarray][source]

Solve system of first order rate equation

Parameters
  • equation – matrix corresponding to model

  • y0 – initial condition

Returns

  1. eigenvalues of equation

  2. eigenvectors for equation

  3. coefficient where y0 = Vc

TRXASprefitpack.mathfun.solve_seq_model(tau)[source]

Solve sequential decay model

sequential decay model:

0 -> 1 -> 2 -> 3 -> … -> n

initial condition:

y0 = [1, 0, 0, …, 0]

Parameters
  • tau – liftime constants for each decay

  • y0 – initial condition

Returns

  1. eigenvalues of equation

  2. eigenvectors for equation

  3. coefficient to match initial condition