Const_2GaussModel

class threadcount.models.Const_2GaussModel(independent_vars=['x'], prefix='', nan_policy='raise', **kwargs)[source]

Bases: CompositeModel

Constant + 2 Gaussians Model.

Essentially created by:

lmfit.models.ConstantModel() + GaussianModelH(prefix="g1_") + GaussianModelH(prefix="g2_")

The param names are [‘g1_height’, ‘g1_center’, ‘g1_sigma’, ‘g2_height’, ‘g2_center’, ‘g2_sigma’, ‘c’]

Parameters:
  • independent_vars (list of str, optional) – Arguments to the model function that are independent variables default is [‘x’]).

  • prefix (str, optional) – String to prepend to parameter names, needed to add two Models that have parameter names in common.

  • nan_policy ({'raise', 'propagate', 'omit'}, optional) – How to handle NaN and missing values in data. See Notes below.

  • **kwargs (optional) – Keyword arguments to pass to Model.

Notes

1. nan_policy sets what to do when a NaN or missing value is seen in the data. Should be one of:

  • ‘raise’ : raise a ValueError (default)

  • ‘propagate’ : do nothing

  • ‘omit’ : drop missing data

Methods Summary

guess(data, x[, sigma0, heights, ...])

Estimate initial model parameter values from data.

Methods Documentation

guess(data, x, sigma0=None, heights=(1, 4), sigma_factors=(1, 1), centers=(-2, 0), absolute_centers=False, **kwargs)

Estimate initial model parameter values from data.

The parameters will control the computation of initial guesses for the two gaussians in relation to guesses for if this had only 1 gaussian component. I beleive these default parameters do an okay job at many of the test-cases I have given it.

The height, center, and sigma are estimated assuming this is 1 gaussian component. Using these parameters and the function inputs, the height, center, and sigma guesses for each gaussian component will be calculated.

I will conserve ~flux, meaning in this case sum(g#_height * g#_sigma) = height * sigma. If sigma0 is None, then sigma0 is set automatically to this sigma from the 1 gaussian guess. Then the rest of the factors are calculated as so:

[g1_sigma, g2_sigma] = sigma_factors * sigma0
if absolute_centers is False:
    [g1_center, g2_center] = center + sigma0 * centers
if absolute_centers is True:
    [g1_center, g2_center] = center + centers
[g1_height, g2_height] = A * height * heights

and the overall amplitude scaling factor A is computed by:

g1_height * g1_sigma + g2_height * g2_sigma = height * sigma
A * height * heights[0] * g1_sigma + A * height * heights[1] * g2_sigma = height * sigma
A = sigma / (heights[0] * g1_sigma + heights[1] * g2_sigma)
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).

  • sigma0 (float, optional) – Sets the reference value for computing sigmas and centers, by default None. If None, this will be set to the sigma returned from guess_from_peak(), which is related to FWHM.

  • heights (array_like of floats of length 2, optional) – A list containing relative heights of [g1_height, g2_height], by default [1,4]. These will have an overall scale factor computed, so no need to normalize.

  • sigma_factors (array_like of floats of length 2, optional) – [g1_sigma, g2_sigma] = sigma0 * sigma_factors, by default [1,1]

  • centers (array_like, optional) – Change from the 1 gaussian guessed center, in units of sigma0 unless absolute_centers is True, by default [-0.5,0] [g1_center, g2_center] = center + sigma0 * centers

  • absolute_centers (bool, optional) – If True, modifies the centers equation to: [g1_center, g2_center] = center + centers, by default False

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

Returns:

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

Return type:

Parameters