Presets¶
This module provides several function builders that can be used to fit your data.
These functions generate a Model class instance from the lmfit package [1].
References
| [1] | https://lmfit.github.io/lmfit-py/ |
-
lmfit_presets.build_2D_model(q, funcName, funcBody, defVals=None, bounds=None, vary=None, expr=None, paramGlobals=None, prefix='', var='x')¶ Builds a 2D lmfit.Model.
Parameters: - q (np.array or list) – momentum transfer q values of scattering.
- funcName (str) – name of the function to be built.
- funcBody (str) – formatted string for the function to be used (in 1D). For a gaussian the string “{a} * np.exp(-(x - {cen})**2 / {width}*{q}**2)” will lead to a model with parameters of root names ‘a’, ‘cen’ and ‘width’. If these parameters are not in argument paramGlobals, the parameter names will be ‘a_1’, ‘a_2’, ‘a_3’, …, ‘a_n’, where n is the length of the array q.
- defVals (dict, optional) – dictionary of default values for the parameters of the form {‘a’: 1., ‘cen’: 0.05, ‘width’: 2}. If None, set to 1.0 for all parameters.
- bounds (dict, optional) – dictionary of bounds for the parameters of the form {‘a’: (0., np.inf}, ‘cen’: (-10, 10)}. If None, set to (-np.inf, np.inf) for all parameters.
- vary (dict, optional) – dictionary of parameter hint ‘vary’ for the parameters of the form {‘a’: False, ‘cen’: True}. If None, set to True for all parameters.
- expr (dict, optional) – dictionary of parameter hint ‘expr’ for the parameters of the form {‘a’: ‘width / sqrt(2)’}. If None, set to None for all parameters.
- paramGlobals (list, optional) – defines which parameters should be considered as ‘global’, that is, a parameter that is fixed for all momentum transfer q values. If set to [‘width’], then the resulting model will have parameters of the form (‘a_1’, …, ‘a_n’, ‘cen_1’, …, ‘cen_n’, ‘width’), where n is the length of the parameter q.
- prefix (str, optional) – prefix to be given to the model name
- var (str, optional) – name of the primary independent variable (default ‘x’)
-
lmfit_presets.calibratedD2O(q, temp=300, **kwargs)¶ Lineshape for D2O where the Lorentzian width was obtained from a measurement on IN6 at the ILL.
Parameters: - q (np.array or list) – Array of momentum transfer q values
- temp (float) – Sample temperature used for the experiment.
- kwargs (dict, optional) – Additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
-
lmfit_presets.delta(q, **kwargs)¶ Normalized Dirac delta.
where the shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
-
lmfit_presets.gaussian(q, qwise=True, **kwargs)¶ Normalized Gaussian lineshape.
\[\rm G(x, q; a, c, \sigma) = \frac{a}{\sqrt(\pi \sigma} e^{-(x - c)^2 / \sigma}\]where the shape of the output array depends on the shape of the independent variable q and \(\sigma\) can have an explicit dependence on q as \(\sigma q**2\).
Parameters: - q (np.array or list) – array of momentum transfer q values
- qwise (bool, optional) – whether the width (sigma) has explicit dependence on q (default False)
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
- sigma
-
lmfit_presets.getDelta(x, amplitude, center)¶ Helper function for the Dirac delta model.
-
lmfit_presets.hline(q, **kwargs)¶ A horizontal line.
-
lmfit_presets.jump_diff(q, qwise=False, **kwargs)¶ Normalized Lorentzian with jump-diffusion model.
The shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- qwise (bool, optional) – whether the width (sigma) has explicit dependence on q (default False)
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
- sigma
- tau
References
For more information see: http://doi.org/10.1103/PhysRev.119.863
-
lmfit_presets.kww(q, **kwargs)¶ Fourier transform of the Kohlrausch-William-Watts (KWW) function.
The shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- tau
- beta
References
For more information, see: https://en.wikipedia.org/wiki/Stretched_exponential_function
-
lmfit_presets.linear(q, **kwargs)¶ Linear model that can be used for background.
The model reads: \(a*x + b\)
Notes
- Two parameters:
- a
- b
-
lmfit_presets.lorentzian(q, qwise=False, **kwargs)¶ Normalized Lorentzian lineshape.
\[\rm \mathcal{L}(x, q; a, c, \sigma) = \frac{a}{\pi} \frac{\sigma}{(x - c)^2 + \sigma^2}\]where the shape of the output array depends on the shape of the independent variable q and \(\sigma\) can have an explicit dependence on q as \(\sigma q**2\).
Parameters: - q (np.array or list) – array of momentum transfer q values
- qwise (bool, optional) – whether the width (sigma) has explicit dependence on q (default False)
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
- sigma
-
lmfit_presets.protein_liquid(q, qWise=False, **kwargs)¶ Model for protein in solution and jump diffusion for internal dynamics.
Parameters: - q (np.array or list) – Array of momentum transfer q-values to be used.
- qWise (bool) – Whether the Lorentzian width are independent for each momentum transfer q or not (explicit q-dependence of the form ‘width * q**2’).
- kwargs (dict) – Additional keyword arguments to pass to
build_2D_model()
Notes
- The parameter root names are:
- beta
- amplitude
- center
- sigma_g
- sigma_i
- tau
-
lmfit_presets.pseudo_voigt(q, **kwargs)¶ Pseudo-Voigt profile.
The shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- fraction
- center
- sigma
-
lmfit_presets.rotations(q, qwise=False, **kwargs)¶ Normalized Lorentzian accounting for rotational motions in liquids.
\[S_r(q, \omega) = A_r J_0^2(qd) \delta(\omega) + \sum_{l=1} (2l + 1) J_l^2(qd) \frac{1}{\pi} \frac{l(l+1) \sigma}{(\omega - center)^2 + (l(l+1) \sigma)^2}\]The shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- qwise (bool, optional) – whether the width (sigma) has explicit dependence on q (default False)
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
- sigma
- bondDist
References
For more information see: http://doi.org/10.1139/p66-108
-
lmfit_presets.two_diff_state(q, qwise=False, **kwargs)¶ Two state switching diffusion model.
The shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
- gamma1
- gamma2
- tau1
- tau2
References
For more information, see: http://doi.org/10.1063/1.4950889 or http://doi.org/10.1039/C4CP04944F
-
lmfit_presets.voigt(q, **kwargs)¶ Voigt profile.
The shape of the output array depends on the shape of the independent variable q.
Parameters: - q (np.array or list) – array of momentum transfer q values
- kwargs (dict, optional) – additional keywords to pass to
build_2D_model().
Notes
- The parameter root names are:
- amplitude
- center
- sigma
- gamma