scippneutron.peaks.model.Model#

class scippneutron.peaks.model.Model(*, param_names, prefix='')[source]#

Abstract base class for fitting models.

This class defines the basic interface for models by way of public methods. Subclasses should override the protected methods _call, _guess, and optionally _param_bounds instead of their public counterparts.

__init__(*, param_names, prefix='')[source]#

Initialize a base model.

Parameters:
  • param_names (Iterable[str]) – Names of parameters in arbitrary order. Does not include the prefix.

  • prefix (str, default: '') – Prefix used for model parameters in all user-facing data.

Methods

__init__(*, param_names[, prefix])

Initialize a base model.

fwhm(params)

Compute full width at half maximum.

guess(data, *[, coord])

Roughly estimate the model parameters for given data.

with_prefix(prefix)

Return a copy of the model with a new prefix.

Attributes

param_bounds

Parameter bounds.

param_names

Parameter names including the prefix.

prefix

Prefix for parameter names.

fwhm(params)[source]#

Compute full width at half maximum.

Note that this function is only implemented for peaked models!

Parameters:

params (dict[str, Variable]) – Parameter values for which to compute the FWHM.

Returns:

Variable – FWHM of the model at the given parameters.

Raises:

NotImplementedError: – If this model does not support computing the FWHM.

guess(data, *, coord=None)[source]#

Roughly estimate the model parameters for given data.

The estimate can be used as the starting point for a fit but does not necessarily represent a good fit by itself.

Parameters:
  • data (DataArray) – Data array where data.data is the dependent variable and a chosen coord (see below) is the independent variable.

  • coord (Optional[str], default: None) – Coordinate name of data to use as independent variable. If not given, data.dim is used instead.

Returns:

dict[str, Variable] – Estimated parameters.

property param_bounds: dict[str, tuple[float, float]]#

Parameter bounds.

Returns:

Upper and lower bounds for parameters. Parameters omitted from this dict are unbounded.

property param_names: set[str]#

Parameter names including the prefix.

property prefix: str#

Prefix for parameter names.

with_prefix(prefix)[source]#

Return a copy of the model with a new prefix.

Return type:

Model