Skip to content

MAINT: Replace internal EEG sample-reading helper with mffpy - #13973

Merged
scott-huberty merged 8 commits into
mne-tools:mainfrom
PragnyaKhandelwal:egi-mff-data-reader
Jun 29, 2026
Merged

scott-huberty merged 8 commits into
mne-tools:mainfrom
PragnyaKhandelwal:egi-mff-data-reader

Conversation

@PragnyaKhandelwal

@PragnyaKhandelwal PragnyaKhandelwal commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Reference issue (if any)

Part of Towards #13926.

Builds on #13932 and #13945 . This is the third micro-PR in the series.

What does this implement/fix?

Replaces the internal binary-block EEG sample reader in RawMff._read_segment_file with mffpy.Reader.get_physical_samples_from_epoch().

Two helpers are added:

  • _get_mff_reader(mff_path) — opens an mffpy.Reader with its default EEG calibration (GCAL) disabled. MNE's cals vector already incorporates that gain (set in _get_eeg_calibration_info), so leaving it enabled would double-scale every EEG sample.

  • _disk_range_to_epochs(egi_info, disk_start, disk_stop) — translates a contiguous range of on-disk sample indices (how BaseRaw addresses data) into per-epoch (t0, dt) windows (how mffpy addresses data). EGI MFF stores signal blocks back-to-back on disk; recording-pause gaps only appear in the logical sample timeline exposed to users.

The ~50-line manual fid.seek / np.fromfile / block-header parsing loop (_block_r) is removed and replaced with a short loop over get_physical_samples_from_epoch(), consistent with how PNS reading already
works downstream.

mff_path is stored in egi_info at RawMff.__init__ time so the reader can be instantiated on demand inside _read_segment_file.

Additional information

All existing tests in mne/io/egi/tests/test_egi.py pass locally, including multi-epoch, paused-recording, PNS, crop, and preload variants. No new test fixtures are needed — the existing .mff files already exercise multi-block reads and epoch boundaries.

Replaces the manual binary block-reading loop in `_read_segment_file`
with `mffpy.Reader.get_physical_samples_from_epoch`, adding two helpers:
`_get_mff_reader` (opens reader with GCAL disabled to avoid double-scaling
against MNE's existing `cals` pipeline) and `_disk_range_to_epochs` (maps
a contiguous on-disk sample range across acquisition-skip gaps to per-epoch
mffpy `(t0, dt)` windows). PNS reading is unchanged.
PragnyaKhandelwal added a commit to PragnyaKhandelwal/mne-python that referenced this pull request Jun 22, 2026
@PragnyaKhandelwal
PragnyaKhandelwal marked this pull request as ready for review June 22, 2026 13:59
@scott-huberty
scott-huberty enabled auto-merge (squash) June 29, 2026 17:08
@scott-huberty

Copy link
Copy Markdown
Contributor

LGTM @PragnyaKhandelwal !! >95% test coverage 🚀 !

I edited the docstring you wrote for the private _disk_to_samps(sic) func, and enabled merge-when-green.

@scott-huberty
scott-huberty merged commit 34d9c7e into mne-tools:main Jun 29, 2026
37 of 38 checks passed
@PragnyaKhandelwal
PragnyaKhandelwal deleted the egi-mff-data-reader branch December 1, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants