ConvolvedModel

Can be used to perform analytic convolutions between models.

class convolvedModel.ConvolvedModel(left, right, on_undefined_conv='numeric', convMap=None, **kws)

Combine two models (left and right) with the provided analytic convolution function(s).

Parameters:
  • left (Model or CompositeModel) – Left-hand model.
  • right (Model or CompositeModel) – Right-hand model.
  • on_undefined_conv ({'numeric', 'raise'}, optional) –

    Determine the behavior when a pair of model has no analytic convolution associated with it:

    • ’numeric’ results in a numerical convolution
    • ’raise’ raises a KeyError

    (default ‘numeric’)

  • convMap (mapping, optional) – Dictionary of dictionaries to map the convolution function to a pair of model. A default convMap is already present in the class but can be overridden by this argument.
  • **kws (optional) – Additional keywords are passed to Model when creating this new model.

Notes

The two models must use the same independent variables. Only the parameters from left and right are used and exposed. The parameters of the convolution function are not exposed outside the class. They are only used internally and determined inside the convolution function by the combination of the parameters and keywords provided for left and right.

The eval_components() returns the convoluted components from left by default. This behavior can be changed by using returnComponents=”right” in the keyword arguments passed to the method.

Examples

First create two models to be convolved (here two Lorentzians):

>>> l1 = lmfit.Model.LorentzianModel()
>>> l2 = lmfit.Model.LorentzianModel()

Define the convolution function using:

>>> def myConv(left, right, params, **kwargs):
...     lp = left.make_funcargs(params, **kwargs)
...     rp = right.make_funcargs(params, **kwargs)
...     amplitude = lp['amplitude'] * rp['amplitude']
...     sigma = lp['sigma'] + rp['sigma']
...     center = lp['center'] + rp['center']
...     out = sigma / (np.pi * ((lp['x'] - center)**2 + sigma**2))
...     return out

Eventually perform the convolution:

>>> convModel = ConvolvedModel(l1, l2)

Assign the convolution function myConv to the pair of ‘lorentzian’ using:

>>> convModel.convMap = {'lorentzian': {'lorentzian': myConv}}
components

Return components for composite model.

eval(params=None, **kwargs)

Evaluate model function for convolved model.

eval_components(**kwargs)

Return OrderedDict of name, results for each component.

on_undefined_conv

Return the parameter ‘on_undefined_conv’

param_names

Return parameter names for composite model.