scipy_residual_to_lmfit

class utilipy.data_utils.fitting.scipy_residual_to_lmfit(func: Optional[Callable] = None, param_order: Optional[Sequence] = None)[source]

Bases: ObjectProxy

Decorator to make scipy residual functions compatible with lmfit.

(see https://lmfit.github.io/lmfit-py/fitting.html)

Parameters
param_orderlist of strs

the variable order used by lmfit the strings are the names of the lmfit parameters must be in the same order as the scipy residual function

Returns
scipy_residual_to_lmfitclass

internally constructed class

Notes

the function can be called as normal add a .lmfit function for use in lmfit minimizations see https://lmfit.github.io/lmfit-py/fitting.html

>>> @scipy_residual_to_lmfit(param_order=['amp', 'phase', 'freq', 'decay'])
... def residual(variables, x, data, eps_data):
...     amp, phase, freq, decay = variables
...     # calculate residual here
...     return res

Todo

since using ObjectProxy, make it compatible with bound functions see https://wrapt.readthedocs.io/en/latest/wrappers.html

Initialize Proxy.

Methods Summary

__call__(*args, **kwargs)

Call scipy residual.

decorator(param_order)

Decorator.

lmfit(params, *args, **kwargs)

lmfit version of function.

Methods Documentation

__call__(*args: Any, **kwargs: Any) → Sequence[source]

Call scipy residual.

Parameters
*argsAny

Arguments into __wrapped__, the residual function.

**kwargsAny

Keyword arguments into __wrapped__, the residual function.

Returns
return_Any

Returns from called __wrapped__.

classmethod decorator(param_order: Sequence) → Callable[source]

Decorator.

lmfit(params: ParametersType, *args: Any, **kwargs: Any) → Sequence[source]

lmfit version of function.