dfisher_2022a.models.lmfit

Submodules

Base models used to construct lmfit composite models. The models are provided by the science team of DFisher_2022A project. The original code can be found at https://github.com/astrodee/threadcount/blob/master/src/threadcount/models.py

class dfisher_2022a.models.lmfit.base.CompositeModel(left, right, op, **kws)[source]

Bases: lmfit.model.CompositeModel

class dfisher_2022a.models.lmfit.base.ConstantModelH(independent_vars=['x'], prefix='', nan_policy='raise', **kwargs)[source]

Bases: lmfit.model.Model

Constant model, with a single Parameter: c. Note that this is ‘constant’ in the sense of having no dependence on the independent variable x, not in the sense of being non-varying. To be clear, c will be a Parameter that will be varied in the fit (by default, of course).

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.

  • .. versionchanged:: 1.0.3 – Argument x is now explicitly required to estimate starting values.

class dfisher_2022a.models.lmfit.base.GaussianConstModelH(independent_vars=['x'], prefix='', nan_policy='raise', **kwargs)[source]

Bases: lmfit.model.Model

Constant model, with a single Parameter: c. Note that this is ‘constant’ in the sense of having no dependence on the independent variable x, not in the sense of being non-varying. To be clear, c will be a Parameter that will be varied in the fit (by default, of course).

flux_factor = 2.5066282746310002

Factor used to create flux_expr().

Type

float

fwhm_factor = 2.3548200450309493

Factor used to create lmfit.models.fwhm_expr().

Type

float

guess(data, x, **kwargs)

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.

  • .. versionchanged:: 1.0.3 – Argument x is now explicitly required to estimate starting values.

class dfisher_2022a.models.lmfit.base.GaussianModelH(independent_vars=['x'], prefix='', nan_policy='raise', **kwargs)[source]

Bases: lmfit.model.Model

A model heavily based on lmfit’s GaussianModel, fitting height instead of amplitude.

A model based on a Gaussian or normal distribution lineshape. The model has three Parameters: height, center, and sigma. In addition, parameters fwhm and flux are included as constraints to report full width at half maximum and integrated flux, respectively.

\[f(x; A, \mu, \sigma) = A e^{[{-{(x-\mu)^2}/{{2\sigma}^2}}]}\]

where the parameter height corresponds to \(A\), center to \(\mu\), and sigma to \(\sigma\). The full width at half maximum is \(2\sigma\sqrt{2\ln{2}}\), approximately \(2.3548\sigma\).

For more information, see: https://en.wikipedia.org/wiki/Normal_distribution

The default model is constrained by default param hints so that height > 0. You may adjust this as you would in any lmfit model, either directly adjusting the parameters after they have been made ( params[‘height’].set(min=-np.inf) ), or by changing the model param hints ( model.set_param_hint(‘height’,min=-np.inf) ).

flux_factor = 2.5066282746310002

Factor used to create flux_expr().

Type

float

fwhm_factor = 2.3548200450309493

Factor used to create lmfit.models.fwhm_expr().

Type

float

guess(data, x, negative=False, **kwargs)[source]

Estimate initial model parameter values from data, guess_from_peak().

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).

  • negative (bool, default False) – If True, guess height value assuming height < 0.

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

Returns

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

Return type

Parameters

dfisher_2022a.models.lmfit.base.flux_expr(model)[source]

Return constraint expression for line flux.

Custom lmfit composite models. The models are provided by the science team of DFisher_2022A project. The original code can be found at https://github.com/astrodee/threadcount/blob/master/src/threadcount/models.py

class dfisher_2022a.models.lmfit.composite.Const_1GaussModel(independent_vars=['x'], prefix='', nan_policy='raise', **kwargs)[source]

Bases: lmfit.model.CompositeModel

Constant + 1 Gaussian Model.

Essentially created by:

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

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

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

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.

  • .. versionchanged:: 1.0.3 – Argument x is now explicitly required to estimate starting values.