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: QWidget

The 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.

scrollable swaps the elided result line for one that scrolls sideways, for the full sensor, where the lines outrun the row.

__init__(parent=None, scrollable=False)[source]
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

clear(text='')[source]
property enabled
show_fits(fits)[source]

Render one refresh’s fits, sigma first, in the result line.

threshold()[source]
class daplis_rtp.gui.widgets.gaussian_fit.ScrollingLabel(text='', parent=None)[source]

Bases: QScrollArea

A 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.

__init__(text='', parent=None)[source]
eventFilter(self, a0: QObject | None, a1: QEvent | None) → bool[source]
minimumSizeHint(self) → QSize[source]
mouseMoveEvent(self, a0: QMouseEvent | None)[source]
mousePressEvent(self, a0: QMouseEvent | None)[source]
mouseReleaseEvent(self, a0: QMouseEvent | None)[source]
setText(text)[source]
setToolTip(self, a0: str | None)[source]
text()[source]
wheelEvent(self, a0: QWheelEvent | None)[source]
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 threshold in 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, low and high (the window fitted). A successful fit adds amplitude, centre, sigma and background, and centre_err and sigma_err - None where the fit could not say. A failed one has error instead, saying why.

Return type:

list of dict

daplis_rtp.gui.widgets.gaussian_fit.gaussian(x, amplitude, centre, sigma, background)[source]

The model every line is fitted with.