Result

class gpype.common.result.Result[source]

Bases: object

One node’s output from a batch run, with what describes it.

A bare array plus a dictionary is not a deliverable: the pipeline computes channel labels, roles and a sampling rate, and handing back a tuple makes every caller rebuild that bookkeeping. So this is the object a run returns.

It is a view over the port context, not a second metadata store. Anything the context gains – units, calibration, events, gaps, trust state – becomes readable here without a change to how it travels. Fields the context does not carry yet are absent rather than faked, so adding them later is additive and nothing has to guess what a default meant. The same holds for a per-channel list whose length is not the channel count: a node upstream changed the channels and not the list, so it describes other channels.

Parameters:
  • data (ndarray) – The block the node emitted, shape (time, channel) or (time, channel, trial).

  • context (Optional[dict]) – The input port context the node was set up with.

  • name (Optional[str]) – Name of the node that produced it, if known.

__init__(data, context=None, name=None)[source]
property data

The samples, (time, channel[, trial]).

property context

The port context this was described by, as a copy.

property name

Name of the node that produced this, if known.

property rate

Sampling rate in Hz, or None if the context carries none.

A float, which is what the engine computes with; rate_exact is the fraction, where the source knows it.

property rate_exact

Sampling rate as an exact fraction, or None.

None unless the source knows the rate exactly and the fraction still agrees with rate: one describing some other rate is worse than none, so a stale one is withheld.

property labels

Channel labels, or None when the channels are unnamed.

property roles

Per-channel roles, or None when none describe these channels.

No roles declared at all means every channel is a signal channel – the same reading the rest of the framework gives it.

property units

Physical unit per channel, or None if none are recorded.

None means the source does not record units, which is not the same as dimensionless – a distinction worth keeping, because unit confusion silently produces plots off by a million.

property si_scale

Factor from each channel’s unit to its SI unit, or None.

Derived from units alone. None when no units are recorded, because absent is not dimensionless. An entry is None where that channel’s unit is not recorded, or is not one g.Pype knows (see Channel.si_scale), such as a derived unit.

to_si()[source]

Return the samples in SI units: data times si_scale.

Volts for uV, mV and nV, m/s^2 for g, rad/s for deg/s, and a plain number for % and count. In the data’s own precision, which for a run is float32.

Return type:

ndarray

Returns:

A new array shaped like data.

Raises:

ValueError – If the result records no units, or a channel’s unit is not recorded or not known. A missing unit is never taken to be microvolts.

property channels

what a source states about it – name, role, unit, and GTC’s calibration field set.

Type:

One Channel per channel

property start_time

Absolute time of the first sample, or None.

Parsed here rather than in the context, which carries an ISO string because it crosses a Link as JSON.

property trust

How much the source vouches for the data, or None.

A result derived from an unsealed or recovered recording says so here, and should say so wherever it is displayed.

property provenance

This run’s provenance record, or None.

None before Pipeline.start() has stamped one – a context built by hand rather than by a running pipeline. Otherwise the document (unless the pipeline held a function node, in which case script_only_nodes names it instead), its content hash, package versions, execution mode, any already-fitted artifacts and what trained them, and this stream’s own input under "input" – nested under "input"]["derived_from"] when the file it came from was itself a g.Pype recording: reprocessing a g.Pype output yields a lineage chain. A Pipeline.fit() run adds fitted_document, the document after the fit, with its artifacts.

A deep copy, so editing what this returns cannot reach the context another Result reading the same run would see.

document()[source]

The document that produced this result, ready to rebuild.

Recovers a pipeline from its own result: pass this to Pipeline.deserialize(), giving it fresh ids first (common.document.with_fresh_ids) to rebuild in the same process without colliding with a still-live one. The rebuilt run is bit-exact against this one only along the sosfilt path – a phase-nonlinear filter and anything touching a live clock are not.

From a Pipeline.fit() run, the document after the fit, carrying its artifacts, so run() on the rebuild applies them.

Returns:

The recorded document.

Return type:

dict

Raises:

ValueError – If this result carries no provenance record at all, the run it describes held a function node (Apply, or an @gp.node) – a document could never rebuild one, so none was recorded; the message names it – or its pipeline could not be saved, and the message says why.

property gaps

Recording interruptions inside this result.

Empty when the source records none. A dense block across a dropout is silently wrong, so anything cutting epochs has to consult this.

property events

Markers inside this result, relative to its first sample.

property trials

Per-trial provenance of a (time, channel, trial) result.

Empty when the context records none, which includes every two-dimensional result: a trial axis is what this describes.

property channel_count

Number of channels.

property sample_count

Number of samples on the time axis.

property duration

Length in seconds, or None without a known rate.

property times

Sample times in seconds from the first sample, or None.

Relative, not absolute: where the source records one, start_time is the absolute time of sample zero.

to_numpy()[source]

Return the samples.

Return type:

ndarray

Returns:

The underlying array, not a copy – callers that intend to modify it should copy first.

to_dataframe()[source]

Return the samples as a pandas DataFrame, time-indexed.

Returns:

A DataFrame with one column per channel.

Raises:
  • ImportError – If pandas is not installed. It is not a g.Pype dependency; this method exists for callers who have it.

  • ValueError – If the data is not two-dimensional.

plot(ax=None, trial=None)[source]

Plot every channel against time, and mark any events.

A (time, channel) result draws one line per channel. A (time, channel, trial) result draws the mean across trials by default; pass trial to draw one trial instead, and its line labels name what trials records for it. Either way, every event in events is drawn as a labelled vertical line.

Parameters:
  • ax – Axes to draw on. A new figure is created if omitted.

  • trial (Optional[int]) – Index of the one trial to draw. None (the default) draws the mean over the trial axis; meaningless, and refused, for a two-dimensional result.

Returns:

The Axes drawn on, so the caller can label or save it.

Raises:
  • ImportError – If matplotlib is not installed. It is not a g.Pype dependency – the Qt scopes are for realtime, and a batch result should not need a widget host.

  • ValueError – If the data is neither two- nor three-dimensional, if trial is given for two-dimensional data, or if trial is outside the trial axis.

__len__()[source]

Number of samples, so len(result) reads as expected.

Return type:

int

__repr__()[source]

One line saying what this is.

A result that prints its shape, rate, duration, channels and trust state is the difference between a REPL session that explains itself and one that prints an object address.

Return type:

str

class gpype.common.result.Channel[source]

Bases: object

One channel of a result: what it is, how it is treated, its unit.

A frozen dataclass rather than a tuple, so a field can be added later without breaking a caller that unpacks it – which is how gain, offset, clipping and filters arrived: additive fields, defaulting to None or empty for a source that records none of GTC’s CHAN field set.

name

Label, or None when the channel is unnamed.

role

Role from Constants.ChannelRoles. Signal when the context declares no roles; None when the roles it declares describe a different number of channels.

unit

Physical unit, or None when none is recorded.

gain = None

Stored-to-physical gain, exact, or None when not recorded.

offset = None

Stored-to-physical offset, exact, or None when not recorded.

clipping = None

(low, high) this channel was clipped to before storage, in its own unit, or None when not recorded.

filters = ()

Hardware filters already applied, oldest first; empty when none were, or when the source does not record this.

property si_scale

Factor from unit to its SI unit, or None.

None when the unit is not recorded, or is not one g.Pype knows, such as a derived unit. The known units are V, mV, uV (also written with a micro sign), nV, g, deg/s, %, count and s.

__init__(name, role, unit, gain=None, offset=None, clipping=None, filters=())
class gpype.common.result.Event[source]

Bases: NamedTuple

One marker: a time and a label, plus two fields that earn it.

duration exists because “seizure from here to here” expressed as two markers forces a reader to pair them by matching label text, and channel because “channel 7 went bad at 1200 s” has to be machine-readable. Both mirror the GTC marker model rather than a smaller one of g.Pype’s own.

sample

Sample index, relative to the first sample of the result.

duration

Length in samples; zero for a point event.

channel

Channel the event is about, or None for the whole recording.

label

What it says. A string; no numeric codes, no registry.

class gpype.common.result.Gap[source]

Bases: NamedTuple

A recording interruption, on the sample grid.

first_missing

First sample that is missing.

n_missing

How many samples are missing.

reason

Why, as the recording states it.