EDF/BDF file writer edfwriter

class pyedflib.EdfWriter(file_name, n_channels, file_type=1)[source]

Bases: object

Methods

blockWritePhysicalSamples(self, data) Writes physical samples (uV, mA, Ohm) must be filled with samples from all signals where each signal has n samples which is the samplefrequency of the signal.
close(self) Closes the file.
setAdmincode(self, admincode) Sets the admincode.
setBirthdate(self, birthdate) Sets the birthdate.
setDatarecordDuration(self, duration) Sets the datarecord duration.
setDigitalMaximum(self, edfsignal, …) Sets the maximum digital value of signal edfsignal.
setDigitalMinimum(self, edfsignal, …) Sets the minimum digital value of signal edfsignal.
setEquipment(self, equipment) Sets the name of the param equipment used during the aquisition.
setGender(self, gender) Sets the gender.
setHeader(self, fileHeader) Sets the file header
setLabel(self, edfsignal, label) Sets the label (name) of signal edfsignal (“FP1”, “SaO2”, etc.).
setPatientAdditional(self, patient_additional) Sets the additional patientinfo to patient_additional.
setPatientCode(self, patient_code) Sets the patientcode to patient_code.
setPatientName(self, patient_name) Sets the patientname to patient_name.
setPhysicalDimension(self, edfsignal, …) Sets the physical dimension of signal edfsignal (“uV”, “BPM”, “mA”, “Degr.”, etc.)
setPhysicalMaximum(self, edfsignal, …) Sets the physical_maximum of signal edfsignal.
setPhysicalMinimum(self, edfsignal, …) Sets the physical_minimum of signal edfsignal.
setPrefilter(self, edfsignal, prefilter) Sets the prefilter of signal edfsignal (“HP:0.1Hz”, “LP:75Hz N:50Hz”, etc.)
setRecordingAdditional(self, …) Sets the additional recordinginfo
setSamplefrequency(self, edfsignal, …) Sets the samplefrequency of signal edfsignal.
setSignalHeader(self, edfsignal, channel_info) Sets the parameter for signal edfsignal.
setSignalHeaders(self, signalHeaders) Sets the parameter for all signals
setStartdatetime(self, recording_start_time) Sets the recording start Time
setTechnician(self, technician) Sets the technicians name to technician.
setTransducer(self, edfsignal, transducer) Sets the transducer of signal edfsignal
set_number_of_annotation_signals(self, …) Sets the number of annotation signals.
update_header(self) Updates header to edffile struct
writeAnnotation(self, onset_in_seconds, …) Writes an annotation/event to the file
writePhysicalSamples(self, data) Writes n physical samples (uV, mA, Ohm) belonging to one signal where n is the samplefrequency of the signal.
writeSamples(self, data_list[, digital]) Writes physical samples (uV, mA, Ohm) from data belonging to all signals The physical samples will be converted to digital samples using the values of physical maximum, physical minimum, digital maximum and digital minimum.
blockWriteDigitalSamples  
blockWriteDigitalShortSamples  
writeDigitalSamples  
writeDigitalShortSamples  
blockWriteDigitalSamples(self, data)[source]
blockWriteDigitalShortSamples(self, data)[source]
blockWritePhysicalSamples(self, data)[source]

Writes physical samples (uV, mA, Ohm) must be filled with samples from all signals where each signal has n samples which is the samplefrequency of the signal.

data_vec belonging to one signal. The size must be the samplefrequency of the signal.

Notes

buf must be filled with samples from all signals, starting with signal 0, 1, 2, etc. one block equals one second The physical samples will be converted to digital samples using the values of physical maximum, physical minimum, digital maximum and digital minimum The number of samples written is equal to the sum of the samplefrequencies of all signals Size of buf should be equal to or bigger than sizeof(double) multiplied by the sum of the samplefrequencies of all signals Returns 0 on success, otherwise -1

All parameters must be already written into the bdf/edf-file.

close(self)[source]

Closes the file.

setAdmincode(self, admincode)[source]

Sets the admincode.

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

Parameters:
admincode : str

admincode which is written into the header

setBirthdate(self, birthdate)[source]

Sets the birthdate.

Parameters:
birthdate: date object from datetime

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

Examples

>>> import pyedflib
>>> from datetime import datetime, date
>>> f = pyedflib.EdfWriter('test.bdf', 1, file_type=pyedflib.FILETYPE_BDFPLUS)
>>> f.setBirthdate(date(1951, 8, 2))
>>> f.close()
setDatarecordDuration(self, duration)[source]

Sets the datarecord duration. The default value is 100000 which is 1 second. ATTENTION: the argument “duration” is expressed in units of 10 microSeconds! So, if you want to set the datarecord duration to 0.1 second, you must give the argument “duration” a value of “10000”. This function is optional, normally you don’t need to change the default value. The datarecord duration must be in the range 0.001 to 60 seconds. Returns 0 on success, otherwise -1.

Parameters:
duration : integer

Sets the datarecord duration in units of 10 microSeconds

Notes

This function is NOT REQUIRED but can be called after opening a file in writemode and before the first sample write action. This function can be used when you want to use a samplerate which is not an integer. For example, if you want to use a samplerate of 0.5 Hz, set the samplefrequency to 5 Hz and the datarecord duration to 10 seconds. Do not use this function, except when absolutely necessary!

setDigitalMaximum(self, edfsignal, digital_maximum)[source]

Sets the maximum digital value of signal edfsignal. Usually, the value 32767 is used for EDF+ and 8388607 for BDF+.

Parameters:
edfsignal : int

signal number

digital_maximum : int

Sets the maximum digital value

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setDigitalMinimum(self, edfsignal, digital_minimum)[source]

Sets the minimum digital value of signal edfsignal. Usually, the value -32768 is used for EDF+ and -8388608 for BDF+. Usually this will be (-(digital_maximum + 1)).

Parameters:
edfsignal : int

signal number

digital_minimum : int

Sets the minimum digital value

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setEquipment(self, equipment)[source]

Sets the name of the param equipment used during the aquisition. This function is optional and can be called only after opening a file in writemode and before the first sample write action.

Parameters:
equipment : str

Describes the measurement equpipment

setGender(self, gender)[source]

Sets the gender. This function is optional and can be called only after opening a file in writemode and before the first sample write action.

Parameters:
gender : int

1 is male, 0 is female

setHeader(self, fileHeader)[source]

Sets the file header

setLabel(self, edfsignal, label)[source]

Sets the label (name) of signal edfsignal (“FP1”, “SaO2”, etc.).

Parameters:
edfsignal : int

signal number on which the label should be changed

label : str

signal label

Notes

This function is recommended for every signal and can be called only after opening a file in writemode and before the first sample write action.

setPatientAdditional(self, patient_additional)[source]

Sets the additional patientinfo to patient_additional.

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setPatientCode(self, patient_code)[source]

Sets the patientcode to patient_code.

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setPatientName(self, patient_name)[source]

Sets the patientname to patient_name.

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setPhysicalDimension(self, edfsignal, physical_dimension)[source]

Sets the physical dimension of signal edfsignal (“uV”, “BPM”, “mA”, “Degr.”, etc.)

Parameters:
  • edfsignal – int
  • physical_dimension – str

Notes

This function is recommended for every signal and can be called only after opening a file in writemode and before the first sample write action.

setPhysicalMaximum(self, edfsignal, physical_maximum)[source]

Sets the physical_maximum of signal edfsignal.

Parameters:
edfsignal: int

signal number

physical_maximum: float

Sets the physical maximum

Notes

This function is required for every signal and can be called only after opening a file in writemode and before the first sample write action.

setPhysicalMinimum(self, edfsignal, physical_minimum)[source]

Sets the physical_minimum of signal edfsignal.

Parameters:
edfsignal: int

signal number

physical_minimum: float

Sets the physical minimum

Notes

This function is required for every signal and can be called only after opening a file in writemode and before the first sample write action.

setPrefilter(self, edfsignal, prefilter)[source]

Sets the prefilter of signal edfsignal (“HP:0.1Hz”, “LP:75Hz N:50Hz”, etc.)

Parameters:
  • edfsignal – int
  • prefilter – str

Notes

This function is optional for every signal and can be called only after opening a file in writemode and before the first sample write action.

setRecordingAdditional(self, recording_additional)[source]

Sets the additional recordinginfo

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setSamplefrequency(self, edfsignal, samplefrequency)[source]

Sets the samplefrequency of signal edfsignal.

Notes

This function is required for every signal and can be called only after opening a file in writemode and before the first sample write action.

setSignalHeader(self, edfsignal, channel_info)[source]

Sets the parameter for signal edfsignal.

channel_info should be a dict with these values:

‘label’ : channel label (string, <= 16 characters, must be unique) ‘dimension’ : physical dimension (e.g., mV) (string, <= 8 characters) ‘sample_rate’ : sample frequency in hertz (int). Deprecated: use ‘sample_frequency’ instead. ‘sample_frequency’ : number of samples per record (int) ‘physical_max’ : maximum physical value (float) ‘physical_min’ : minimum physical value (float) ‘digital_max’ : maximum digital value (int, -2**15 <= x < 2**15) ‘digital_min’ : minimum digital value (int, -2**15 <= x < 2**15)
setSignalHeaders(self, signalHeaders)[source]

Sets the parameter for all signals

Parameters:
signalHeaders : array_like
containing dict with
‘label’ : str

channel label (string, <= 16 characters, must be unique)

‘dimension’ : str

physical dimension (e.g., mV) (string, <= 8 characters)

‘sample_rate’ :

sample frequency in hertz (int). Deprecated: use ‘sample_frequency’ instead.

‘sample_frequency’ : int

number of samples per record

‘physical_max’ : float

maximum physical value

‘physical_min’ : float

minimum physical value

‘digital_max’ : int

maximum digital value (-2**15 <= x < 2**15)

‘digital_min’ : int

minimum digital value (-2**15 <= x < 2**15)

setStartdatetime(self, recording_start_time)[source]

Sets the recording start Time

Parameters:
recording_start_time: datetime object

Sets the recording start Time

setTechnician(self, technician)[source]

Sets the technicians name to technician.

Notes

This function is optional and can be called only after opening a file in writemode and before the first sample write action.

setTransducer(self, edfsignal, transducer)[source]

Sets the transducer of signal edfsignal

Parameters:
  • edfsignal – int
  • transducer – str

Notes

This function is optional for every signal and can be called only after opening a file in writemode and before the first sample write action.

set_number_of_annotation_signals(self, number_of_annotations)[source]

Sets the number of annotation signals. The default value is 1 This function is optional and can be called only after opening a file in writemode and before the first sample write action Normally you don’t need to change the default value. Only when the number of annotations you want to write is more than the number of seconds of the duration of the recording, you can use this function to increase the storage space for annotations Minimum is 1, maximum is 64

Parameters:
number_of_annotations : integer

Sets the number of annotation signals

update_header(self)[source]

Updates header to edffile struct

writeAnnotation(self, onset_in_seconds, duration_in_seconds, description, str_format='utf-8')[source]

Writes an annotation/event to the file

writeDigitalSamples(self, data)[source]
writeDigitalShortSamples(self, data)[source]
writePhysicalSamples(self, data)[source]

Writes n physical samples (uV, mA, Ohm) belonging to one signal where n is the samplefrequency of the signal.

data_vec belonging to one signal. The size must be the samplefrequency of the signal.

Notes

Writes n physical samples (uV, mA, Ohm) from data_vec belonging to one signal where n is the samplefrequency of the signal. The physical samples will be converted to digital samples using the values of physical maximum, physical minimum, digital maximum and digital minimum. The number of samples written is equal to the samplefrequency of the signal. Call this function for every signal in the file. The order is important! When there are 4 signals in the file, the order of calling this function must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc.

All parameters must be already written into the bdf/edf-file.

writeSamples(self, data_list, digital=False)[source]

Writes physical samples (uV, mA, Ohm) from data belonging to all signals The physical samples will be converted to digital samples using the values of physical maximum, physical minimum, digital maximum and digital minimum. if the samplefrequency of all signals are equal, then the data could be saved into a matrix with the size (N,signals) If the samplefrequency is different, then sample_freq is a vector containing all the different samplefrequencys. The data is saved as list. Each list entry contains a vector with the data of one signal.

If digital is True, digital signals (as directly from the ADC) will be expected. (e.g. int16 from 0 to 2048)

All parameters must be already written into the bdf/edf-file.