API Reference¶
read_edf(source, *, physical=True, dtype=None, tzinfo=None, eager_load_samples=False)
¶
Open and parse an EDF/EDF+ file, returning an :class:EDFFile.
The returned object contains parsed header metadata and wired
:class:Signal instances. Sample data is loaded lazily on first access
to signal.samples or signal.load(), unless eager_load_samples
is True.
| PARAMETER | DESCRIPTION |
|---|---|
source
|
Path to the EDF file (as
TYPE:
|
physical
|
When
TYPE:
|
dtype
|
Optional NumPy dtype to cast scaled physical values to (e.g.
TYPE:
|
tzinfo
|
Optional timezone info to attach to the parsed start time and
start datetime.
TYPE:
|
eager_load_samples
|
When
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EDFFile
|
A fully-constructed :class: |
EDFFile
|
and (for EDF+ files) annotations. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
FileNotFoundError
|
If |
PermissionError
|
If |
ValueError
|
If |
Source code in src/edfplus/reader.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
EDFFile(header, signals, annotations, _f, _all_signals=None, _record_onsets=None)
¶
Top-level container returned by read_edf().
Holds the parsed header, all wired Signal instances (with lazy loading),
and an Annotation list for EDF+ files. The underlying file handle is
kept open for lazy signal loading. Always use the context-manager protocol
or call close() when done.
Signals are populated immediately upon construction. Sample data is loaded
lazily on first access to signal.samples or signal.load(), unless
eager_load_samples=True was passed to read_edf().
| PARAMETER | DESCRIPTION |
|---|---|
header
|
Parsed
TYPE:
|
signals
|
List of non-annotation
TYPE:
|
annotations
|
List of
TYPE:
|
_f
|
Open binary file handle for lazy data record reading.
TYPE:
|
_all_signals
|
Full list of all
TYPE:
|
_record_onsets
|
Per-record time-keeping onsets for EDF+D files.
TYPE:
|
Source code in src/edfplus/_models.py
EDFHeader(version, local_patient_id, local_recording_id, num_records, record_duration, num_signals, header_bytes, variant, start_date, start_time, start_datetime, patient_code, patient_sex, patient_birthdate, patient_name, recording_startdate, recording_admin_code, recording_technician, recording_equipment, _raw_global, _raw_signals)
dataclass
¶
Parsed global header from a 256-byte EDF/EDF+ header block.
| ATTRIBUTE | DESCRIPTION |
|---|---|
version |
Version field, always
TYPE:
|
local_patient_id |
Raw 80-byte local patient identification field, stripped.
TYPE:
|
local_recording_id |
Raw 80-byte local recording identification field, stripped.
TYPE:
|
num_records |
Number of data records in the file (inferred from file size when
the on-disk value is
TYPE:
|
record_duration |
Duration of each data record in seconds.
TYPE:
|
num_signals |
Total number of signals (
TYPE:
|
header_bytes |
Total header size in bytes (
TYPE:
|
variant |
EDF variant detected from the reserved field. One of
TYPE:
|
start_date |
Recording start date. Year is interpreted with the two-digit rule:
TYPE:
|
start_time |
Recording start time. Timezone-naive unless a
TYPE:
|
start_datetime |
Combined
TYPE:
|
patient_code |
Hospital/patient code from the EDF+ patient identification
subfield;
TYPE:
|
patient_sex |
Sex subfield from the EDF+ patient identification;
TYPE:
|
patient_birthdate |
Parsed birthdate from the EDF+ patient identification
subfield;
TYPE:
|
patient_name |
Patient name from the EDF+ patient identification subfield;
TYPE:
|
recording_startdate |
Recording start date parsed from the EDF+ recording
identification subfield;
TYPE:
|
recording_admin_code |
Investigation/admin code from the EDF+ recording
identification subfield;
TYPE:
|
recording_technician |
Technician/investigator code from the EDF+ recording
identification subfield;
TYPE:
|
recording_equipment |
Equipment code from the EDF+ recording identification
subfield;
TYPE:
|
_raw_global |
Original 256 bytes of the global header, preserved for round-trip fidelity.
TYPE:
|
_raw_signals |
Original
TYPE:
|
Signal(label, transducer_type, physical_dimension, physical_min, physical_max, digital_min, digital_max, prefiltering, samples_per_record, sample_rate, is_annotation, index, _edf_file=None, _edf_header=None, _byte_offset_in_record=0, _bytes_per_record=0, _physical=True, _dtype=None)
dataclass
¶
A single EDF/EDF+ signal channel with header metadata and lazy sample loading.
All per-signal header fields are stored directly as dataclass fields.
Sample data is loaded lazily: accessing the samples property auto-loads
from disk on first access (if a parent EDFFile weakref is wired), or raises
RuntimeError if the signal is not wired to a file.
| ATTRIBUTE | DESCRIPTION |
|---|---|
label |
Signal label, stripped of leading/trailing whitespace.
TYPE:
|
transducer_type |
Transducer type string.
TYPE:
|
physical_dimension |
Physical dimension (unit) string.
TYPE:
|
physical_min |
Physical minimum calibration value.
TYPE:
|
physical_max |
Physical maximum calibration value.
TYPE:
|
digital_min |
Minimum raw digital (int16) value.
TYPE:
|
digital_max |
Maximum raw digital (int16) value.
TYPE:
|
prefiltering |
Pre-filtering description string.
TYPE:
|
samples_per_record |
Number of samples in each data record for this signal.
TYPE:
|
sample_rate |
Sample rate in Hz (
TYPE:
|
is_annotation |
TYPE:
|
index |
0-based position of this signal in the file's signal list.
TYPE:
|
samples
property
¶
Loaded sample array (physical float64 by default, or raw int16 if unscaled).
Auto-loads from disk on first access if wired to an EDFFile.
load(start=None, stop=None, *, onset=None, duration=None)
¶
Load and return a slice of the signal's samples.
Supports flexible cropping by sample index, seconds, datetime, or timedelta.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
Start position. int=sample index, float=seconds, datetime=absolute, timedelta=offset from recording start.
TYPE:
|
stop
|
Stop position (same type interpretation as start).
TYPE:
|
onset
|
Alias for start. Cannot be used together with start.
TYPE:
|
duration
|
Duration from start. float=seconds, timedelta=offset. Cannot be used together with stop.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A NumPy array of the cropped samples. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If both start and onset are specified, or both stop and duration are specified. |
Source code in src/edfplus/_models.py
load_with_timestamps(start=None, stop=None, *, onset=None, duration=None, time_format='seconds')
¶
Load samples and corresponding timestamps.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
Start position (same semantics as
TYPE:
|
stop
|
Stop position (same semantics as
TYPE:
|
onset
|
Alias for start.
TYPE:
|
duration
|
Duration from start.
TYPE:
|
time_format
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A tuple |
ndarray
|
length. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If both start and onset are specified, or both stop and duration are specified. |
Source code in src/edfplus/_models.py
physical_samples(dtype=None)
¶
Return the loaded samples as scaled physical values.
| PARAMETER | DESCRIPTION |
|---|---|
dtype
|
Optional NumPy float dtype to cast the output to. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A NumPy array of physical values. |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If sample data has not been loaded yet. |
Source code in src/edfplus/_models.py
digital_samples()
¶
Return the loaded samples as raw digital int16 values without scaling.
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A NumPy array with dtype |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If sample data has not been loaded yet. |
Source code in src/edfplus/_models.py
timestamps()
¶
Return per-sample onset times in seconds from the recording start.
For sample index i, the onset is i / sample_rate. For EDF+D signals
that contain NaN gap-filler values, the corresponding positions in the returned
array are also NaN so the two arrays remain positionally aligned.
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If sample data has not been loaded yet. |
Source code in src/edfplus/_models.py
datetimes()
¶
Return per-sample absolute datetimes as numpy.datetime64 values.
Each element is EDFHeader.start_datetime + timedelta(seconds=onset_i) where
onset_i comes from timestamps(). Gap samples (NaN onset) produce
numpy.datetime64('NaT') entries.
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A NumPy array of |
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
If sample data has not been loaded yet. |
Source code in src/edfplus/_models.py
Annotation(onset, duration, text)
dataclass
¶
A single EDF+ annotation parsed from a Time-stamped Annotation List (TAL).
Each Annotation holds exactly one text string. Multi-text TAL blocks
produce multiple Annotation instances sharing the same onset and duration.
| ATTRIBUTE | DESCRIPTION |
|---|---|
onset |
Onset time in seconds from the recording start.
TYPE:
|
duration |
Duration of the annotated event in seconds, or
TYPE:
|
text |
The annotation text string for this entry.
TYPE:
|