Result
- class gpype.common.result.Result[source]
Bases:
objectOne 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:
- 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_exactis 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
unitsalone. 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 (seeChannel.si_scale), such as a derived unit.
- to_si()[source]
Return the samples in SI units:
datatimessi_scale.Volts for
uV,mVandnV, m/s^2 forg, rad/s fordeg/s, and a plain number for%andcount. In the data’s own precision, which for a run is float32.- Return type:
- 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
Channelper 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 casescript_only_nodesnames 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. APipeline.fit()run addsfitted_document, the document after the fit, with its artifacts.A deep copy, so editing what this returns cannot reach the context another
Resultreading 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 thesosfiltpath – 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, sorun()on the rebuild applies them.- Returns:
The recorded document.
- Return type:
- 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_timeis the absolute time of sample zero.
- to_numpy()[source]
Return the samples.
- Return type:
- 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; passtrialto draw one trial instead, and its line labels name whattrialsrecords for it. Either way, every event ineventsis drawn as a labelled vertical line.- Parameters:
- 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
trialis given for two-dimensional data, or iftrialis outside the trial axis.
- class gpype.common.result.Channel[source]
Bases:
objectOne 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
unitto 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,%,countands.
- __init__(name, role, unit, gain=None, offset=None, clipping=None, filters=())
- class gpype.common.result.Event[source]
Bases:
NamedTupleOne marker: a time and a label, plus two fields that earn it.
durationexists because “seizure from here to here” expressed as two markers forces a reader to pair them by matching label text, andchannelbecause “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.