fitting
- A collection of general fitting routines
A comprehensive bundle of mathematical functions and routines for fitting experimental data.
Provides methods for
- polynomials, Lorentzians, Gaussians, Voigts, exponentials, etc.
- Lorentz oscillator model,
- fitting beam waists using the knife edge method,
- LPSVD fitting of periodic noisy data,
- short-time Fourier transform,
- principal component analysis (using NIPALS),
Utility Functions
curve_fit (*args) |
A convenience wrapper for scipy.optimize.curve_fit() , so you do not have to import scipy in addition. |
weighted_mean (x, s) |
Calculate the weighted average over a given data set and its uncertainties. |
stft (data, fs, w[, overlap_fac]) |
Short time (or moving window) Fourier transform using a Hanning window. |
Polynomials
const (x, a) |
Returns a constant. |
proportional (x, b) |
Proportionality, i.e., a line through the origin. |
line (x, a, b) |
A line. |
parabola (x, a, b, c) |
A parabola. |
parabola2 (x, y0, x0, a) |
Another version of the parabola using the vertex (x0, y0). |
cubic (x, a, b, c, d) |
Third order polynomial. |
quartic (x, a, b, c, d, e) |
Fourth order polynomial. |
poly (x, *coeffs) |
A general polynomial. |
lagrange (x, x0, y0) |
Construct the polynomial over x with the least degree that passes through all points (x0, y0) using Lagrange polynomials. |
Powers
power (x, A, a) |
Power law without offset. |
power_const (x, y0, A, a) |
Power law with constant offset. |
Trigonometric Functions
cosine (x, a, b, c[, d]) |
A cosine with constant offset. |
cosine2 (x, a, b, c[, d]) |
A cosine squared. |
sinusoids (x, *p) |
A sum over a variable number of decaying sinusoids. |
sinusoidsFT (f, *p) |
Returns reconstructed frequency domain representation from analytic Fourier transform of one sided decaying sinusoid for a variable number of sinusoids. |
Lorentzians
lor (x, A, x0, dx) |
Single Lorentzian without baseline / offset. |
lorentzians (x, *p) |
Sum over variable number of Lorentzians without baseline. |
lorentzians_const (x, a, *p) |
Sum over variable number of Lorentzians on a constant background. |
lorentzians_line (x, a, b, *p) |
Sum over variable number of Lorentzians on a linear background. |
lorentzians_parabola (x, a, b, c, *p) |
Sum over variable number of Lorentzians on a quadratic background. |
lorentzians_cubic (x, a, b, c, d, *p) |
Sum over variable number of Lorentzians on a cubic background. |
lorentzians_quartic (x, a, b, c, d, e, *p) |
Sum over variable number of Lorentzians on a quartic background. |
Dispersive Lorentzians
displor (x, A, B, x0, dx) |
A dispersive Lorentzian without baseline / offset. |
displorentzians (x, *p) |
A sum over a variable number of dispersive Lorentzians without baseline. |
displorentzians_const (x, a, *p) |
A sum over a variable number of dispersive Lorentzians on a constant background. |
displorentzians_line (x, a, b, *p) |
A sum over a variable number of dispersive Lorentzians on a linear background. |
displorentzians_parabola (x, a, b, c, *p) |
A sum over a variable number of dispersive Lorentzians on a quadratic background. |
displorentzians_cubic (x, a, b, c, d, *p) |
A sum over a variable number of dispersive Lorentzians on a cubic background. |
displorentzians_quartic (x, a, b, c, d, e, *p) |
A sum over a variable number of dispersive Lorentzians on a quartic background. |
Gaussians
gauss (x, A, x0, dx) |
A single Gaussian without baseline / offset. |
gaussians (x, *p) |
Sum over a variable number of Gaussians without baseline. |
gaussians_const (x, a, *p) |
Sum over a variable number of Gaussians on a constant background. |
gaussians_line (x, a, b, *p) |
Sum over a variable number of Gaussians on a linear background. |
gaussians_parabola (x, a, b, c, *p) |
Sum over a variable number of Gaussians on a quadratic background. |
gaussians_cubic (x, a, b, c, d, *p) |
Sum over a variable number of Gaussians on a cubic background. |
gaussians_quartic (x, a, b, c, d, e, *p) |
Sum over a variable number of Gaussians on a quartic background. |
Dispersive Gaussians
dispgauss (x, A, B, x0, dx) |
A single dispersive Gaussian without baseline / offset. |
dispgaussians (x, *p) |
Sum over a variable number of dispersive Gaussians without baseline. |
dispgaussians_const (x, a, *p) |
Sum over a variable number of dispersive Gaussians on a constant background. |
dispgaussians_line (x, a, b, *p) |
Sum over a variable number of dispersive Gaussians on a linear background. |
dispgaussians_parabola (x, a, b, c, *p) |
Sum over a variable number of dispersive Gaussians on a quadratic background. |
dispgaussians_cubic (x, a, b, c, d, *p) |
Sum over a variable number of dispersive Gaussians on a cubic background. |
dispgaussians_quartic (x, a, b, c, d, e, *p) |
Sum over a variable number of dispersive Gaussians on a quartic background. |
Pseudo-Voigt Profiles
voigt (x, A, x0, dx, a) |
Approximation to a Voigt profile based on a weighted sum of a Gaussian and a Lorentzian with the same parameters. |
voigts (x, *p) |
Sum over variable number of approximate Voigt profiles without baseline / offset. |
voigts_const (x, a, *p) |
Sum over variable number of approximate Voigt profiles on a constant background. |
voigts_line (x, a, b, *p) |
Sum over variable number of approximate Voigt profiles on a linear background. |
voigts_parabola (x, a, b, c, *p) |
Sum over variable number of approximate Voigt profiles on a quadratic background. |
voigts_cubic (x, a, b, c, d, *p) |
Sum over variable number of approximate Voigt profiles on a cubic background. |
voigts_quartic (x, a, b, c, d, e, *p) |
Sum over variable number of approximate Voigt profiles on a quartic background. |
Saturation Curves
saturation (x, A, x2) |
Saturation curve from 0 to A. |
Step Functions
heaviside (x, x0) |
Heaviside step function. |
step (x, x0, y0, y1, a) |
Sharp step function on a linear background. |
smoothstep (x, x0, y0, y1, a, k) |
Smooth step function on a linear background. |
Lorentz Oscillator Model
lorOscRe (w, A, w0, dw) |
Real part of a Lorentz oscillator model for the dielectric function. |
lorOscIm (w, A, w0, dw) |
Imaginary part of a Lorentz oscillator model for the dielectric function. |
Beam Waist Fitting
waist (z, A, y0, z0, w0) |
Use this function to fit the integrated intensity profile obtained by translating a knife edge through the waist of a laser beam. |
rayleigh (x, x0, xR, w0) |
Waist size of a Gaussian laser beam as function of position along axis. |
fit_waist (y, dz) |
Convenience function for extracting the beam waist from a knife-edge intensity profile using waist() and regularly spaced points. |
Linear Prediction and Singular Value Decomposition
lpsvd (x, Y[, eta, refine]) |
LPSVD fitting function based on Kumaresan and Tufts, IEEE Transactions on Acoustics, Speech and Signal Processing ASSP-30, 833 (1982) and the Matlab code by Greg Reynolds, 2006 (from mathworks.com). |
lpsvd2 (x, Y[, eta, M, removeBias, refine]) |
Variation of LPSVD fitting function based on Barkhujisen et al, Journal of Magnetic Resonance 61, 465 (1985), which seems to be more robust for noisy data. |
Principal Component Analysis
nipals (A[, n]) |
Principal component analysis based on the NIPALS algorithm for deconvolution of spectra containing the signature of multiple species. |
getRdimer (Kp, c, T[, outR]) |
Calculate the transform matrix R using an estimate for the monomer <-> dimer equilibrium constant Kp. |
getR23mer (K, c, T[, outR]) |
Calculate the transform matrix R using an estimate for the monomer <-> dimer and monomer <-> trimer equilibrium constants K2 and K3. |