Error related with the EEGLAB file (buffer is too small)

Dear MNE Community:

MNE version: 1.11.0
The system: windows 11

I hope this message finds you well. I am currently working with EEG data that has been preprocessed using EEGLAB, including epoching (using the ERPLAB plugin in EEGLAB), ICA processing, and filtering. However, when attempting to read the processed EEG data into MNE using mne.io.read_epochs_eeglab(datapath), I am encountering the following error:


TypeError Traceback (most recent call last)
Cell In[9], line 6
3 for n,setname in enumerate(setfile):
4 print(setname)
----> 6 raw = mne.io.read_epochs_eeglab(setname)

File E:\conda\envs\mne\Lib\site-packages\mne\io\eeglab\eeglab.py:398, in read_epochs_eeglab(input_fname, events, event_id, eog, uint16_codec, montage_units, verbose)
339 @fill_doc
340 def read_epochs_eeglab(
341 input_fname,
(…)
348 verbose=None,
349 ) → “EpochsEEGLAB”:
350 r""“Reader function for EEGLAB epochs files.
351
352 Parameters
(…)
396 .. versionadded:: 0.11.0
397 “””
→ 398 epochs = EpochsEEGLAB(
399 input_fname=input_fname,
400 events=events,
401 eog=eog,
402 event_id=event_id,
403 uint16_codec=uint16_codec,
404 montage_units=montage_units,
405 verbose=verbose,
406 )
407 return epochs

File :12, in init(self, input_fname, events, event_id, tmin, baseline, reject, flat, reject_tmin, reject_tmax, eog, uint16_codec, montage_units, verbose)

File E:\conda\envs\mne\Lib\site-packages\mne\io\eeglab\eeglab.py:645, in EpochsEEGLAB.init(self, input_fname, events, event_id, tmin, baseline, reject, flat, reject_tmin, reject_tmax, eog, uint16_codec, montage_units, verbose)
641 input_fname = str(
642 _check_fname(fname=input_fname, must_exist=True, overwrite=“read”)
643 )
644 # the epoches data are always preloaded
→ 645 eeg = _check_load_mat(input_fname, uint16_codec, preload=True)
647 if not (
648 (events is None and event_id is None)
649 or (events is not None and event_id is not None)
650 ):
651 raise ValueError(“Both events and event_id must be None or not None”)

File E:\conda\envs\mne\Lib\site-packages\mne\io\eeglab\eeglab.py:77, in _check_load_mat(fname, uint16_codec, preload)
75 “”“Check if the mat struct contains ‘EEG’.”“”
76 fname = _check_fname(fname, “read”, True)
—> 77 eeg = _readmat(fname, uint16_codec=uint16_codec, preload=preload)
78 if “ALLEEG” in eeg:
79 raise NotImplementedError(
80 “Loading an ALLEEG array is not supported. Please contact”
81 “mne-python developers for more information.”
82 )

File E:\conda\envs\mne\Lib\site-packages\mne\io\eeglab_eeglab.py:271, in _readmat(fname, uint16_codec, preload)
269 # here is intended to be if and not else if
270 if preload:
→ 271 return read_mat(fname, uint16_codec=uint16_codec)

File E:\conda\envs\mne\Lib\site-packages\mne\io\eeglab_eeglab.py:76, in _scipy_reader(file_name, variable_names, uint16_codec)
74 def _scipy_reader(file_name, variable_names=None, uint16_codec=None):
75 “”“Load with scipy and then run the check function.”“”
—> 76 mat_data = loadmat(
77 file_name,
78 squeeze_me=True,
79 mat_dtype=False,
80 variable_names=variable_names,
81 uint16_codec=uint16_codec,
82 )
83 return _check_for_scipy_mat_struct(mat_data)

File E:\conda\envs\mne\Lib\site-packages\scipy\io\matlab_mio.py:235, in loadmat(file_name, mdict, appendmat, spmatrix, **kwargs)
233 with _open_file_context(file_name, appendmat) as f:
234 MR, _ = mat_reader_factory(f, **kwargs)
→ 235 matfile_dict = MR.get_variables(variable_names)
236 if spmatrix:
237 from scipy.sparse import issparse, coo_matrix

File E:\conda\envs\mne\Lib\site-packages\scipy\io\matlab_mio5.py:333, in MatFile5Reader.get_variables(self, variable_names)
331 continue
332 try:
→ 333 res = self.read_var_array(hdr, process)
334 except MatReadError as err:
335 warnings.warn(
336 f’Unreadable variable “{name}”, because “{err}”',
337 Warning, stacklevel=2)

File E:\conda\envs\mne\Lib\site-packages\scipy\io\matlab_mio5.py:291, in MatFile5Reader.read_var_array(self, header, process)
274 def read_var_array(self, header, process=True):
275 ‘’’ Read array, given header
276
277 Parameters
(…)
289 process.
290 ‘’’
→ 291 return self._matrix_reader.array_from_header(header, process)

File scipy/io/matlab/_mio5_utils.pyx:665, in scipy.io.matlab._mio5_utils.VarReader5.array_from_header()

File scipy/io/matlab/_mio5_utils.pyx:712, in scipy.io.matlab._mio5_utils.VarReader5.array_from_header()

File scipy/io/matlab/_mio5_utils.pyx:954, in scipy.io.matlab._mio5_utils.VarReader5.read_struct()

File scipy/io/matlab/_mio5_utils.pyx:663, in scipy.io.matlab._mio5_utils.VarReader5.read_mi_matrix()

File scipy/io/matlab/_mio5_utils.pyx:706, in scipy.io.matlab._mio5_utils.VarReader5.array_from_header()

File scipy/io/matlab/_mio5_utils.pyx:868, in scipy.io.matlab._mio5_utils.VarReader5.read_char()

TypeError: buffer is too small for requested array

The last line of the traceback says:

which could be a bug, or could mean that you’re hitting the memory limit of your system. We would need access to the file to help with debugging probably. Are you able to share the file?

Thank you very much. This issue was resolved by specifying
uint16_codec='ascii' when calling
mne.io.read_epochs_eeglab.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.