TRXASprefitpack.mathfun package#

Module contents#

mathfun: subpackage for the mathematical functions for TRXASprefitpack

copyright

2021-2022 by pistack (Junho Lee).

license

LGPL3.

TRXASprefitpack.mathfun.cauchy_irf(t: Union[float, numpy.ndarray], fwhm: float) Union[float, numpy.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: numpy.ndarray, eigval: numpy.ndarray, V: numpy.ndarray, c: numpy.ndarray) numpy.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: numpy.ndarray, fwhm: float, eigval: numpy.ndarray, V: numpy.ndarray, c: numpy.ndarray) numpy.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: numpy.ndarray, fwhm: float, eigval: numpy.ndarray, V: numpy.ndarray, c: numpy.ndarray) numpy.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: numpy.ndarray, fwhm_G: float, fwhm_L: float, eta: float, eigval: numpy.ndarray, V: numpy.ndarray, c: numpy.ndarray) numpy.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.exp_conv_cauchy(t: Union[float, numpy.ndarray], fwhm: float, k: float) Union[float, numpy.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, numpy.ndarray], fwhm: float, k: float) Union[float, numpy.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, numpy.ndarray], fwhm_G: float, fwhm_L: float, eta: float, k: float) Union[float, numpy.ndarray][source]#

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

Math

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_exp_conv(t: numpy.ndarray, fwhm: Union[float, numpy.ndarray], tau: numpy.ndarray, base: Optional[bool] = True, irf: Optional[str] = 'g', eta: Optional[float] = None, data: Optional[numpy.ndarray] = None, eps: Optional[numpy.ndarray] = None) numpy.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

irf
  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.gau_irf(t: Union[float, numpy.ndarray], fwhm: float) Union[float, numpy.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.model_n_comp_conv(t: numpy.ndarray, fwhm: Union[float, numpy.ndarray], tau: numpy.ndarray, c: numpy.ndarray, base: Optional[bool] = True, irf: Optional[str] = 'g', eta: Optional[float] = None) numpy.ndarray[source]#

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

irf
  • 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, numpy.ndarray], fwhm_G: float, fwhm_L: float, eta: float) Union[float, numpy.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.solve_model(equation: numpy.ndarray, y0: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray, numpy.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