edfrw.writer

Write data to files in European Data Format (EDF).

EdfWriter(filename, header, saving_period_s)

Bases: object

Open an EDF for writing.

Attributes:

Name Type Description
filename str

EDF file name.

header object of `class::EdfHeader`

File header.

saving_period_s int

How often to write data to the EDF file.

closed bool

Whether the file has been closed.

Create and open an EDF file for writing.

Parameters:

Name Type Description Default
filename str

EDF file name.

required
header instance of

The file header.

required
saving_period_s integer

How often (in seconds) will the data be saved to disk? This value sets EDF header’s duration_of_data_record, which is the duration in seconds of one data record.

From the specification: “The duration of each data record is recommended to be a whole number of seconds and its size (number of bytes) is recommended not to exceed 61440. Only if a 1s data record exceeds this size limit, the duration is recommended to be smaller than 1s (e.g. 0.01).”

required

close()

Close the EDF file

update_number_of_records()

Update the number of data records in the file header.

Writes to the header the most recent value of ‘number_of_data_records’ (referred to as ‘nr’ in the EDF specification).

By definition, this value is 8-bits long and it starts at position 236 in the header.

write_data_record(buffer)

Write one data record.

Parameters:

Name Type Description Default
buffer uint16

The data to be save to disk. It must be an unsigned 16-bit integer, two-complement values, as required by the EDF file format specification.

required
Notes

Signals are allowed to be acquired at different sampling rates. The data are saved in data blocks (named ‘data records’ in the specification). The total number of samples in the block is thus determined by adding the sizes of the individual signals (signal.number_of_samples_in_data_record).

Each data block holds all data acquired during a time interval of header.duration_of_data_record seconds, and the total number of data records in the file are header.number_of_data_records.

Thus, to write a data block (data record), the data must be the concatenation of samples acquired during the period of time duration_of_data_record first all samples from signal 0, then signal 1, etc:

signal_0.samples[sig_0_number_of_samples_in_data_record] signal_1.samples[sig_1_number_of_samples_in_data_record]

write_header()

Write the EDF header to the current file.

Packs the header record attributes in the format required by EDF and writes these values at the beginning of the current file.