Skip to content

visualdynamics.plot.averaging

averaging

Averaging frames drawn on the time history they will be cut from.

A list of frame start times does not show whether the analysis covers the part of the record that was intended, so the frames are drawn on the plot.

Above the trace is a rail: one row of slots, each frame's window drawn in its slot and shaded under the curve, so the window is shown where it is set and not over the data it is applied to. Frames that overlap cannot share a row without their windows running through each other, so each takes the lowest row whose last frame has already ended. That gives one row at no overlap, two at half overlap and four at three quarters.

Under each frame's slot, a band runs down to the bottom of the plot. Its height shows which row the frame is in, so where two frames overlap there are two heights and a step between them. Each band's shading follows its frame's window, so it shows the weight each part of the record carries in the average.

The span of all the frames is one draggable region. Dragging its middle slides the analysis along the record; dragging an edge adds or removes frames. Only whole frames are used, so when the drag ends the edge moves to the end of the last whole frame.

A capture the controller already cut into frames has nothing to drag, because the frame is the record. For it the region is drawn with locked and cannot be moved.

Classes:

Name Description
AveragingOverlay

Averaging parameters drawn as marks on a time history plot.

Classes

AveragingOverlay

AveragingOverlay(plot: Any, averaging: Averaging, sample_rate: float, samples: int, colors: Mapping[str, str], locked: bool = False, parent: Any = None, origin: float = 0.0)

Bases: QObject

Averaging parameters drawn as marks on a time history plot.

The overlay owns every item it adds and removes all of them in remove, so a redraw cannot leave a band behind. While it is up it raises the top of the plot's y range to make room for the rail, and remove gives the plot its own range back. A finished drag is reported through changed and not acted on here: storing the new averaging and updating the table are left to whatever created the overlay.

samples is the record's length in samples, which a drag cannot pass, and origin is the time of its first sample, the zero the averaging's start counts from.

Methods:

Name Description
remove

Remove every mark from the plot. The overlay cannot be used after this.

set_averaging

Draw a different averaging, such as one edited in the table, without emitting changed.

Source code in src/visualdynamics/plot/averaging.py
def __init__(self, plot: Any, averaging: Averaging, sample_rate: float,
             samples: int, colors: Mapping[str, str],
             locked: bool = False, parent: Any = None,
             origin: float = 0.0) -> None:
    super().__init__(parent)
    self.plot: Any = plot
    self.averaging: Averaging = averaging
    self.sample_rate: float = float(sample_rate)
    self.samples: int = int(samples)
    #: the record's first instant: the marks sit on the plot's
    #: clock, the averaging counts from the record's beginning
    self.origin: float = float(origin)
    self.colors: dict[str, str] = colors
    self.locked: bool = bool(locked)
    self.bands: list[Any] = []
    self.glyphs: list[Any] = []
    self.caps: list[Any] = []
    self.region: Any = None
    self._snapping = False
    #: the plot's own y limits, put back when the marks come off
    self._locked = None
    self._draw()
    # connected before the room is made, so that the marks follow the
    # range they are about to be given rather than the one they were
    # drawn against
    plot.getViewBox().sigYRangeChanged.connect(self._rescale)
    self._make_room()
Methods:
remove
remove() -> None

Remove every mark from the plot. The overlay cannot be used after this.

Source code in src/visualdynamics/plot/averaging.py
def remove(self) -> None:
    """Remove every mark from the plot. The overlay cannot be used after this."""
    try:
        self.plot.getViewBox().sigYRangeChanged.disconnect(self._rescale)
    except (RuntimeError, TypeError):
        # the view went first, which is the usual way a pane is torn
        # down; there is nothing left to disconnect from
        pass
    self._clear_items()
    try:
        # the room was for the rail; with the rail gone the trace
        # has the height, and the lock its own ceiling again
        view = self.plot.getViewBox()
        if self._locked is not None:
            view.setLimits(yMin=self._locked[0], yMax=self._locked[1])
            self._locked = None
        view.enableAutoRange(axis='y')
    except RuntimeError:
        pass
set_averaging
set_averaging(averaging: Averaging) -> None

Draw a different averaging, such as one edited in the table, without emitting changed.

Source code in src/visualdynamics/plot/averaging.py
def set_averaging(self, averaging: Averaging) -> None:
    """Draw a different averaging, such as one edited in the table, without emitting `changed`."""
    self.averaging = averaging
    self._redraw_marks()
    if self.region is not None:
        self._snap()

Functions: