Fitting workers

Fitting workers (fits) provide curve fitting. Each fit defines a dictionary of fitting parameters; they are individual per data item. Each fit in a pipeline requires subclassing from Fit.

class parseq.fits.basefit.Fit(node=None, widgetClass=None)

Parental Fit class. Must be subclassed to define the following class variables:

name: str name that must be unique within the pipeline.

defaultParams: dict of default fitting parameters for new data.

dataAttrs: dict of keys ‘x’, ‘y’ and ‘fit’ that defines the input and output arrays.

ioAttrs: dict of keys ‘range’, ‘params’ and ‘result’ that defines the key names in defaultParams for, correspondingly, fitting range (2-list), fitting parameters (user specific) and results (dict).

The method run_main() must be declared either with @staticmethod or @classmethod decorator. A returned not None value indicates success.

nThreads or nProcesses can be > 1 to use threading or multiprocessing. If both are > 1, threading is used. The value can be an integer, ‘all’ or ‘half’ which refer to the hardware limit multiprocessing.cpu_count().

progressTimeDelta, float, default 1.0 sec, a timeout delta to report on transformation progress. Only needed if run_main() is defined with a parameter progress.

__init__(node=None, widgetClass=None)

node is instance of core.nodes.Node.

widgetClass optional, widget class, descendant of gui.fits.gbasefit.FitWidget.

classmethod run_main(data)

Provides the actual functionality of the class. Other possible signatures:

run_main(cls, data, allData, progress)
run_main(cls, data, allData)
run_main(cls, data, progress)

data is a data item, instance of Spectrum.

allData and progress are both optional in the method’s signature. The keyword names must be kept as given above if they are used and must be in this given order if both are present.

allData is a list of all data items living in the data model. If allData is needed, both nThreads or nProcesses must be set to 1.

progress is an object having a field value. A heavy fit routine should periodically update this field, like this: progress.value = 0.5 (means 50% completion). If used with GUI, progress will be visualized as an expanding colored background rectangle in the data tree. Quick fits do not need progress reporting.

Should an error happen during the fitting, the error state will be notified in the ParSeq status bar and the traceback will be shown in the data item’s tooltip in the data tree view.

The method should update the ‘result’ entry in data.fitParams.

Fit widgets

Custom fit widgets are supposed to inherit from FitWidget that gives some common functionality to all fit widgets.

A custom widget typically instantiates a table view class for displaying fitting parameters and an associated table model class for it.

class parseq.gui.fits.gbasefit.FitWidget(*args: Any, **kwargs: Any)

Base widget for custom fit widgets. It sends fit parameters to the fit table model (provided by custom widgets), provides a range widget and reactions on it, a display widget for fit results and a start button. It also send fitReady signal to the node widget.