Skip to content

Commit b410a9c

Browse files
Read Artemis123, Curry, EEGLAB, Eximia, FIL and NSx in cache-sized blocks (#14246)
1 parent 03e4240 commit b410a9c

7 files changed

Lines changed: 88 additions & 5 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speed up reading large Artemis123, Curry, EEGLAB, Eximia, FIL and NSx files by reading them in cache-sized blocks, by `Bruno Aristimunha`_.

mne/io/artemis123/artemis123.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
from ..base import BaseRaw
2020
from .utils import _load_mne_locs, _read_pos
2121

22+
# read in cache-sized blocks rather than one huge one (1.5x on a 176 MB file); see
23+
# _read_segments_file() for why a smaller block is faster
24+
_BLOCK_BYTES = 16 * 1024**2
25+
2226

2327
@verbose
2428
def read_raw_artemis123(
@@ -536,4 +540,15 @@ def __init__(
536540

537541
def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
538542
"""Read a chunk of raw data."""
539-
_read_segments_file(self, data, idx, fi, start, stop, cals, mult, dtype=">f4")
543+
_read_segments_file(
544+
self,
545+
data,
546+
idx,
547+
fi,
548+
start,
549+
stop,
550+
cals,
551+
mult,
552+
dtype=">f4",
553+
max_block_bytes=_BLOCK_BYTES,
554+
)

mne/io/curry/curry.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ def _get_curry_recording_type(fname):
209209
return "evoked"
210210

211211

212+
# read in cache-sized blocks rather than one huge one (1.5x on a 107 MB file); see
213+
# _read_segments_file() for why a smaller block is faster
214+
_BLOCK_BYTES = 16 * 1024**2
215+
216+
212217
def _get_curry_epoch_info(fname):
213218
_soft_import("curryreader", "read epoch info")
214219
_soft_import("pandas", "dataframe integration")
@@ -865,7 +870,16 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
865870

866871
else:
867872
_read_segments_file(
868-
self, data, idx, fi, start, stop, cals, mult, dtype="<f4"
873+
self,
874+
data,
875+
idx,
876+
fi,
877+
start,
878+
stop,
879+
cals,
880+
mult,
881+
dtype="<f4",
882+
max_block_bytes=_BLOCK_BYTES,
869883
)
870884

871885

mne/io/eeglab/eeglab.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ def _get_montage_information(eeg, get_pos, *, montage_units):
216216
return ch_names, ch_types, montage
217217

218218

219+
# read in cache-sized blocks rather than one huge one (2.1x on a 102 MB file); see
220+
# _read_segments_file() for why a smaller block is faster
221+
_BLOCK_BYTES = 4 * 1024**2
222+
223+
219224
def _get_info(eeg, *, eog, montage_units):
220225
"""Get measurement info."""
221226
# add the ch_names and info['chs'][idx]['loc']
@@ -546,7 +551,18 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
546551
return
547552

548553
# Fall back to reading from file (separate .fdt file)
549-
_read_segments_file(self, data, idx, fi, start, stop, cals, mult, dtype="<f4")
554+
_read_segments_file(
555+
self,
556+
data,
557+
idx,
558+
fi,
559+
start,
560+
stop,
561+
cals,
562+
mult,
563+
dtype="<f4",
564+
max_block_bytes=_BLOCK_BYTES,
565+
)
550566

551567

552568
class EpochsEEGLAB(BaseEpochs):

mne/io/eximia/eximia.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
from ...utils import _check_fname, fill_doc, logger, verbose, warn
1111
from ..base import BaseRaw
1212

13+
# read in cache-sized blocks rather than one huge one (2.4x on a 102 MB file); see
14+
# _read_segments_file() for why a smaller block is faster
15+
_BLOCK_BYTES = 2 * 1024**2
16+
1317

1418
@fill_doc
1519
def read_raw_eximia(
@@ -105,4 +109,15 @@ def __init__(self, fname, preload=False, verbose=None):
105109

106110
def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
107111
"""Read a chunk of raw data."""
108-
_read_segments_file(self, data, idx, fi, start, stop, cals, mult, dtype="<i2")
112+
_read_segments_file(
113+
self,
114+
data,
115+
idx,
116+
fi,
117+
start,
118+
stop,
119+
cals,
120+
mult,
121+
dtype="<i2",
122+
max_block_bytes=_BLOCK_BYTES,
123+
)

mne/io/fil/fil.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,26 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
184184
"""Read a chunk of raw data."""
185185
si = self._raw_extras[fi]
186186
_read_segments_file(
187-
self, data, idx, fi, start, stop, cals, mult, dtype=si["dt"]
187+
self,
188+
data,
189+
idx,
190+
fi,
191+
start,
192+
stop,
193+
cals,
194+
mult,
195+
dtype=si["dt"],
196+
max_block_bytes=_BLOCK_BYTES,
188197
)
189198

190199

200+
# read in cache-sized blocks rather than one huge one (1.9x on a 197 MB file); see
201+
# _read_segments_file() for why a smaller block is faster. 4 MiB is faster still
202+
# (2.5x) but measurably regresses the 9.8 MB shipped fixture, which fits in one
203+
# 16 MiB block and so keeps its current code path exactly.
204+
_BLOCK_BYTES = 16 * 1024**2
205+
206+
191207
def _convert_channel_info(chans):
192208
"""Convert the imported _channels.tsv into the chs element of raw.info."""
193209
nmeg = nstim = nmisc = nref = 0

mne/io/nsx/nsx.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ def read_raw_nsx(
146146
)
147147

148148

149+
# read in cache-sized blocks rather than one huge one (2.3x on a 102 MB file); see
150+
# _read_segments_file() for why a smaller block is faster
151+
_BLOCK_BYTES = 4 * 1024**2
152+
153+
149154
@fill_doc
150155
class RawNSX(BaseRaw):
151156
"""Raw object from NSx file from Blackrock Microsystems.
@@ -256,6 +261,7 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
256261
n_channels=None,
257262
offset=offset,
258263
trigger_ch=None,
264+
max_block_bytes=_BLOCK_BYTES,
259265
)
260266

261267

0 commit comments

Comments
 (0)