Skip to content

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

Open
PragnyaKhandelwal wants to merge 5 commits into
mne-tools:mainfrom
PragnyaKhandelwal:egi-mff-data-reader
Open

MAINT: Replace internal EEG sample-reading helper with mffpy#13973
PragnyaKhandelwal wants to merge 5 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 (merged — mffpy for event reading) and #13945 (open — mffpy
for metadata reading). 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
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.

1 participant