Epochs

class gpype.backend.flow.epochs.Epochs[source]

Bases: IONode

Cuts one epoch per marker of a condition, stacked into a trial axis.

Batch only, like Apply (D-BATCH-56): a realtime pipeline is refused with this node named. Selects on the events model rather than on a trigger column (D-BATCH-13) – every marker in the input context whose label equals condition becomes one trial, spanning [tmin, tmax) seconds around its sample.

An epoch that straddles a recording gap is refused outright, naming the trial and the gap (D-BATCH-12): a dense block across a dropout would silently mean less than it claims. One that runs off either end of the recording is dropped instead, and the count is logged once (D-BATCH-88). An unknown condition is refused, listing the labels the recording actually has.

The output has no samples in common with its input’s grid, so its context carries no markers or gaps (D-BATCH-86); it carries Constants.Keys.TRIALS instead – [[source_sample, label], ...], one entry per trial – which Result.trials reads. It also publishes time_pre/time_post the way Trigger does, so Baseline and EpochAverage work downstream of either.

Parameters:
  • condition (str) – The marker label to cut epochs around.

  • tmin (float) – Epoch start, in seconds relative to the marker’s sample. Negative for time before it.

  • tmax (float) – Epoch end, in seconds relative to the marker’s sample.

  • **kwargs – Additional arguments for the parent IONode.

Raises:

ValueError – If tmin is not earlier than tmax.

BATCH_ONLY = True

Refused outside a batch run, by Pipeline._validate (see Apply.BATCH_ONLY): the whole recording has to already be in hand for a marker’s neighbourhood to mean anything.

TIME_PRE = 'time_pre'

Context keys naming where the marker sits in the epoch, in the exact strings Trigger publishes and Baseline reads – so either node can feed a Baseline or an EpochAverage downstream.

TIME_POST = 'time_post'
class Configuration[source]

Bases: Configuration

Configuration class for Epochs parameters.

class Keys[source]

Bases: Keys

Configuration key constants for Epochs.

CONDITION = 'condition'

Marker label to cut epochs around

TMIN = 'tmin'

Epoch start, seconds relative to the marker

TMAX = 'tmax'

Epoch end, seconds relative to the marker

__init__(condition, tmin, tmax, **kwargs)[source]

Initialize the epoch cutter.

Parameters:
  • condition (str) – The marker label to cut epochs around.

  • tmin (float) – Epoch start in seconds relative to the marker.

  • tmax (float) – Epoch end in seconds relative to the marker.

  • **kwargs – Additional arguments for the parent IONode.

Raises:

ValueError – If tmin is not earlier than tmax.

setup(data, port_context_in)[source]

Resolve every trial’s slice against the input’s events model.

Parameters:
Return type:

dict[str, dict]

Returns:

Output port contexts.

Raises:

ValueError – If the context declares no sampling rate; if no marker matches condition, naming the labels present; or if an in-range epoch straddles a recording gap, naming the trial and the gap.

process(data)[source]

Cut every trial and stack them into a trial axis.

Parameters:

data (dict[str, ndarray]) – The complete recording, under key PORT_IN.

Return type:

dict[str, ndarray]

Returns:

(time, channel, trial) under key PORT_OUT.