psi.data package

Subpackages

Submodules

psi.data.api module

psi.data.plot_groups module

Grouped-epoch accumulation for the plotting subsystem.

EpochGroupAccumulator tracks epochs grouped by a (tab_key, plot_key) pair and implements the n_update batching rule: a group’s plot is only redrawn once at least n_update new epochs have arrived since its last redraw.

Averaging is incremental: each epoch is folded into a per-group running mean as it arrives (optionally through a transform applied per epoch, for plots that average in a transformed space such as dB-PSD). This keeps redraw cost proportional to the epoch length rather than to the number of epochs acquired so far, and means raw epochs do not need to be retained — memory is O(groups x samples) instead of O(total epochs).

Pure Python — no Qt — so the bookkeeping is testable without a GUI.

class psi.data.plot_groups.EpochGroupAccumulator(n_update=1, transform=None)[source]

Bases: object

add_epochs(epochs, group_key)[source]

Fold each epoch into the running mean for group_key(epoch.metadata).

Epochs whose key is None are excluded. Returns the key of the last epoch processed (which may be None), or None if epochs is empty.

count(key)[source]
get_mean(key)[source]

Running mean of the (transformed) epochs for this group, or None if the group has no epochs.

keys_for_tab(tab_key)[source]

Return all group keys whose tab component matches tab_key.

mark_updated(key)[source]
property max_samples

Longest epoch (in samples) seen across all groups (0 if no epochs).

needs_update(key)[source]
reset()[source]
tab_needs_update(tab_key)[source]

True if at least one group in the tab has accumulated enough new epochs to warrant a redraw.

transform

Applied to each epoch before folding it into the group mean (e.g., dB-PSD for FFT-averaged plots). Must be a pure function of the epoch; parameters it closes over (fs, channel, …) must not change once epochs have been folded. Defaults to np.asarray.

class psi.data.plot_groups.RunningMean[source]

Bases: object

Incremental mean of arrays, ignoring NaN values.

Arrays may grow along the last axis (ragged epochs): shorter arrays are treated as missing data (NaN) for the trailing samples, so the mean at each sample position reflects only the epochs that covered it.

Thread-safe: epochs are typically folded from an acquisition thread while the GUI thread reads the mean for rendering.

add(arr)[source]
property mean

Current mean, or None if nothing has been added. Positions never covered by any epoch are NaN.

psi.data.plot_ranges module

Data-range state machines for the plotting subsystem.

These track the currently-visible x-range of a plot container based on the data flowing through the attached sources. Pure Atom classes — no pyqtgraph/Qt — so the windowing semantics can be tested without a GUI.

class psi.data.plot_ranges.BaseDataRange[source]

Bases: Atom

add_source(source)[source]
container

A value which allows objects of a given type or types.

Values will be tested using the PyObject_TypeCheck C API call. This call is equivalent to type(obj) in cls.mro(). It is less flexible but can be faster than Instance. Use Instance when allowing you need a tuple of types or (abstract) types relying on custom __isinstancecheck__ and Typed when the value type is explicit.

If optional is True, the value of a Typed may be set to None, otherwise None is not considered as a valid value.

current_range

A member which allows tuple values.

If item validation is used, then assignment will create a copy of the original tuple before validating the items, since validation may change the item values.

data_received(data)[source]
delay

A value of type float.

By default, ints and longs will be promoted to floats. Pass strict=True to the constructor to enable strict float checking.

span

A value of type float.

By default, ints and longs will be promoted to floats. Pass strict=True to the constructor to enable strict float checking.

class psi.data.plot_ranges.ChannelDataRange[source]

Bases: BaseDataRange

add_source(source)[source]
current_time

A value of type float.

By default, ints and longs will be promoted to floats. Pass strict=True to the constructor to enable strict float checking.

data_received(data)[source]
track_sources

A member which allows list values.

Assigning to a list creates a copy. The orginal list will remain unmodified. This is similar to the semantics of the assignment operator on the C++ STL container classes.

class psi.data.plot_ranges.EpochDataRange[source]

Bases: BaseDataRange

add_source(source)[source]
data_received(data)[source]
max_duration

A value of type float.

By default, ints and longs will be promoted to floats. Pass strict=True to the constructor to enable strict float checking.

psi.data.plot_util module

Pure-Python helpers for the plotting subsystem.

Nothing in this module may import pyqtgraph or Qt: it holds the numeric and formatting logic (decimation, tick formatting, color cycles) so it can be tested without a GUI.

psi.data.plot_util.decimate_extremes(data, downsample)[source]
psi.data.plot_util.decimate_mean(data, downsample)[source]
psi.data.plot_util.format_log_ticks(values, scale, spacing)[source]
psi.data.plot_util.format_time(seconds, fmt='{H:02d}:{M:02d}:{S:02.0f}')[source]
psi.data.plot_util.get_color_cycle(name, n)[source]
psi.data.plot_util.get_freq(fs, duration)[source]
psi.data.plot_util.prepare_decimated_curve(data, t, downsample, mode)[source]

Prepare (x, y, plot_kw) arrays for rendering a channel trace.

Parameters:
  • data (1D array) – Signal for the visible range (NaN-filled where no data exists yet).

  • t (1D array) – Time axis matching data.

  • downsample (int) – Decimation factor (pixels per sample); applied when > 1 and mode is not ‘none’.

  • mode ({'extremes', 'mean', 'none'}) – Decimation strategy.

Returns:

  • (x, y, plot_kw) with empty arrays when the visible range contains no

  • data (i.e., the plot should be cleared), or None when x and y are

  • inconsistent (the caller should skip this update entirely — this can

  • happen transiently while buffers resize).

psi.data.plots module

psi.data.plugin module

Module contents