mne-tools / mne-bids

MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python.
https://mne.tools/mne-bids/
BSD 3-Clause "New" or "Revised" License
131 stars 85 forks source link

"Wrong Number of Columns" When `read_raw_bids` #353

Closed adam2392 closed 4 years ago

adam2392 commented 4 years ago

Describe the bug

I am reading in a file written from EDF and converted to BV via read_raw_bids, and I get this error:

Traceback (most recent call last):
    raw = read_raw_bids(bids_fname, bids_root)
line 349, in read_raw_bids
    raw = _handle_events_reading(events_fname, raw)
line 125, in _handle_events_reading
    events_dict = _from_tsv(events_fname)
  packages/mne_bids/tsv_handler.py", line 121, in _from_tsv
    data = np.loadtxt(fname, dtype=str, delimiter='\t', encoding='utf-8')
 line 1146, in loadtxt
    for x in read_data(_loadtxt_chunksize):
  line 1071, in read_data
    % line_num)
ValueError: Wrong number of columns at line 5

However, my file looks... correct? Is this a bug in _from_tsv, or something else?

Additional information

I have placed the file in here. sub-pt3_ses-seizure_task-monitor_acq-eeg_run-03_events.zip

jasmainak commented 4 years ago

It doesn't look like the file is a valid tab separated file. There are columns that are not separated by tabs in the rows after the first one

adam2392 commented 4 years ago

Hmmm.. that's weird tho. I wrote these in with mne_bids.write_raw_bids, and then simply ran read_raw_bids. I am viewing them with a .tsv text-editor and they do show up as tabs, so I believe that's not the reason.

It looks like the main issue occurs when there is a "#" character because tsv_handler.py's _from_tsv uses np.loadtxt, which defaults to "#" being comments. I just tried it out locally, and adding comments=None to the np.loadtxt line of _from_tsv fixes it.

However, I'm not sure if there is a reason for including the comments? What do you think @jasmainak

adam2392 commented 4 years ago

If it's nothing to worry about, then I can submit a quick PR to fix this.

jasmainak commented 4 years ago

hummm I agree that round trip should work