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 all argument names and default values from a function signature. |
Classes
Base class for dynamic functions. |
|
|
Polynomial Fermi edge with a linear intensity background. |
|
Multiple peaks with optional Fermi-Dirac distribution and background. |
|
A callable class for an arbitrary degree polynomial. |
- class erlab.analysis.fit.functions.dynamic.DynamicFunction[source]¶
Bases:
objectBase class for dynamic functions.
Dynamic functions exploits the way
lmfithandles asteval functions inlmfit.Model._parse_params.
- class erlab.analysis.fit.functions.dynamic.FermiEdge2dFunction(degree=1)[source]¶
Bases:
DynamicFunctionPolynomial Fermi edge with a linear intensity background.
The edge position is
\[E_F(\alpha) = \sum_{i=0}^{n} c_i \alpha^i,\]where
degreeis \(n\). A Gaussian convolution is applied alongeV.- Parameters:
degree (
int, default:1) – Degree of the polynomial that describes the edge position as a function ofalpha.
Notes
eV, \(E_F\), andresolutionare in eV.alphais in degrees,tempis in K, andresolutionis the Gaussian FWHM. Coefficientc{i}has units of eV per degree raised toi.const_bkgandoffsethave the units of the returned intensity.lin_bkghas intensity per eV units.Calling the function with separate NumPy coordinates returns a flattened array in
(eV, alpha)order. If both coordinates arexarray.DataArrayobjects, the result has their broadcast dimensions and coordinates. If only one coordinate is a DataArray, the result is a NumPy array. The Gaussian convolution delegates todo_convolve_2d().
- class erlab.analysis.fit.functions.dynamic.MultiPeakFunction(npeaks, peak_shapes=None, *, fd=True, background='linear', degree=2, convolve=True, oversample=3, segmented=False)[source]¶
Bases:
DynamicFunctionMultiple peaks with optional Fermi-Dirac distribution and background.
- Parameters:
npeaks (
int) – The number of peaks to fit.peak_shapes (
list[str] |str|None, default: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. Supported shapes are"lorentzian","gaussian", and"voigt", together with their documented aliases. If omitted, all peaks are Lorentzian.fd (
bool, default:True) – Whether to multiply the peaks and background by a Fermi-Dirac distribution. This addsefermiin the units ofx,tempin K, andoffsetin the units of the dependent data. When this option is enabled,xandefermimust be in eV.background (
Literal['constant','linear','polynomial','none','shirley'], default:'linear') –The type of background to include in the model. Possible values are:
Value
Additional parameters
’none’
None
’constant’
const_bkg’linear’
lin_bkg,const_bkg’polynomial’
c0,c1, … depending ondegree’shirley’
const_bkg,lin_bkg,k_slope, andk_step_iwith i from 0 tonpeaks- 1Note
The ‘shirley’ background is calculated by
erlab.analysis.fit.functions.general.active_shirley()See its documentation for details about the parameters.degree (
int, default:2) – The degree of the polynomial background. Only used ifbackgroundis'polynomial'. Default is 2.convolve (
bool, default:True) – Whether to convolve the complete model with a Gaussian kernel. IfTrue, the model includesresolution, the Gaussian FWHM in the units ofx.oversample (
int, default:3) – Factor by which to oversamplexduring convolution to reduce numerical artifacts.segmented (
bool, default:False) – Whether to convolve the model in contiguous uniformly spaced segments. UseTruewhenxcontains large gaps or discontinuities.
Notes
Peak parameters use the prefix
p{i}_, whereistarts at zero. All peak positions and widths use the units ofx.Gaussian and Lorentzian peaks use
center,width, andheight.widthis the FWHM andheightis the intensity atcenter. The correspondingsigmaorgammaandamplitudeparameters are derived.Voigt peaks use
center,sigma,gamma, andamplitude.sigmais the Gaussian standard deviation,gammais the Lorentzian HWHM, andamplitudeis the integrated peak area.widthandheightare derived.
Background parameter units follow from the dependent data and
x. For example,const_bkghas intensity units andlin_bkghas intensity per unit ofx.
- class erlab.analysis.fit.functions.dynamic.PolynomialFunction(degree=1)[source]¶
Bases:
DynamicFunctionA callable class for an arbitrary degree polynomial.
- Parameters:
degree (
int, default:1) – The degree of the polynomial.
- 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:
- Return type:
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})