erlab.analysis.fit.models

Models for fitting data.

Classes

BCSGapModel(**kwargs)

Interpolation formula for temperature dependent BCS-like gap magnitude.

DynesModel(**kwargs)

Dynes formula for superconducting density of states.

FermiDiracModel(**kwargs)

Model that represents a Fermi-Dirac distribution convolved with a Gaussian.

FermiEdge2dModel([degree])

A 2D model for a polynomial Fermi edge with a linear density of states.

FermiEdgeModel(**kwargs)

Model for fitting a Fermi edge with a linear background.

MultiPeakModel([npeaks, peak_shapes, fd, ...])

Multiple peaks with optional Fermi-Dirac distribution and background.

PolynomialModel([degree])

Model a polynomial with coefficients in ascending order.

StepEdgeModel(**kwargs)

Model a Gaussian-broadened step between two linear backgrounds.

SymmetrizedGapModel(**kwargs)

Resolution-broadened superconducting spectral function.

TLLModel(**kwargs)

Resolution-broadened Tomonaga-Luttinger liquid (TLL) spectral function.

class erlab.analysis.fit.models.BCSGapModel(**kwargs)[source]

Bases: Model

Interpolation formula for temperature dependent BCS-like gap magnitude.

\[\Delta(T) \simeq a \cdot k_B T_c \cdot \tanh\left(b \sqrt{\frac{T_c}{T} - 1}\right)\]
Parameters:
  • x (array-like) – The temperature values in kelvins at which to calculate the BCS gap.

  • a – Proportionality constant. Default is 1.76.

  • b – Proportionality constant. Default is 1.74.

  • tc – The critical temperature in Kelvins. Default is 100.0.

class erlab.analysis.fit.models.DynesModel(**kwargs)[source]

Bases: Model

Dynes formula for superconducting density of states.

The formula is given by [Dynes et al., 1978]:

\[N_0 \text{Re}\left[\frac{|x| + i \Gamma}{\sqrt{(|x| + i \Gamma)^2 - \Delta^2}}\right]\]

where \(x\) is the binding energy, \(N_0\) is the normal-state density of states at the Fermi level, \(\Gamma\) is the broadening term, and \(\Delta\) is the superconducting energy gap.

Parameters:
  • x (array-like) – The input array of energy in eV.

  • n0\(N_0\), by default 1.0.

  • gamma\(\Gamma\), by default 0.003.

  • delta – The superconducting energy gap \(\Delta\), by default 0.01.

class erlab.analysis.fit.models.FermiDiracModel(**kwargs)[source]

Bases: Model

Model that represents a Fermi-Dirac distribution convolved with a Gaussian.

The model function is given by

\[I(\omega) = \left\{\frac{1}{1 + e^{(\omega-\omega_0)/k_B T}}\right\} \otimes g(\sigma)\]

where \(\omega\) is the binding energy, \(\omega_0\) is the center, \(k_B\) is the Boltzmann constant, \(T\) is the temperature, and \(g(\sigma)\) is a Gaussian kernel with standard deviation \(\sigma\). Note that the resolution parameter is not the standard deviation of the Gaussian, but rather the full width at half maximum (FWHM) of the Gaussian. The relationship is given by \(\text{FWHM} = 2\sqrt{2\ln(2)}\sigma\).

The independent variable x, center, and resolution are in eV. temp is in K.

See also

FermiEdgeModel

A model that includes a linear background.

guess(data, x, **kwargs)[source]

Guess starting values for the parameters of a model.

Parameters:
  • data (array-like) – Array of data (i.e., y-values) to use to guess parameter values.

  • x (array-like) – Array of values for the independent variable (i.e., x-values).

  • **kws (optional) – Additional keyword arguments, passed to model function.

Returns:

params (Parameters) – Initial, guessed values for the parameters of a Model.

class erlab.analysis.fit.models.FermiEdge2dModel(degree=2, **kwargs)[source]

Bases: Model

A 2D model for a polynomial Fermi edge with a linear density of states.

The model function can be written as

\[I = \left\{(a\omega + b)\left[1 + \exp\left(\frac{\omega - \sum_{i = 0}^{n} c_i \alpha^i}{k_B T}\right)\right]^{-1} + c\right\}\otimes g(\sigma)\]

for a \(n\) th degree polynomial edge with coefficients \(c_i\) with a linear density of states described by \(a\omega+b\) with a constant background \(c\) convolved with a gaussian, where \(\omega\) is the binding energy and \(\alpha\) is the detector angle.

Parameters:
  • degree (int, default: 2) – Degree of the polynomial that describes the Fermi-edge position as a function of alpha.

  • **kwargs – Additional keyword arguments passed to lmfit.model.Model. The independent variables default to ["eV", "alpha"].

Notes

eV, the polynomial edge position, and resolution are in eV. alpha is in degrees, temp is in K, and resolution is the Gaussian FWHM. Polynomial coefficient c{i} has units of eV per degree raised to i. const_bkg and offset have intensity units, and lin_bkg has intensity per eV units.

guess(data, eV, alpha, **kwargs)[source]

Guess starting values for the parameters of a model.

Parameters:
  • data (array-like) – Array of data (i.e., y-values) to use to guess parameter values.

  • eV (array-like) – Array of values for the independent variable (i.e., x-values).

  • alpha (array-like) – Array of values for the independent variable (i.e., x-values).

  • **kws (optional) – Additional keyword arguments, passed to model function.

Returns:

params (Parameters) – Initial, guessed values for the parameters of a Model.

fit(data, *args, **kwargs)[source]

Fit the two-dimensional Fermi-edge model.

Parameters:
  • data – Intensity to fit. A xarray.DataArray must be two-dimensional with exactly the dimensions eV and alpha. It is transposed to that order and flattened before fitting. Array-like input is flattened in its existing order.

  • *args – Additional arguments passed to lmfit.model.Model.fit().

  • **kwargs – Additional arguments passed to lmfit.model.Model.fit().

Returns:

lmfit.model.ModelResult – The fit result. The input array is not modified.

Return type:

ModelResult

class erlab.analysis.fit.models.FermiEdgeModel(**kwargs)[source]

Bases: Model

Model for fitting a Fermi edge with a linear background.

The model function is a Fermi-dirac function with linear background above and below the fermi level, convolved with a gaussian kernel.

Notes

The independent variable x, center, and resolution are in eV. resolution is the Gaussian FWHM, and temp is in K.

See also

FermiDiracModel

A model that does not include a linear background.

guess(data, x, **kwargs)[source]

Guess starting values for the parameters of a model.

Parameters:
  • data (array-like) – Array of data (i.e., y-values) to use to guess parameter values.

  • x (array-like) – Array of values for the independent variable (i.e., x-values).

  • **kws (optional) – Additional keyword arguments, passed to model function.

Returns:

params (Parameters) – Initial, guessed values for the parameters of a Model.

class erlab.analysis.fit.models.MultiPeakModel(npeaks=1, peak_shapes=None, *, fd=True, background='linear', degree=2, convolve=True, oversample=3, segmented=False, **kwargs)[source]

Bases: Model

Multiple peaks with optional Fermi-Dirac distribution and background.

Parameters:
  • npeaks (int, default: 1) – The number of peaks to fit.

  • peak_shapes (list[str] | str | None, default: None) – The shape(s) of the peaks in the model. If a list of strings is provided, each string represents the shape of a peak. If a single string is provided, it will be split by spaces to create a list of peak shapes. Supported shapes are "lorentzian", "gaussian", and "voigt", together with their documented aliases. If omitted, all peaks are Lorentzian.

  • fd (bool, default: True) – Whether to multiply the peaks and background by a Fermi-Dirac distribution. This adds efermi in the units of x, temp in K, and offset in the units of the dependent data. When this option is enabled, x and efermi must be in eV.

  • background (Literal['none', 'constant', 'linear', 'polynomial', 'shirley'], default: 'linear') –

    The type of background to include in the model. Possible values are:

    Value

    Additional parameters

    ’none’

    None

    ’constant’

    const_bkg

    ’linear’

    lin_bkg, const_bkg

    ’polynomial’

    c0, c1, … depending on degree

    ’shirley’

    const_bkg, lin_bkg, k_slope, and k_step_i with i from 0 to npeaks - 1

    Note

    The ‘shirley’ background is calculated by erlab.analysis.fit.functions.general.active_shirley() See its documentation for details about the parameters.

  • degree (int, default: 2) – The degree of the polynomial background. Only used if background is 'polynomial'. Default is 2.

  • convolve (bool, default: True) – Whether to convolve the complete model with a Gaussian kernel. If True, the model includes resolution, the Gaussian FWHM in the units of x.

  • oversample (int, default: 3) – Factor by which to oversample x during convolution to reduce numerical artifacts.

  • segmented (bool, default: False) – Whether to convolve the model in contiguous uniformly spaced segments. Use True when x contains large gaps or discontinuities.

  • **kwargs – Additional keyword arguments passed to the lmfit.model.Model constructor.

Notes

Peak parameters use the prefix p{i}_, where i starts at zero. All peak positions and widths use the units of x.

  • Gaussian and Lorentzian peaks use center, width, and height. width is the FWHM and height is the intensity at center. The corresponding sigma or gamma and amplitude parameters are derived.

  • Voigt peaks use center, sigma, gamma, and amplitude. sigma is the Gaussian standard deviation, gamma is the Lorentzian HWHM, and amplitude is the integrated peak area. width and height are derived.

Background parameter units follow from the dependent data and x. For example, const_bkg has intensity units and lin_bkg has intensity per unit of x.

func: MultiPeakFunction
guess(data, x=None, **kwargs)[source]

Guess starting values for the parameters of a model.

Parameters:
  • data (array-like) – Array of data (i.e., y-values) to use to guess parameter values.

  • x (array-like) – Array of values for the independent variable (i.e., x-values).

  • **kws (optional) – Additional keyword arguments, passed to model function.

Returns:

params (Parameters) – Initial, guessed values for the parameters of a Model.

eval_components(params=None, **kwargs)[source]

Evaluate model components.

Changed in version 3.20.0: Background components are returned as separate entries (for example, {prefix}_baseline, {prefix}_shirley, {prefix}_slope or {prefix}_constant/{prefix}_linear/{prefix}_polynomial) instead of a single {prefix}_bkg entry that represented the sum of all background components.

class erlab.analysis.fit.models.PolynomialModel(degree=9, **kwargs)[source]

Bases: Model

Model a polynomial with coefficients in ascending order.

The model is

\[y(x) = \sum_{i=0}^{n} c_i x^i,\]

where degree is \(n\).

Parameters:
  • degree (default: 9) – Highest power of x. The model contains parameters c0 through c{degree}.

  • **kwargs – Additional keyword arguments passed to lmfit.model.Model.

func: PolynomialFunction
guess(data, x=None, **kwargs)[source]

Estimate polynomial coefficients.

Parameters:
  • data – One-dimensional data to fit.

  • x (default: None) – Independent-variable values. If omitted, c0 is the mean of data and all higher coefficients are zero. If supplied, the estimate is a least-squares polynomial fit.

  • **kwargs – Parameter values that replace the estimates in the returned parameters.

Returns:

lmfit.Parameters – Estimated parameters named c0 through c{degree}.

class erlab.analysis.fit.models.StepEdgeModel(**kwargs)[source]

Bases: Model

Model a Gaussian-broadened step between two linear backgrounds.

The lower-x branch is dos0 + dos1 * x. The higher-x branch is back0 + back1 * x. A complementary error function joins the two branches.

Notes

center and sigma have the same units as the independent variable x. sigma is the standard deviation of the Gaussian broadening, not its FWHM.

guess(data, x, **kwargs)[source]

Estimate the step position and the two linear backgrounds.

Parameters:
  • data – One-dimensional data to fit.

  • x – Independent-variable values. The values must have the same length as data.

  • **kwargs – Parameter values that replace the estimates in the returned parameters.

Returns:

lmfit.Parameters – Estimated model parameters. The estimate uses linear fits to both ends of the data and the minimum of a smoothed derivative for center.

class erlab.analysis.fit.models.SymmetrizedGapModel(**kwargs)[source]

Bases: Model

Resolution-broadened superconducting spectral function.

The superconducting spectral function with a linear background is calculated as:

\[I(x) = \left[ A \cdot A_{sc}(x, \Sigma) + \left(m \cdot |x| + b \right) \right] \otimes \text{g}(\sigma)\]

where \(A_{sc}(x, \Sigma)\) is the superconducting spectral function calculated using the self-energy \(\Sigma(x)\) given by sc_self_energy(). \(\text{g}(\sigma)\) is a Gaussian kernel with standard deviation \(\sigma\). Note that the resolution parameter is the FWHM of the Gaussian kernel, not the standard deviation.

Parameters:
  • x (array-like) – The input array of energy in eV.

  • amp – The overall scale factor \(A\).

  • gamma1\(\Gamma_1\), the single-particle scattering rate.

  • gamma0\(\Gamma_0\), the pair-breaking scattering rate.

  • delta – The energy gap \(\Delta\).

  • lin_bkg – The slope of the linear background \(m\).

  • const_bkg – The constant background \(b\).

  • resolution – The broadening in eV. Note that this is the FWHM of the Gaussian kernel, not the standard deviation.

class erlab.analysis.fit.models.TLLModel(**kwargs)[source]

Bases: Model

Resolution-broadened Tomonaga-Luttinger liquid (TLL) spectral function.

The TLL spectral function is calculated as [Ohtsubo et al., 2015]:

\[I(x,T) = \left[A T^\alpha \cosh\left(\frac{\epsilon}{2}\right) \left|\Gamma\left(\frac{1 + \alpha}{2} + i \frac{\epsilon}{2\pi}\right)\right|^2 f(\epsilon,T)\right] \otimes \text{g}(\sigma) + B\]

where \(\epsilon=(x - x_0)/k_B T\) is the temperature-normalized energy, \(\Gamma\) is the gamma function, \(f(\epsilon,T) = 1/(e^{\epsilon}+1)\) is the Fermi-Dirac distribution, \(\text{g}(\sigma)\) is a Gaussian kernel with standard deviation \(\sigma\), and \(B\) is a constant background.

Note that the resolution parameter is the FWHM of the Gaussian kernel, not the standard deviation.

Parameters:
  • x – The energy values at which to calculate the TLL spectral function.

  • amp – The amplitude.

  • center – The center.

  • alpha – The power law exponent.

  • temp – The temperature in K.

  • resolution – The resolution of the Gaussian kernel in eV. Note that this is the FWHM of the Gaussian kernel, not the standard deviation.

  • const_bkg – A constant background to add to the broadened TLL function.