Skip to content

Add optional edfio parsing engine to read_raw_edf - #14215

Closed
bruAristimunha wants to merge 4 commits into
mne-tools:mainfrom
bruAristimunha:pr/4-edfio-engine
Closed

Add optional edfio parsing engine to read_raw_edf#14215
bruAristimunha wants to merge 4 commits into
mne-tools:mainfrom
bruAristimunha:pr/4-edfio-engine

Conversation

@bruAristimunha

@bruAristimunha bruAristimunha commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Reference issue (if any)

None. Part 4/5 of the IO-speedup series. Depends on #14214 (→ #14213#14212).

What does this implement/fix?

Adds engine="mne" | "edfio" to read_raw_edf. The edfio engine parses via
the optional edfio package into a preloaded Raw. Minimal scope: uniform
sampling rates only, all channels EEG, meas_date unset.

Full load of a 236 MB EDF: native ~453 ms → edfio ~368 ms.

Related upstream change: the-siesta-group/edfio#114 (public scaling factors).

Additional information

AI disclosure: same as #14212.
CI note: held until the parent PR merges.

get_data resolves picks=None to arange directly instead of going through
string-based channel-name machinery on every call; _picks_to_idx gets an
early return for integer arrays already unique and in range (duplicate
picks keep taking the validating path); _mult_cal_one fuses gather,
type-cast, and calibration into a single elementwise pass.
FIF raw segments are read as byte-offset views into a PID-keyed memory
map of the file instead of open/seek/read per call; buffer entries are
selected with searchsorted on the sorted bounds. gzip, file-like objects,
and non-simple tag types keep the legacy path. The generic memory-map
cache in _read_segments_file also serves the other binary readers.
Uniform-sampling-rate EDF/BDF windows decode through a strided gather
plus an optional-numba kernel writing calibrated samples directly into
the caller's output buffer, replacing the per-channel Python loop.
Big-endian chunks are byteswapped to native order first; uniform stim
channels apply the legacy truncating bitmask on the fast path;
projector/compensation reads keep the exact legacy route. EDF/BDF/GDF
file handles persist per process (PID-keyed LRU).
engine='edfio' parses EDF via the optional edfio package into a preloaded
Raw (uniform sampling rates; all channels EEG; no meas_date). Decoding
stacks digital samples once and applies calibration in two fused passes;
output matches the native engine within 1 ulp.
@larsoner

Copy link
Copy Markdown
Member

Rather than add a backend to shave 25%, could we profile both to see where we lose speed and they do not? Is it inefficient conversion, etc.? If at the end of the day we have to allow using a different backend we can, but it would be good to understand where our time loss is.

@larsoner

Copy link
Copy Markdown
Member

Okay @bruAristimunha I think this one is next, see comment above ☝️

@bruAristimunha

Copy link
Copy Markdown
Contributor Author

Superseded by #14237, which speeds up the same EDF/BDF cold path natively (236 MB EDF preload ~250 ms -> ~85 ms on my machine, interleaved A/B against a pristine main) without an optional dependency, a new public engine parameter, or the uniform-rate / all-EEG / no-meas_date restrictions this branch needed. Closing in favour of that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants