API reference#

exception edfio.AnonymizedDateError[source]#

Raised when trying to access an anonymized startdate or birthdate.

with_traceback()[source]#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class edfio.Bdf(signals, *, patient=None, recording=None, starttime=None, data_record_duration=None, annotations=None)[source]#

Python representation of a BDF file.

See Edf for 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.

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:
annotationsIterable[EdfAnnotation]

The annotations to add.

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 X

  • local recording identification is set to Startdate X X X X

  • startdate is set to 01.01.85

  • starttime 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 to X X 01-JAN-YYYY X, where YYYY is 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.

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_duration and 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.

Parameters:
new_signalsBdfSignal | Iterable[BdfSignal]

The signal(s) to add.

property bytes_in_header_record[source]#

Number of bytes in the header record.

copy()[source]#

Create a deep copy of the Bdf.

Returns:
Bdf

The copied Bdf object.

property data_record_duration[source]#

Duration of each data record in seconds.

drop_annotations(text)[source]#

Drop annotations with a given text.

Parameters:
textstr

All annotations whose text exactly matches this parameter are removed.

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.

Parameters:
dropIterable[int | str]

The signals to drop, identified by index or label.

property duration[source]#

Recording duration in seconds.

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.

Parameters:
start_secondfloat, optional

The start of the time region in seconds from recording start. If not provided, the start of the recording is used.

stop_secondfloat, optional

The end of the time region in seconds. If not provided, the end of the recording is used.

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.

Parameters:
labelstr

A label identifying a single signal

Returns:
BdfSignal

The signal corresponding to the given label.

property labels[source]#

The labels of all signals contained in the Bdf.

Returns:
tuple[str, …]

The labels, in order of the signals.

property local_patient_identification[source]#

Unparsed string representation of the legacy local patient identification.

See also

patient

Parsed representation, as a Patient object.

property local_recording_identification[source]#

Unparsed string representation of the legacy local recording identification.

See also

recording

Parsed representation, as a Recording object.

property num_data_records[source]#

Number of data records in the recording.

property num_signals[source]#

Return the number of signals, excluding annotation signals for BDF+.

property patient[source]#

Parsed object representation of the local patient identification.

See Patient for information on its attributes.

property recording[source]#

Parsed object representation of the local recording identification.

See Recording for information on its attributes.

property reserved[source]#

"BDF+C" for an BDF+C file, else "".

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:
annotationsIterable[EdfAnnotation]

The annotations to set.

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(), or BdfSignal.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_text is excluded. start_text and stop_text each have to uniquely identify a single annotation, whose onset corresponds exactly to a sample time in all non-annotation signals.

Parameters:
start_textstr

Text identifying the start annotation.

stop_textstr

Text identifying the stop annotation.

keep_all_annotationsbool, default: False

If set to True, annotations outside the selected time interval are kept.

slice_between_seconds(start, stop, *, keep_all_annotations=False)[source]#

Slice to the interval between two times.

The sample point corresponding to stop is excluded. start and stop are given in seconds from recording start and have to correspond exactly to a sample time in all non-annotation signals.

Parameters:
startfloat

Start time in seconds from recording start.

stopfloat

Stop time in seconds from recording start.

keep_all_annotationsbool, default: False

If set to True, annotations outside the selected time interval are kept.

property startdate[source]#

Recording startdate.

If the local_recording_identification conforms to the BDF+ standard, the startdate provided there is used. If not, this falls back to the legacy startdate field. If both differ, a warning is issued and the BDF+ field is preferred. Raises an AnonymizedDateError if the BDF+ field is anonymized (i.e., begins with Startdate X).

property starttime[source]#

Recording starttime.

In BDF+ files, microsecond accuracy is supported.

to_bytes()[source]#

Convert an Bdf to a bytes object.

Returns:
bytes

The binary representation of the Bdf object (i.e., what a file created with Bdf.write would 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_durationfloat

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)

property version[source]#

The BDF version, always �BIOSEMI.

write(target)[source]#

Write an Bdf to a file or file-like object.

Parameters:
targetPath | str | io.BufferedWriter | io.BytesIO

The file location (path object or string) or file-like object to write to.

class edfio.BdfSignal(data, sampling_frequency, *, label='', transducer_type='', physical_dimension='', physical_range=None, digital_range=(-8388608, 8388607), prefiltering='')[source]#

A single BDF signal.

See EdfSignal for details on the parameters and attributes.

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.

property data[source]#

Numpy array containing the physical signal values as floats.

To simplify avoiding inconsistencies between signal data and header fields, individual values in the returned array can not be modified. Use BdfSignal.update_data() to overwrite with new physical data.

property digital[source]#

Numpy array containing the digital (uncalibrated) signal values as integers.

The values of the array may be accessed and modified directly.

For EDF these are 16-bit integers, for BDF these are 32-bit integers.

property digital_max[source]#

Digital maximum, e.g., 2047.

property digital_min[source]#

Digital minimum, e.g., -2048.

property digital_range[source]#

The digital range as a tuple of (digital_min, digital_max).

classmethod from_hypnogram(stages, stage_duration=30, *, label='')[source]#

Create an EDF signal from a hypnogram, with scaling according to EDF specs.

According to the EDF FAQ [1], use integer numbers 0, 1, 2, 3, 4, 5, 6, and 9 for sleep stages W, 1, 2, 3, 4, R, MT, und unscored, respectively. The digital range is set to (0, 9).

Parameters:
stagesnpt.NDArray[np.float64]

The sleep stages, coded as integer numbers.

stage_durationfloat, default: 30

The duration of each sleep stage in seconds, used to set the sampling frequency to its inverse.

labelstr, default: ""

The signal’s label.

Returns:
BdfSignal

The resulting BdfSignal object.

References

get_data_slice(start_second, stop_second)[source]#

Get a slice of the signal data.

If the signal has not been loaded into memory so far, only the requested slice will be read.

Parameters:
start_secondfloat

The start of the slice in seconds.

stop_secondfloat

The end of the slice in seconds.

get_digital_slice(start_second, stop_second)[source]#

Get a slice of the digital signal values.

If the signal has not been loaded into memory so far, only the requested slice will be read.

Parameters:
start_secondfloat

The start of the slice in seconds.

stop_secondfloat

The end of the slice in seconds.

property label[source]#

Signal label, e.g., "EEG Fpz-Cz" or "Body temp".

property physical_dimension[source]#

Physical dimension, e.g., "uV" or "degreeC.

property physical_max[source]#

Physical maximum, e.g., 500 or 40.

property physical_min[source]#

Physical minimum, e.g., -500 or 34.

property physical_range[source]#

The physical range as a tuple of (physical_min, physical_max).

property prefiltering[source]#

Signal prefiltering, e.g., "HP:0.1Hz LP:75Hz".

property reserved[source]#

Reserved signal header field, always "".

property samples_per_data_record[source]#

Number of samples in each data record.

For newly instantiated BdfSignal objects, this is only set once Bdf.write() is called.

property sampling_frequency[source]#

The sampling frequency in Hz.

property transducer_type[source]#

Transducer type, e.g., "AgAgCl electrode".

update_data(data, *, keep_physical_range=False, sampling_frequency=None)[source]#

Overwrite physical signal values with an array of equal length.

Parameters:
datanpt.NDArray[np.float64]

The new physical data.

keep_physical_rangebool, default: False

If True, the physical_range is not modified to accomodate the new data.

sampling_frequencyfloat | None, default: None

If not None, the sampling_frequency is updated to the new value. The new data must match the expected length for the new sampling frequency.

class edfio.Edf(signals, *, patient=None, recording=None, starttime=None, data_record_duration=None, annotations=None)[source]#

Python representation of an EDF file.

EDF header fields are exposed as properties with appropriate data types (i.e., string, numeric, date, or time objects). Fields that might break the file on modification (i.e., version, bytes_in_header_record, reserved, num_data_records, data_record_duration, and num_signals) can not be set after instantiation.

Note that the startdate has to be set via the parameter recording.

For writing an EDF file with a non-integer seconds duration, currently an appropriate value for data_record_duration has to be provided manually.

Parameters:
signalsSequence[EdfSignal]

The (non-annotation) signals to be contained in the EDF file.

patientPatient | None, default: None

The “local patient identification”, containing patient code, sex, birthdate, name, and optional additional fields. If None, the field is set to X X X X in accordance with EDF+ specs.

recordingRecording | None, default: None

The “local recording identification”, containing recording startdate, hospital administration code, investigator/technical code, equipment code, and optional additional fields. If None, the field is set to Startdate X X X X in accordance with EDF+ specs.

starttimedatetime.time | None, default: None

The starttime of the recording. If None, 00.00.00 is used. If starttime contains microseconds, an EDF+C file is created.

data_record_durationfloat | None, default: None

The duration of each data record in seconds. If None, an appropriate value is chosen automatically.

annotationsIterable[EdfAnnotation] | None, default: None

The annotations, consisting of onset, duration (optional), and text. If not None, an EDF+C file is created.

add_annotations(annotations)[source]#

Add annotations to the Edf.

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:
annotationsIterable[EdfAnnotation]

The annotations to add.

property annotations[source]#

All annotations contained in the Edf, 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 X

  • local recording identification is set to Startdate X X X X

  • startdate is set to 01.01.85

  • starttime is set to 00.00.00

For EDF+ 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 to X X 01-JAN-YYYY X, where YYYY is 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.

append_signals(new_signals)[source]#

Append one or more signal(s) to the Edf recording.

Every signal must be compatible with the current data_record_duration and all signal durations must match the overall recording duration. For recordings containing EDF+ annotation signals, the new signals are inserted after the last ordinary (i.e. non-annotation) signal.

Parameters:
new_signalsEdfSignal | Iterable[EdfSignal]

The signal(s) to add.

property bytes_in_header_record[source]#

Number of bytes in the header record.

copy()[source]#

Create a deep copy of the Edf.

Returns:
Edf

The copied Edf object.

property data_record_duration[source]#

Duration of each data record in seconds.

drop_annotations(text)[source]#

Drop annotations with a given text.

Parameters:
textstr

All annotations whose text exactly matches this parameter are removed.

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.

Parameters:
dropIterable[int | str]

The signals to drop, identified by index or label.

property duration[source]#

Recording duration in seconds.

get_annotations(start_second=None, stop_second=None)[source]#

All annotations defined (starting) in a specified time region of the Edf, 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.

Parameters:
start_secondfloat, optional

The start of the time region in seconds from recording start. If not provided, the start of the recording is used.

stop_secondfloat, optional

The end of the time region in seconds. If not provided, the end of the recording is used.

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.

Parameters:
labelstr

A label identifying a single signal

Returns:
EdfSignal

The signal corresponding to the given label.

property labels[source]#

The labels of all signals contained in the Edf.

Returns:
tuple[str, …]

The labels, in order of the signals.

property local_patient_identification[source]#

Unparsed string representation of the legacy local patient identification.

See also

patient

Parsed representation, as a Patient object.

property local_recording_identification[source]#

Unparsed string representation of the legacy local recording identification.

See also

recording

Parsed representation, as a Recording object.

property num_data_records[source]#

Number of data records in the recording.

property num_signals[source]#

Return the number of signals, excluding annotation signals for EDF+.

property patient[source]#

Parsed object representation of the local patient identification.

See Patient for information on its attributes.

property recording[source]#

Parsed object representation of the local recording identification.

See Recording for information on its attributes.

property reserved[source]#

"EDF+C" for an EDF+C file, else "".

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:
annotationsIterable[EdfAnnotation]

The annotations to set.

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 Edf.append_signals(), Edf.drop_signals(), or EdfSignal.data, respectively.

slice_between_annotations(start_text, stop_text, *, keep_all_annotations=False)[source]#

Slice to the interval between two EDF+ annotations.

The sample point corresponding to the onset of the annotation identified by stop_text is excluded. start_text and stop_text each have to uniquely identify a single annotation, whose onset corresponds exactly to a sample time in all non-annotation signals.

Parameters:
start_textstr

Text identifying the start annotation.

stop_textstr

Text identifying the stop annotation.

keep_all_annotationsbool, default: False

If set to True, annotations outside the selected time interval are kept.

slice_between_seconds(start, stop, *, keep_all_annotations=False)[source]#

Slice to the interval between two times.

The sample point corresponding to stop is excluded. start and stop are given in seconds from recording start and have to correspond exactly to a sample time in all non-annotation signals.

Parameters:
startfloat

Start time in seconds from recording start.

stopfloat

Stop time in seconds from recording start.

keep_all_annotationsbool, default: False

If set to True, annotations outside the selected time interval are kept.

property startdate[source]#

Recording startdate.

If the local_recording_identification conforms to the EDF+ standard, the startdate provided there is used. If not, this falls back to the legacy startdate field. If both differ, a warning is issued and the EDF+ field is preferred. Raises an AnonymizedDateError if the EDF+ field is anonymized (i.e., begins with Startdate X).

property starttime[source]#

Recording starttime.

In EDF+ files, microsecond accuracy is supported.

to_bytes()[source]#

Convert an Edf to a bytes object.

Returns:
bytes

The binary representation of the Edf object (i.e., what a file created with Edf.write would 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_durationfloat

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 Edf 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)

property version[source]#

EDF version, always 0.

write(target)[source]#

Write an Edf to a file or file-like object.

Parameters:
targetPath | str | io.BufferedWriter | io.BytesIO

The file location (path object or string) or file-like object to write to.

class edfio.EdfAnnotation(onset, duration, text)[source]#

A single EDF+ annotation.

Parameters:
onsetfloat

The annotation onset in seconds from recording start.

durationfloat | None

The annotation duration in seconds (None if annotation has no duration).

textstr

The annotation text, can be empty.

count(value, /)[source]#

Return number of occurrences of value.

duration[source]#

Alias for field number 1

index(value, start=0, stop=sys.maxsize, /)[source]#

Return first index of value.

Raises ValueError if the value is not present.

onset[source]#

Alias for field number 0

text[source]#

Alias for field number 2

class edfio.EdfSignal(data, sampling_frequency, *, label='', transducer_type='', physical_dimension='', physical_range=None, digital_range=(-32768, 32767), prefiltering='')[source]#

A single EDF signal.

Attributes that might break the signal or file on modification (i.e., sampling_frequency, physical_range, digital_range, samples_per_data_record, and reserved) can not be set after instantiation.

To reduce memory consumption, signal data is always stored as a 16-bit integer array containing the digital values that would be written to the corresponding EDF file. Therefore, it is expected that EdfSignal.data does not match the physical values passed during instantiation exactly.

Parameters:
datanpt.NDArray[np.float64]

The signal data (physical values).

sampling_frequencyfloat

The sampling frequency in Hz.

labelstr, default: ""

The signal’s label, e.g., "EEG Fpz-Cz" or "Body temp".

transducer_typestr, default: ""

The transducer type, e.g., "AgAgCl electrode".

physical_dimensionstr, default: ""

The physical dimension, e.g., "uV" or "degreeC"

physical_rangetuple[float, float], default: (-32768, 32767)

The physical range given as a tuple of (physical_min, physical_max). If None, this is determined from the data.

digital_rangetuple[int, int] | None, default: None

The digital range given as a tuple of (digital_min, digital_max). Uses the maximum resolution of 16-bit integers.

prefilteringstr, default: ""

The signal prefiltering, e.g., "HP:0.1Hz LP:75Hz".

property data[source]#

Numpy array containing the physical signal values as floats.

To simplify avoiding inconsistencies between signal data and header fields, individual values in the returned array can not be modified. Use EdfSignal.update_data() to overwrite with new physical data.

property digital[source]#

Numpy array containing the digital (uncalibrated) signal values as integers.

The values of the array may be accessed and modified directly.

For EDF these are 16-bit integers, for BDF these are 32-bit integers.

property digital_max[source]#

Digital maximum, e.g., 2047.

property digital_min[source]#

Digital minimum, e.g., -2048.

property digital_range[source]#

The digital range as a tuple of (digital_min, digital_max).

classmethod from_hypnogram(stages, stage_duration=30, *, label='')[source]#

Create an EDF signal from a hypnogram, with scaling according to EDF specs.

According to the EDF FAQ [1], use integer numbers 0, 1, 2, 3, 4, 5, 6, and 9 for sleep stages W, 1, 2, 3, 4, R, MT, und unscored, respectively. The digital range is set to (0, 9).

Parameters:
stagesnpt.NDArray[np.float64]

The sleep stages, coded as integer numbers.

stage_durationfloat, default: 30

The duration of each sleep stage in seconds, used to set the sampling frequency to its inverse.

labelstr, default: ""

The signal’s label.

Returns:
EdfSignal

The resulting EdfSignal object.

References

get_data_slice(start_second, stop_second)[source]#

Get a slice of the signal data.

If the signal has not been loaded into memory so far, only the requested slice will be read.

Parameters:
start_secondfloat

The start of the slice in seconds.

stop_secondfloat

The end of the slice in seconds.

get_digital_slice(start_second, stop_second)[source]#

Get a slice of the digital signal values.

If the signal has not been loaded into memory so far, only the requested slice will be read.

Parameters:
start_secondfloat

The start of the slice in seconds.

stop_secondfloat

The end of the slice in seconds.

property label[source]#

Signal label, e.g., "EEG Fpz-Cz" or "Body temp".

property physical_dimension[source]#

Physical dimension, e.g., "uV" or "degreeC.

property physical_max[source]#

Physical maximum, e.g., 500 or 40.

property physical_min[source]#

Physical minimum, e.g., -500 or 34.

property physical_range[source]#

The physical range as a tuple of (physical_min, physical_max).

property prefiltering[source]#

Signal prefiltering, e.g., "HP:0.1Hz LP:75Hz".

property reserved[source]#

Reserved signal header field, always "".

property samples_per_data_record[source]#

Number of samples in each data record.

For newly instantiated EdfSignal objects, this is only set once Edf.write() is called.

property sampling_frequency[source]#

The sampling frequency in Hz.

property transducer_type[source]#

Transducer type, e.g., "AgAgCl electrode".

update_data(data, *, keep_physical_range=False, sampling_frequency=None)[source]#

Overwrite physical signal values with an array of equal length.

Parameters:
datanpt.NDArray[np.float64]

The new physical data.

keep_physical_rangebool, default: False

If True, the physical_range is not modified to accomodate the new data.

sampling_frequencyfloat | None, default: None

If not None, the sampling_frequency is updated to the new value. The new data must match the expected length for the new sampling frequency.

class edfio.Patient(*, code='X', sex='X', birthdate=None, name='X', additional=())[source]#

Object representation of the local patient identification.

Parsing from/to the string containing the local_patient_identification header field is done according to the EDF+ specs. Subfields must be ASCII (32..126) and may not contain spaces.

Parameters:
codestr, default: "X"

The code by which the patient is known in the hospital administration.

sex{"X", "F", "M"}, default: "X"

Sex, F for female, M for male, X if anonymized.

birthdatedatetime.date | None, default: None

Patient birthdate, stored as X if None.

namestr, default: "X"

The patient’s name, stored as X if None.

additionalSequence[str], default: ()

Optional additional subfields. Will be stored in the header field separated by spaces.

property additional[source]#

Optional additional subfields.

property birthdate[source]#

Patient birthdate.

property code[source]#

The code by which the patient is known in the hospital administration.

get_subfield(idx)[source]#

Access a subfield of the local patient identification field by index.

Parameters:
idxint

The index of the subfield to access.

Returns:
str

The subfield at the specified index. If the index exceeds the actually available number of subfields, the return value is "X".

property name[source]#

The patient’s name.

property sex[source]#

Sex, F for female, M for male, X if anonymized.

class edfio.Recording(*, startdate=None, hospital_administration_code='X', investigator_technician_code='X', equipment_code='X', additional=())[source]#

Object representation of the local recording identification.

Parsing from/to the string containing the local_recording_identification header field is done according to the EDF+ specs. Subfields must be ASCII (32..126) and may not contain spaces.

Parameters:
startdatedatetime.date | None, default: None

The recording startdate.

hospital_administration_codestr, default: "X"

The hospital administration code of the investigation, e.g., EEG number or PSG number.

investigator_technician_codestr, default: "X"

A code specifying the responsible investigator or technician.

equipment_codestr, default: "X"

A code specifying the used equipment.

additionalSequence[str], default: ()

Optional additional subfields. Will be stored in the header field separated by spaces.

property additional[source]#

Optional additional subfields.

property equipment_code[source]#

A code specifying the used equipment.

get_subfield(idx)[source]#

Access a subfield of the local recording identification field by index.

Parameters:
idxint

The index of the subfield to access. The first subfield (starting at index 0) should always be “Startdate” according to the EDF+ spedification.

Returns:
str

The subfield at the specified index. If the index exceeds the actually available number of subfields, the return value is "X".

property hospital_administration_code[source]#

The hospital administration code of the investigation.

property investigator_technician_code[source]#

A code specifying the responsible investigator or technician.

property startdate[source]#

The recording startdate.

edfio.read_bdf(bdf_file, *, header_encoding='ascii')[source]#

Read a BDF file into a Bdf object.

If a file-like object is passed, its stream position is moved to EOF.

Parameters:
bdf_filePath | str | io.BufferedReader | io.BytesIO

The file location (path object or string) or file-like object to read from.

header_encodingstr, default: “ascii”

The character encoding to use when reading header fields.

Returns:
Bdf

The resulting Bdf object.

edfio.read_edf(edf_file, lazy_load_data='auto', *, header_encoding='ascii')[source]#

Read an EDF file into an Edf object.

If a file-like object is passed, its stream position is moved to EOF.

Parameters:
edf_filePath | str | io.BufferedReader | io.BytesIO

The file location (path object or string) or file-like object to read from.

lazy_load_databool | {“auto”}, default: “auto”

If True, the raw signal data is not loaded into memory until it is accessed. If False, the data is loaded immediately. If "auto", the data is loaded lazily if the specified edf_file represents a local path and the extension is not “.bdf” and eagerly otherwise.

header_encodingstr, default: “ascii”

The character encoding to use when reading header fields.

Returns:
Edf

The resulting Edf object.

read_bdf

Read a BDF file into a Bdf object.

read_edf

Read an EDF file into an Edf object.

Bdf

Python representation of a BDF file.

BdfSignal

A single BDF signal.

Edf

Python representation of an EDF file.

EdfSignal

A single EDF signal.

EdfAnnotation

A single EDF+ annotation.

Patient

Object representation of the local patient identification.

Recording

Object representation of the local recording identification.

AnonymizedDateError

Raised when trying to access an anonymized startdate or birthdate.