Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/changes/dev/14137.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Speed up :func:`mne.io.read_raw_egi` for MFF files by preserving the ``idx`` slice in
``_read_segment_file``, avoiding a costly ``np.take`` copy on large data buffers
(~60% reduction in read time for large recordings with ``preload=True``).
By `Pragnya Khandelwal`_ (:gh:`14137`).
25 changes: 13 additions & 12 deletions mne/io/egi/egimff.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,19 +613,20 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
egi_info = self._raw_extras[fi]
one = np.zeros((egi_info["kind_bounds"][-1], stop - start))

# Check how many channels to read are from each type
# Check how many channels to read are from each type.
# Keep idx as-is (slice or ndarray) for _mult_cal_one — the slice path
# avoids np.take and is significantly faster on large buffers.
bounds = egi_info["kind_bounds"]
if isinstance(idx, slice):
idx = np.arange(idx.start, idx.stop)
eeg_out = np.where(idx < bounds[1])[0]
eeg_one = idx[eeg_out, np.newaxis]
eeg_in = idx[eeg_out]
stim_out = np.where((idx >= bounds[1]) & (idx < bounds[2]))[0]
stim_one = idx[stim_out]
stim_in = idx[stim_out] - bounds[1]
pns_out = np.where((idx >= bounds[2]) & (idx < bounds[3]))[0]
pns_in = idx[pns_out] - bounds[2]
pns_one = idx[pns_out, np.newaxis]
idx_arr = np.arange(idx.start, idx.stop) if isinstance(idx, slice) else idx
eeg_out = np.where(idx_arr < bounds[1])[0]
eeg_one = idx_arr[eeg_out, np.newaxis]
eeg_in = idx_arr[eeg_out]
stim_out = np.where((idx_arr >= bounds[1]) & (idx_arr < bounds[2]))[0]
stim_one = idx_arr[stim_out]
stim_in = idx_arr[stim_out] - bounds[1]
pns_out = np.where((idx_arr >= bounds[2]) & (idx_arr < bounds[3]))[0]
pns_in = idx_arr[pns_out] - bounds[2]
pns_one = idx_arr[pns_out, np.newaxis]
del eeg_out, stim_out, pns_out

# take into account events (already extended to correct size)
Expand Down
Loading