CsvReader

class gpype.backend.sources.csv_reader.CsvReader[source]

Bases: FixedRateSource

Replays a recording as if it were a live source.

This is what makes a session repeatable: a chain can be debugged without a subject present, yesterday’s recording can be run through a changed pipeline, and a regression test can use real data instead of a synthetic approximation of it.

Channel names are taken from the file’s header, so a recording made with a montage keeps its electrode names on the way back in.

speed decides what “replay” means. At one the file is paced to the wall clock, so the recording behaves like the amplifier that produced it and everything downstream sees the timing it expects. At zero it runs as fast as the machine allows, which is what offline reprocessing wants.

TIME_BASE = 'recorded'

Positions advance through the file, not with the host clock, so this stream cannot be merged with a live one.

__init__(file_name, sampling_rate=None, frame_size=1, speed=1.0, loop=False, mode='realtime', edge_id=None, **kwargs)[source]

Initialize the reader core.

Parameters:
  • file_name (str) – Path to the recording.

  • sampling_rate (Optional[float]) – The recording’s rate. Taken from the file’s time column when not given; required without one. One given must agree with the time column.

  • frame_size (int) – Samples emitted per cycle. In batch mode the frame is the whole recording.

  • speed (float) – Replay speed relative to real time. Zero runs as fast as the machine allows.

  • loop (bool) – Start again from the beginning at the end of the file.

  • mode (str) – realtime to replay frame by frame, batch to emit the whole recording in one cycle. See Constants.ExecutionMode.

  • edge_id (Optional[str]) – Which edge runs this node, matched against the edge process’s –edge-id. None, the default, is every edge; ignored when the pipeline is not distributed.

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

Raises:

ValueError – If no file name is given, if the rate can neither be read from the file nor was supplied, if a realtime-only argument is combined with batch mode, or if a sampling_rate, channel_count or batch frame_size given by hand disagrees with the file. A document’s copy is warned about and replaced by the file’s.

start()[source]

Start the reader.

A batch run has no pacing thread: the driver calls cycle() once and the whole recording is emitted in that one call. Starting the thread as well would race the driver for the same file position, and the run would end with part of the recording processed twice.

property sample_count

Number of samples in the file.

property mark

The entitlement mark recovered from the file, if it had one.

None for a file written by an unmarked run, or where the file was not read.

property is_exhausted

Whether the whole recording has been emitted.

Returns:

True once the last sample has been handed over. Never true for a looping reader.

setup(data, port_context_in)[source]

Describe the replayed channels.

Parameters:
Return type:

dict[str, dict]

Returns:

Output port contexts carrying the file’s channel names and, where the file was read, its identity.

step(data)[source]

Emit the next frame of the recording.

Return type:

dict[str, ndarray]

Returns:

The next frame, or None on a non-decimation step or once the file is exhausted.