Math
- spinlab.math.lineshape.gaussian(x, x0, sigma, integral=1.0)
Gaussian distribution.
- Parameters:
x (array_like) -- input x
x0 (float) -- Center of distribution
sigma (float) -- Standard deviation of Gaussian distribution
integral (float) -- Integral of distribution
- Returns:
Gaussian distribution
- Return type:
ndarray
The Gaussian distribution is defined as:
\[f(x; x_0, \sigma) = \frac{1}{\sigma \sqrt{2 \pi}} \exp{\left(\frac{(x-x_0)^2}{2 \sigma^2}\right)}\]
- spinlab.math.lineshape.lorentzian(x, x0, gamma, integral=1.0, deriv=False)
Lorentzian Distribution.
- Parameters:
x (array_like) -- input x
x0 (float) -- Center of distribution
gamma (float) -- Lorentzian width. 2*gamma is full width at half maximum (FWHM)
integral (float) -- Integral of distribution
deriv (boolean) -- Derivative of a Lorentzian Distribution (Imaginary part of a phased spectrum)
- Returns:
Lorentzian distribution
- Return type:
ndarray
The Lorentzian distribution is defined as:
\[f(x) = \frac{1}{\pi \gamma} \left[\frac{\gamma^2}{(x-x_0)^2 + \gamma^2}\right]\]Derivative:
\[f(x) = \frac{1}{\pi \gamma} \left[\frac{- 2\gamma^2 (x-x_0)}{\left( (x-x_0)^2 + \gamma^2 \right)^2}\right]\]
- spinlab.math.lineshape.voigtian(x, x0, sigma, gamma, integral=1.0, deriv=False)
Voigtian distribution. Lineshape given by a convolution of Gaussian and Lorentzian distributions.
- Parameters:
x (array_like) -- input x
x0 (float) -- center of distribution
sigma (float) -- Gaussian Linewidth. Standard deviation of Gaussian distribution.
gamma (float) -- Lorentzian linewidth. 2*gamma is the full width at half maximum (FWHM)
integral (float) -- Integral of distribution
deriv (boolean) -- Derivative of a Voigtian distribution (Gaussian broadened imaginary part of a phased spectrum).
- Returns:
Voigtian distribution
- Return type:
ndarray
The Voigtian distribution is defined as:
\[f(x; x_0, \sigma, \gamma) = \frac{\operatorname{Re}[w(z)]}{\sigma \sqrt{2 \pi}}\]with
\[z = \frac{x + i\gamma}{\sigma \sqrt{2}}\]Derivative: .. math:
f(x) = \frac{1}{\sigma^3 \sqrt{2 \pi}} \left[ \gamma \operatorname{Im}[w(z)] - \left(x - x0\right) \operatorname{Re}[w(z)] \right]
with
\[z = \frac{\left( \left( x - x0 \right) + 1j \gamma \right)}{\sigma \sqrt{2}}\]
- spinlab.math.relaxation.buildup_function(p, E_max, p_half)
Calculate asymptotic buildup curve
- Parameters:
p (array) -- power series
E_max (float) -- maximum enhancement
p_half (float) -- power at half saturation
- Returns:
buildup curve
- Return type:
ndarray
\[f(p) = 1 + E_{max} * p / (p_{1/2} + p)\]
- spinlab.math.relaxation.general_biexp(t, C1, C2, tau1, C3, tau2)
Calculate bi-exponential curve
- Parameters:
t (array_like) -- time series
C1 (float) -- see equation
C2 (float) -- see equation
C3 (float) -- see equation
tau1 (float) -- see equation
tau2 (float) -- see equation
- Returns:
bi-exponential curve
- Return type:
ndarray
\[f(t) = C1 + C2 e^{-t/tau1} + C3 e^{-t/tau2}\]
- spinlab.math.relaxation.general_exp(t, C1, C2, tau)
Calculate mono-exponential curve
- Parameters:
t (array_like) -- time series
C1 (float) -- see equation
C2 (float) -- see equation
tau (float) -- see equation
- Returns:
mono-exponential curve
- Return type:
ndarray
\[f(t) = C1 + C2 e^{-t/tau}\]
- spinlab.math.relaxation.ksigma_smax(p, E_max, p_half)
Calculate asymptotic buildup curve
- Parameters:
p (array) -- power series
E_max (float) -- maximum enhancement
p_half (float) -- power at half saturation
- Returns:
buildup curve
- Return type:
ndarray
\[f(p) = E_{max} * p / (p_{1/2} + p)\]
- spinlab.math.relaxation.logistic(x, c, x0, L, k)
Not Implemented. Placeholder for calculating asymptotic buildup curve
- Parameters:
x (array) -- x values
c (float) -- offset
x0 (float) -- x-value of sigmoid's midpoint
L (float) -- maximum value
k (float) -- logistic growth steepness
- Returns:
buildup curve
- Return type:
ndarray
- spinlab.math.relaxation.t1(t, T1, M_0, M_inf)
Exponential recovery for inversion recovery and saturation recovery T1 Measurements
- Parameters:
t (array_like) -- time series
T_1 (float) -- T1 value
M_0 (float) -- see equation
M_inf (float) -- see equation
- Returns:
T1 curve
- Return type:
ndarray
\[f(t) = M_{\infty} - (M_{\infty} - M_0) e^{-t/T_1}\]
- spinlab.math.relaxation.t2(t, M_0, T2, p=1.0)
Calculate stretched or un-stretched (p=1) exponential T2 curve
- Parameters:
t (array_like) -- time series
M_0 (float) -- see equation
T_2 (float) -- T2 value
p (float) -- see equation
- Returns:
T2 curve
- Return type:
ndarray
\[f(t) = M_{0} e^{(-(t/T_{2})^{p}}\]
- spinlab.math.window.exponential(x, lw)
Calculate exponential window function
- Parameters:
x (array_like) -- Vector of points
lw (int or float) -- Exponential line broadening.
- Returns:
exponential window function
- Return type:
array
\[\mathrm{exponential}(x) = e^{-\pi (x - x_0) lw}\]
- spinlab.math.window.gaussian(x, lw)
Calculate gaussian window function
- Parameters:
x (array_like) -- vector of points
lw (float) -- Full width at half maximum of the Gaussian window.
- Returns:
gaussian window function
- Return type:
array
\[\begin{split}\sigma &= \frac{lw}{2\sqrt{2\ln(2)}} \\ \mathrm{gaussian}(x) &= e^{-2\pi^2 x^2 \sigma^2}\end{split}\]
- spinlab.math.window.hamming(x)
Calculate hamming window function
- Parameters:
x (array_like, int) -- vector of points or number of points.
- Returns:
hamming window function
- Return type:
ndarray
\[\mathrm{hamming} = 0.53836 + 0.46164\cos(\pi * n / (N-1))\]
- spinlab.math.window.hann(x)
Calculate hann window function
- Parameters:
x (array_like, int) -- vector of points or number of points.
- Returns:
hann window function
- Return type:
ndarray
\[\mathrm{hann} = 0.5 + 0.5\cos(\pi * n / (N-1))\]
- spinlab.math.window.lorentz_gauss(x, lw, gauss_lw, gaussian_max=0)
Calculate lorentz-gauss window function
- Parameters:
x (array_like) -- vector of points
lw (int or float) -- exponential linewidth
gauss_lw (int or float) -- gaussian linewidth
gaussian_max (int or float) -- location of maximum in gaussian window
- Returns:
gauss_lorentz window function
- Return type:
array
\[ \begin{align}\begin{aligned}\mathrm{lorentz\_gauss} &= \exp(L - G^{2}) &\\ L(t) &= \pi * \mathrm{linewidth[0]} * t &\\ G(t) &= 0.6\pi * \mathrm{linewidth[1]} * (\mathrm{gaussian\_max} * (N - 1) - t) &\end{aligned}\end{align} \]
- spinlab.math.window.sin2(x)
Calculate sin-squared window function
- Parameters:
x (array_like, int) -- vector of points or number of points.
- Returns:
sin-squared window function
- Return type:
array
\[\sin^{2} = \cos((-0.5\pi * n / (N - 1)) + \pi)^{2}\]
- spinlab.math.window.traf(x, lw)
Calculate traf window function
- Parameters:
x (array_like) -- vector of points
lw (int or float) -- linewidth of Traficante window
- Returns:
traf window function
- Return type:
ndarray
\[ \begin{align}\begin{aligned}\mathrm{traf} &= (f1 * (f1 + f2)) / (f1^{2} + f2^{2}) &\\ f1(t) &= \exp(-t * \pi * \mathrm{linewidth[0]}) &\\ f2(t) &= \exp((t - T) * \pi * \mathrm{linewidth[1]}) &\end{aligned}\end{align} \]
The shaped pulses simulation
Author: Timothy Keller
Edit: Yen-Chun Huang
- spinlab.math.pulses.adiabatic(tp, BW, beta, resolution=1e-09)
Make Adiabatic Pulse Shape based on Hyperbolic Secant pulse
\[\text{sech} \left( \beta (t - \frac{t_p}{2}) \right) ^{1+i(\pi BW / \beta)}\]- Parameters:
tp (float) -- pulse length
BW (float) -- pulse bandwidth
beta (float) -- truncation factor
resolution (float) -- pulse resolution
- Returns:
tuple containing:
t (numpy.ndarray): Time axes
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple
- spinlab.math.pulses.chirp(tp, BW, resolution=1e-09)
Complex chirp pulse
\[e^{i 2 \pi (k/2) (t - t_p/2)^2}\]- Parameters:
tp (float) -- Pulse length
BW (float) -- Bandwidth of pulse
- Returns:
tuple containing:
t (numpy.ndarray): Time axis
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple
- spinlab.math.pulses.gaussian(tp, sigmas, resolution=1e-09)
Gaussian pulse
\[e^{- \frac{1}{2} \left( \frac{t - t_p/2}{\sigma} \right)^2}\]- Parameters:
tp (float) -- Pulse length
sigmas (float) -- Number of standard deviations where pulse is truncated
- Returns:
tuple containing:
t (numpy.ndarray): Time axis
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple
- spinlab.math.pulses.load_shape(filename)
Load a pulse shape from csv file
- Parameters:
filename (str) -- Path to file
- Returns:
Array of pulse shape
- Return type:
numpy.ndarray
- spinlab.math.pulses.plane_wave(tp, f, resolution=1e-09)
Complex plane wave pulse shape
\[e^{i 2 \pi f \left( t - \frac{t_p}{2} \right) }\]- Parameters:
tp (float) -- Pulse length
f (float) -- Frequency of plane wave
- Returns:
tuple containing:
t (numpy.ndarray): Time axis
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple
- spinlab.math.pulses.save_shape(pulse_shape, filename, num=101)
Save a numpy array as csv format compatible with Xepr
- Parameters:
pulse_shape (numpy.ndarray) -- Array of pulse shape
filename (str) -- Filename to save pulse shape
- spinlab.math.pulses.sinc(tp, n, resolution=1e-09)
Sinc pulse
\[ \begin{align}\begin{aligned}\frac{\sin \left( \frac{\pi}{2} (n + 1) x \right) }{x}\\x = \frac{t-\frac{t_p}{2}}{\frac{t_p}{2}}\end{aligned}\end{align} \]- Parameters:
tp (float) -- Pulse length
n (float) -- Total sinc lobes, must be odd for full sinc
n is number of sinc lobes, should be odd for full sinc
- Returns:
tuple containing:
t (numpy.ndarray): Time axis
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple
- spinlab.math.pulses.square(tp, t_length=0.0, resolution=1e-09)
Square pulse
- Parameters:
tp (float) -- Pulse length
t_length (float) -- Total length of time axis
- Returns:
tuple containing:
t (numpy.ndarray): Time axis
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple
- spinlab.math.pulses.wurst(tp, N, resolution=1e-09)
Real value WURST envelope pulse shape
\[1 - \text{abs} \left( \cos \left( \frac{\pi}{t_p} (t - \frac{t_p}{2}) + \frac{\pi}{2} \right) \right) ^N\]- Parameters:
tp (float) -- Pulse length
N (float) -- exponential
- Returns:
tuple containing:
t (numpy.ndarray): Time axis
pulse (numpy.ndarray): Pulse shape
- Return type:
tuple