Epoching nodes


class timeflux.nodes.epoch.Epoch(event_trigger, before=0.2, after=0.6)[source]

Bases: timeflux.core.node.Node

Event-triggered epoching.

This node continuously buffers a small amount of data (of a duration of before seconds) from the default input stream. When it detects a marker matching the event_trigger in the label column of the event input stream, it starts accumulating data for after seconds. It then sends the epoched data to an output stream, and sets the metadata to a dictionary containing the triggering marker and optional event data. Multiple, overlapping epochs are authorized. Each concurrent epoch is assigned its own Port. For convenience, the first epoch is bound to the default output, so you can avoid enumerating all output ports if you expects only one epoch.

  • i (Port) – Default data input, expects DataFrame.

  • i_events (Port) – Event input, expects DataFrame.

  • o (Port) – Default output, provides DataFrame and meta.

  • o_* (Port) – Dynamic outputs, provide DataFrame and meta.

  • event_trigger (string) – The marker name.

  • before (float) – Length before onset, in seconds.

  • after (float) – Length after onset, in seconds.



  # Nothing is displayed because the epoch does not have any event input
  - id: example
    - id: random
      module: timeflux.nodes.random
      class: Random
    - id: epoch
      module: timeflux.nodes.epoch
      class: Epoch
        event_trigger: test
    - id: display
      module: timeflux.nodes.debug
      class: Display
    - source: random
      target: epoch
    - source: epoch
      target: display
    rate: 10

Create instance and initialize the logger.

class timeflux.nodes.epoch.ToXArray(reporting='warn', output='DataArray', context_key=None)[source]

Bases: timeflux.core.node.Node

Convert multiple epochs to DataArray

This node iterates over input ports with valid epochs, concatenates them on the first axis, and creates a XArray with dimensions (‘epoch’, ‘time’, ‘space’) where epoch corresponds to th input ports, time to the ports data index and space to the ports data columns. A port is considered to be valid if it has meta with key ‘epoch’ and data with expected number of samples. If some epoch have an invalid length (which happens when the data has jitter), the node either raises a warning, an error or pass.

  • i_* (Port) – Dynamic inputs, expects DataFrame and meta.

  • o (Port) – Default output, provides DataArray and meta.

  • reporting (string| None) – How this function handles epochs with invalid length: warn will issue a warning with warnings.warn(), error will raise an exception, None will ignore it.

  • output (DataArray`|`Dataset) – Type of output to return

  • context_key (string|None) – If output type is Dataset, key to define the target of the event. If None, the whole context is considered.

Create instance and initialize the logger.