FitWidget
¶
This module provides a widget designed to configure and run a fitting process with constraints on parameters.
The main class is FitWidget
. It relies on
silx.math.fit.fitmanager
, which relies on silx.math.fit.leastsq()
.
The user can choose between functions before running the fit. These function can
be user defined, or by default are loaded from
silx.math.fit.fittheories
.
For a tutorial on how to use FitWidget
, see Using FitWidget.
API¶
-
class
FitWidget
(parent=None, title=None, fitmngr=None, enableconfig=True, enablestatus=True, enablebuttons=True)[source]¶ This widget can be used to configure, run and display results of a fitting process.
The standard steps for using this widget is to initialize it, then load the data to be fitted.
Optionally, you can also load user defined fit theories. If you skip this step, a series of default fit functions will be presented (gaussian-like functions), and you can later load your custom fit theories from an external file using the GUI.
A fit theory is a fit function and its associated features:
- estimation function,
- list of parameter names
- numerical derivative algorithm
- configuration widget
Once the widget is up and running, the user may select a fit theory and a background theory, change configuration parameters specific to the theory run the estimation, set constraints on parameters and run the actual fit.
The results are displayed in a table.
-
__init__
(parent=None, title=None, fitmngr=None, enableconfig=True, enablestatus=True, enablebuttons=True)[source]¶ Parameters: - parent – Parent widget
- title – Window title
- fitmngr – User defined instance of
silx.math.fit.fitmanager.FitManager
, orNone
- enableconfig – If
True
, activate widgets to modify the fit configuration (select between several fit functions or background functions, apply global constraints, peak search parameters…) - enablestatus – If
True
, add a fit status widget, to display a message when fit estimation is available and when fit results are available, as well as a measure of the fit error. - enablebuttons – If
True
, add buttons to run estimation and fitting.
-
associateConfigDialog
(theory_name, config_widget, theory_is_background=False)[source]¶ Associate an instance of custom configuration dialog widget to a fit theory or to a background theory.
This adds or modifies an item in the correspondence table
configdialogs
orbgconfigdialogs
.Parameters: - theory_name (str) – Name of fit theory. This must be a key of dict
fitmanager.theories
- config_widget – Custom configuration widget. See documentation
for
configdialogs
- theory_is_background (bool) – If flag is True, add dialog to
bgconfigdialogs
rather thanconfigdialogs
(default).
Raise: KeyError if parameter
theory_name
does not match an existing fit theory or background theory infitmanager
.Raise: AttributeError if the widget does not implement the mandatory methods (show, exec_, result, setDefault) or the mandatory attribute (output).
- theory_name (str) – Name of fit theory. This must be a key of dict
-
setData
(x=None, y=None, sigmay=None, xmin=None, xmax=None)[source]¶ Set data to be fitted.
Parameters: - x (Sequence or numpy array or None) – Abscissa data. If
None
,xdata`
is set tonumpy.array([0.0, 1.0, 2.0, ..., len(y)-1])
- y (Sequence or numpy array or None) – The dependant data
y = f(x)
.y
must have the same shape asx
ifx
is notNone
. - sigmay (Sequence or numpy array or None) – The uncertainties in the
ydata
array. These are used as weights in the least-squares problem. IfNone
, the uncertainties are assumed to be 1. - xmin – Lower value of x values to use for fitting
- xmax – Upper value of x values to use for fitting
- x (Sequence or numpy array or None) – Abscissa data. If