daplis_rtp.gui.widgets.gaussian_fit module
Gaussian fits of the lines in view, refreshed with every file.
The “Peak in view” box describes one peak, the brightest, by its shape alone. Aligning a spectrometer on a neon lamp wants more than that: every line on the sensor at once, and a width that is a fitted parameter with an uncertainty, so that a change in focus can be told apart from noise while the mirror is still being turned.
What counts as a line is decided by a threshold set by hand. Hot pixels and lines both stand above the dark floor, and nothing in one trace tells them apart reliably, but the person at the bench can see which is which - so the threshold is theirs to set, and the plot shows it as a dashed line to set it against.
A line is a run of neighbouring pixels above the threshold. Each run is fitted with a Gaussian on a constant background, over a window wide enough to see the background on either side, then fitted again over four sigmas of what the first fit found. Two lines close enough that the trace never drops below the threshold between them are one run and one fit: raise the threshold to split them.
The arithmetic is a plain function, like peak_stats, so that it can
be tested on shapes whose answers are known; the strip below only
displays what it returns.
- class daplis_rtp.gui.widgets.gaussian_fit.GaussianFitStrip(parent=None, scrollable=False)[source]
Bases:
QWidgetThe switch, the threshold, and one sigma per line, in one row.
Sits directly above the plot, under the row naming the brightest pixels, so that the widths being watched are read in the same glance as the peaks they belong to.
scrollableswaps the elided result line for one that scrolls sideways, for the full sensor, where the lines outrun the row.- changed
str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Type:
pyqtSignal(*types, name
- property enabled
- class daplis_rtp.gui.widgets.gaussian_fit.ScrollingLabel(text='', parent=None)[source]
Bases:
QScrollAreaA one-line readout that scrolls sideways instead of eliding.
For a line of results that can outgrow the row: every line on the full sensor is too many to fit, and an ellipsis hides exactly the ones at the far end. The mouse wheel or a click-and-drag moves along it. No scroll bar is drawn, since the row has the height of one line of text and no more.
The position is kept across refreshes, so a line scrolled into view stays in view while the stream runs.
- daplis_rtp.gui.widgets.gaussian_fit.describe_fit(fit, short=True)[source]
One line for one fit, as the strip and the export show it.
- daplis_rtp.gui.widgets.gaussian_fit.fit_peaks(rates, threshold, x_lim=None, valid=None)[source]
Fit a Gaussian to every line above
thresholdin view.- Parameters:
rates (array-like) – Photon rate per pixel, indexed by pixel number.
threshold (float) – Rate a pixel must exceed to belong to a line.
x_lim (tuple, optional) –
(low, high)pixel numbers, inclusive, as shown on the plot. The whole array when omitted.valid (array-like, optional) – Truthy for the pixels that may be used. Masked pixels read zero, and a zero inside a line would drag its fit down, so they are left out of the fit rather than fitted as data.
- Returns:
One per line, left to right. Each has
peak_pixel,lowandhigh(the window fitted). A successful fit addsamplitude,centre,sigmaandbackground, andcentre_errandsigma_err-Nonewhere the fit could not say. A failed one haserrorinstead, saying why.- Return type:
list of dict