EDF Writer

class gpype.backend.sinks.edf_writer.EDFWriter[source]

Bases: FileWriter

EDF+ (.edf) file writer for real-time data logging.

Buffers incoming blocks to whole EDF data records – writing a partial record per pipeline block was measured to interleave fabricated padding between the real samples – and records the true sample count as an EDF+ annotation, since EDF’s own header cannot express a count that is not a multiple of the record size. EDFReader trims to it.

The stream’s markers are written as EDF+ annotations, onset and duration in seconds. The annotation channel holds one annotation per data record, and the sample count takes the first, so a file of n records stores n - 1 markers. EDF+ annotations name no channel. A marker that does not fit, or that names a channel, is not written, and the writer logs how many at close. An annotation keeps 40 bytes of UTF-8 text, so a longer label is cut at a character boundary, and the writer names it. A marker past the last sample written is left out.

A trigger-role channel is written unscaled, with EDF’s digital range as its physical range, so an integer code in that range survives exactly. physical_min and physical_max apply to the others.

__init__(file_name, physical_min=-10000.0, physical_max=10000.0, edge_id=None, **kwargs)[source]

Initialize the EDF writer core.

Parameters:
  • file_name (str) – Base filename for the .edf output. A timestamp will be automatically appended.

  • physical_min (float) – Physical minimum value in uV, for every channel but a trigger (see above). Kept wide (-10000) by default: EDF clips silently outside this range (measured – see _write_block()), and the header is written in setup() before any sample is seen, so a streaming writer cannot auto-range. A caller who knows their signal’s true range can pass a tighter one for better resolution; clipping, if it then happens, is reported at close.

  • physical_max (float) – Physical maximum value in uV. See physical_min.

  • 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 passed to parent FileWriter.

Raises:

ValueError – If physical_max is not greater than physical_min.

property file_extension

Return the file extension for EDF files.

Returns:

The EDF file extension ‘.edf’.