edfio.Bdf#
- class edfio.Bdf(signals, *, patient=None, recording=None, starttime=None, data_record_duration=None, annotations=None)[source]#
Python representation of a BDF file.
See
Edffor information on the header fields and their types.Note
BDF uses 24-bit integers (compared to 16-bit for EDF) for the digital values. The default for
digital_range(and the supported depth) thus differs.Attributes
All annotations contained in the Bdf, sorted chronologically.
Number of bytes in the header record.
Duration of each data record in seconds.
Recording duration in seconds.
The labels of all signals contained in the Bdf.
Unparsed string representation of the legacy local patient identification.
Unparsed string representation of the legacy local recording identification.
Number of data records in the recording.
Return the number of signals, excluding annotation signals for BDF+.
Parsed object representation of the local patient identification.
Parsed object representation of the local recording identification.
"BDF+C"for an BDF+C file, else"".Ordinary signals contained in the recording.
Recording startdate.
Recording starttime.
The BDF version, always
�BIOSEMI.Methods
__init__Add annotations to the Bdf.
Anonymize a recording.
Append one or more signal(s) to the Bdf recording.
Create a deep copy of the Bdf.
Drop annotations with a given text.
Drop signals by index or label.
All annotations defined (starting) in a specified time region of the Bdf, sorted chronologically.
Retrieve a single signal by its label.
Overwrite all annotations with new ones.
Slice to the interval between two BDF+ annotations.
Slice to the interval between two times.
Convert an Bdf to a
bytesobject.Update the data record duration.
Write an Bdf to a file or file-like object.
- add_annotations(annotations)[source]#
Add annotations to the Bdf.
This removes all existing annotation signals and adds a new one containing the old and new annotations as the last signal in the file.
- Parameters:
- annotations
Iterable[EdfAnnotation] The annotations to add.
- annotations
- property annotations[source]#
All annotations contained in the Bdf, sorted chronologically.
Does not include timekeeping annotations.
- anonymize(*, keep_age=False, keep_sex=False, keep_starttime=False)[source]#
Anonymize a recording.
- By default, header fields are modified as follows:
local patient identification is set to
X X X Xlocal recording identification is set to
Startdate X X X Xstartdate is set to
01.01.85starttime is set to
00.00.00
For BDF+ files, subsecond starttimes specified via an annotations signal are removed.
Optionally, parts of the original information can be preserved by setting the corresponding parameters to True (see below).
- Parameters:
- keep_agebool, default:
False Whether to keep age information relative to the anonymized start date in the local patient identification. If True, the birthdate is set to January 1st of the year that preserves the age relative to
01.01.85. This implies that the local patient identification is set toX X 01-JAN-YYYY X, whereYYYYis the age-preserving year.- keep_sexbool, default:
False Whether to keep the sex field in the local patient identification.
- keep_starttimebool, default:
False Whether to keep the original start time.
- keep_agebool, default:
- append_signals(new_signals)[source]#
Append one or more signal(s) to the Bdf recording.
Every signal must be compatible with the current
data_record_durationand all signal durations must match the overall recording duration. For recordings containing BDF+ annotation signals, the new signals are inserted after the last ordinary (i.e. non-annotation) signal.
- drop_annotations(text)[source]#
Drop annotations with a given text.
- Parameters:
- text
str All annotations whose text exactly matches this parameter are removed.
- text
- drop_signals(drop)[source]#
Drop signals by index or label.
_Signal indices (int) and labels (str) can be provided in the same iterable. For ambiguous labels, all corresponding signals are dropped. Raises a ValueError if at least one of the provided identifiers does not correspond to a signal.
- get_annotations(start_second=None, stop_second=None)[source]#
All annotations defined (starting) in a specified time region of the Bdf, sorted chronologically.
Does not include timekeeping annotations. Will not include annotations that start within the specified time region but are defined in data records outside of that window.
- get_signal(label)[source]#
Retrieve a single signal by its label.
The label has to be unique - a ValueError is raised if it is ambiguous or does not exist.
- property local_patient_identification[source]#
Unparsed string representation of the legacy local patient identification.
- property local_recording_identification[source]#
Unparsed string representation of the legacy local recording identification.
- property patient[source]#
Parsed object representation of the local patient identification.
See
Patientfor information on its attributes.
- property recording[source]#
Parsed object representation of the local recording identification.
See
Recordingfor information on its attributes.
- set_annotations(annotations)[source]#
Overwrite all annotations with new ones.
This removes all existing annotation signals and adds a new one as the last signal in the file.
- Parameters:
- annotations
Iterable[EdfAnnotation] The annotations to set.
- annotations
- property signals[source]#
Ordinary signals contained in the recording.
Annotation signals are excluded. Individual signals can not be removed, added, or replaced by modifying this property. Use
Bdf.append_signals(),Bdf.drop_signals(), orBdfSignal.data, respectively.
- slice_between_annotations(start_text, stop_text, *, keep_all_annotations=False)[source]#
Slice to the interval between two BDF+ annotations.
The sample point corresponding to the onset of the annotation identified by
stop_textis excluded.start_textandstop_texteach have to uniquely identify a single annotation, whose onset corresponds exactly to a sample time in all non-annotation signals.
- slice_between_seconds(start, stop, *, keep_all_annotations=False)[source]#
Slice to the interval between two times.
The sample point corresponding to
stopis excluded.startandstopare given in seconds from recording start and have to correspond exactly to a sample time in all non-annotation signals.
- property startdate[source]#
Recording startdate.
If the
local_recording_identificationconforms to the BDF+ standard, the startdate provided there is used. If not, this falls back to the legacystartdatefield. If both differ, a warning is issued and the BDF+ field is preferred. Raises anAnonymizedDateErrorif the BDF+ field is anonymized (i.e., begins withStartdate X).
- to_bytes()[source]#
Convert an Bdf to a
bytesobject.- Returns:
bytesThe binary representation of the Bdf object (i.e., what a file created with
Bdf.writewould contain).
- update_data_record_duration(data_record_duration, method='strict')[source]#
Update the data record duration.
This operation will fail if the new duration is incompatible with the current sampling frequencies.
- Parameters:
- data_record_duration
float The new data record duration in seconds.
- method
{"strict", "pad", "truncate"}, default:"strict" How to handle the case where the new duration does not divide the Bdf duration evenly
“strict”: Raise a ValueError
“pad”: Pad the data with zeros to the next compatible duration. If zero is outside the physical range, data is padded with the physical minimum.
“truncate”: Truncate the data to the previous compatible duration (might lead to loss of data)
- data_record_duration
- write(target)[source]#
Write an Bdf to a file or file-like object.
- Parameters:
- target
Path|str|io.BufferedWriter|io.BytesIO The file location (path object or string) or file-like object to write to.
- target