erlab.analysis.fit.functions.dynamic

Class-based dynamic functions for fitting.

These functions are not limited to a single function form, and can be used to create complex models.

Functions

get_args_kwargs(func)

Get all argument names and default values from a function signature.

get_args_kwargs_dict(func)

Classes

DynamicFunction()

Base class for dynamic functions.

FermiEdge2dFunction([degree])

MultiPeakFunction(npeaks[, peak_shapes, fd, ...])

A callable class for a multi-peak model.

PeakArgs

PolynomialFunction([degree])

A callable class for a arbitrary degree polynomial.

class erlab.analysis.fit.functions.dynamic.DynamicFunction[source]

Bases: object

Base class for dynamic functions.

Dynamic functions exploits the way lmfit handles asteval functions in lmfit.Model._parse_params.

property argnames: list[str]
property kwargs: dict[str, int | float]
class erlab.analysis.fit.functions.dynamic.FermiEdge2dFunction(degree=1)[source]

Bases: DynamicFunction

pre_call(eV, alpha, **params)[source]
property argnames: list[str]
property kwargs
class erlab.analysis.fit.functions.dynamic.MultiPeakFunction(npeaks, peak_shapes=None, fd=True, convolve=True)[source]

Bases: DynamicFunction

A callable class for a multi-peak model.

Parameters:
  • npeaks (int) – The number of peaks to fit.

  • peak_shapes (list[str] | str | None) – The shape(s) of the peaks in the model. If a list of strings is provided, each string represents the shape of a peak. If a single string is provided, it will be split by spaces to create a list of peak shapes. If not provided, the default peak shape will be used for all peaks.

  • fd (bool) – Flag indicating whether the model should be multiplied by the Fermi-Dirac distribution. This adds three parameters to the model: efermi, temp, and offset, each corresponding to the Fermi level, temperature in K, and constant background.

  • convolve (bool) – Flag indicating whether the model should be convolved with a gaussian kernel. If True, adds a resolution parameter to the model, corresponding to the FWHM of the gaussian kernel.

amplitude_expr(index, prefix)[source]
eval_bkg(x, **params)[source]
eval_peak(index, x, **params)[source]
pre_call(x, **params)[source]
sigma_expr(index, prefix)[source]
DEFAULT_PEAK: str = 'lorentzian'
PEAK_SHAPES: ClassVar[dict[Callable, list[str]]] = {CPUDispatcher(<function gaussian_wh>): ['gaussian', 'gauss', 'g'], CPUDispatcher(<function lorentzian_wh>): ['lorentzian', 'lor', 'l']}
property argnames: list[str]
property kwargs
property peak_all_args: dict[Callable, PeakArgs]
property peak_argnames: dict[Callable, list[str]]
property peak_funcs: Sequence[Callable]
class erlab.analysis.fit.functions.dynamic.PolynomialFunction(degree=1)[source]

Bases: DynamicFunction

A callable class for a arbitrary degree polynomial.

Parameters:

degree (int) – The degree of the polynomial.

property argnames: list[str]
erlab.analysis.fit.functions.dynamic.get_args_kwargs(func)[source]

Get all argument names and default values from a function signature.

Parameters:

func (Callable) – The function to inspect.

Returns:

  • args (list of str) – A list of argument names with no default value.

  • args_default (dict) – A dictionary of keyword arguments with their default values.

Return type:

tuple[list[str], dict[str, Any]]

Note

This function does not support function signatures containing varargs.

Example

>>> def my_func(a, b=10):
...     pass
>>> get_args_kwargs(my_func)
(['a'], {'b': 10})