Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when read raw cnt file #12982

Closed
ZiyiTsang opened this issue Nov 22, 2024 · 5 comments
Closed

Bug when read raw cnt file #12982

ZiyiTsang opened this issue Nov 22, 2024 · 5 comments
Labels
Milestone

Comments

@ZiyiTsang
Copy link
Contributor

Description of the problem

Hi who it may concern, I am writing the code to read cnt when it occur the error as follow:

Error
File /mnt/nvme2n1/(xxxxxxxxxx)/lib/python3.10/site-packages/mne/io/cnt/cnt.py:340, in _get_cnt_info(input_fname, eog, ecg, emg, misc, data_format, date_format, header)
338 # See: PR #12393
339 annotations = _read_annotations_cnt(input_fname, data_format="int16")
--> 340 if annotations.onset[-1] * sfreq > n_samples:
341 n_bytes = 4
342 n_samples = n_samples_header

IndexError: index -1 is out of bounds for axis 0 with size 0

Steps to reproduce

data = mne.io.read_raw_cnt('1_1.cnt', preload=True)

(then orrur happen...)

Link to data

This is a file in SEED-GER dataset. I can send you the file email for debug purpose only.

Expected results

Expected run perfectly

Actual results

image
Traceback

IndexError Traceback (most recent call last)
Cell In[15], line 3
1 with warnings.catch_warnings():
2 warnings.simplefilter("ignore")
----> 3 data = mne.io.read_raw_cnt('/mnt/xxxxxxxxxxx/SEED_GER/German/01-EEG-raw/1_1.cnt', preload=True)

File /mnt/xxxxxxxxxxx/python3.10/site-packages/mne/io/cnt/cnt.py:248, in read_raw_cnt(input_fname, eog, misc, ecg, emg, data_format, date_format, header, preload, verbose)
163 @fill_doc
164 def read_raw_cnt(
165 input_fname,
(...)
175 verbose=None,
176 ) -> "RawCNT":
177 """Read CNT data as raw object.
178
179 .. Note::
(...)
246 .. versionadded:: 0.12
247 """
--> 248 return RawCNT(
249 input_fname,
250 eog=eog,
251 misc=misc,
252 ecg=ecg,
253 emg=emg,
254 data_format=data_format,
255 date_format=date_format,
256 header=header,
257 preload=preload,
258 verbose=verbose,
259 )

File /mnt/xxxxxxxxxxxx/python3.10/site-packages/mne/io/cnt/cnt.py:531, in RawCNT.init(self, input_fname, eog, misc, ecg, emg, data_format, date_format, header, preload, verbose)
528 _date_format = "%m/%d/%y %H:%M:%S"
530 input_fname = path.abspath(input_fname)
--> 531 info, cnt_info = _get_cnt_info(
532 input_fname, eog, ecg, emg, misc, data_format, _date_format, header
533 )
534 last_samps = [cnt_info["n_samples"] - 1]
535 super().init(
536 info,
537 preload,
(...)
542 verbose=verbose,
543 )

File /mnt/xxxxxxxxxxxxxxxx/python3.10/site-packages/mne/io/cnt/cnt.py:340, in _get_cnt_info(input_fname, eog, ecg, emg, misc, data_format, date_format, header)
338 # See: PR #12393
339 annotations = _read_annotations_cnt(input_fname, data_format="int16")
--> 340 if annotations.onset[-1] * sfreq > n_samples:
341 n_bytes = 4
342 n_samples = n_samples_header

IndexError: index -1 is out of bounds for axis 0 with size 0

Additional information

Platform Linux-5.15.0-124-generic-x86_64-with-glibc2.31
Python 3.10.15 (main, Oct 3 2024, 07:27:34) [GCC 11.2.0]
Executable /mnt/nvme2n1/zengziyi/anaconda/envs/LGU/bin/python
CPU x86_64 (112 cores)
Memory 1007.5 GB

Core
├☑ mne 1.8.0 (latest release)
├☑ numpy 1.26.4 (MKL 2023.1-Product with 56 threads)
├☑ scipy 1.13.1
└☑ matplotlib 3.9.2 (backend=module://matplotlib_inline.backend_inline)

Numerical (optional)
├☑ sklearn 1.5.2
├☑ pandas 2.2.2
├☑ h5io 0.2.4
└☐ unavailable numba, nibabel, nilearn, dipy, openmeeg, cupy, h5py

Visualization (optional)
├☑ ipywidgets 8.1.5
└☐ unavailable pyvista, pyvistaqt, vtk, qtpy, ipympl, pyqtgraph, mne-qt-browser, trame_client, trame_server, trame_vtk, trame_vuetify

Ecosystem (optional)
├☑ mne-icalabel 0.7.0
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv

@ZiyiTsang ZiyiTsang added the BUG label Nov 22, 2024
Copy link

welcome bot commented Nov 22, 2024

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@larsoner larsoner added this to the 1.9 milestone Nov 22, 2024
@larsoner
Copy link
Member

Indeed this looks like it's probably a bug where we assume that there is at least one annotation, but there are none.

If you change

if annotations.onset[-1] * sfreq > n_samples:

To

if len(annotations) and annotations.onset[-1] * sfreq > n_samples:

does it work? If so, PR welcome for this quick fix!

@ZiyiTsang
Copy link
Contributor Author

ZiyiTsang commented Nov 23, 2024

Ok, trying to work on it!

@ZiyiTsang
Copy link
Contributor Author

Yes, it work for me. I have create PR #12986 to quick fix this.
This is my first time creating PR. If anything wrong, kindly inform me. Thanks.

@ZiyiTsang
Copy link
Contributor Author

As PR complete, I close this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants