diff --git a/doc/changes/devel/12371.newfeature.rst b/doc/changes/devel/12371.newfeature.rst new file mode 100644 index 00000000000..4d28ff1f5ce --- /dev/null +++ b/doc/changes/devel/12371.newfeature.rst @@ -0,0 +1 @@ +Speed up :func:`mne.io.read_raw_neuralynx` on large datasets with many gaps, by `Kristijan Armeni`_. \ No newline at end of file diff --git a/mne/io/neuralynx/neuralynx.py b/mne/io/neuralynx/neuralynx.py index 55de7579d67..ab768d57b13 100644 --- a/mne/io/neuralynx/neuralynx.py +++ b/mne/io/neuralynx/neuralynx.py @@ -223,11 +223,8 @@ def __init__( [np.full(shape=(n,), fill_value=i) for i, n in enumerate(sizes_sorted)] ) - # construct Annotations() - gap_seg_ids = np.unique(sample2segment)[gap_indicator] - gap_start_ids = np.array( - [np.where(sample2segment == seg_id)[0][0] for seg_id in gap_seg_ids] - ) + # get the start sample index for each gap segment () + gap_start_ids = np.cumsum(np.hstack([[0], sizes_sorted[:-1]]))[gap_indicator] # recreate time axis for gap annotations mne_times = np.arange(0, len(sample2segment)) / info["sfreq"]