mne-bids: [BUG] write_raw_bids conversion to bv breaks event timing

See

import os.path as op

import mne
from mne.utils import _TempDir
from mne.datasets import testing
from mne_bids import write_raw_bids, make_bids_basename


base_path = op.join(op.dirname(mne.__file__), 'io')
subject_id = '01'
subject_id2 = '02'
session_id = '01'
run = '01'
acq = '01'
run2 = '02'
task = 'testing'

bids_basename = make_bids_basename(
    subject=subject_id, session=session_id, run=run, acquisition=acq,
    task=task)

output_path = _TempDir()
data_path = testing.data_path()
raw_fname = op.join(data_path, 'MEG', 'sample',
                    'sample_audvis_trunc_raw.fif')

event_id = {'Auditory/Left': 1, 'Auditory/Right': 2, 'Visual/Left': 3,
            'Visual/Right': 4, 'Smiley': 5, 'Button': 32}
events_fname = op.join(data_path, 'MEG', 'sample',
                       'sample_audvis_trunc_raw-eve.fif')

raw = mne.io.read_raw_fif(raw_fname)
raw.load_data()
events = mne.find_events(raw)
raw2 = raw.pick_types(meg=False, eeg=True, stim=True, eog=True, ecg=True)
raw2.save(op.join(output_path, 'test-raw.fif'), overwrite=True)
raw2 = mne.io.Raw(op.join(output_path, 'test-raw.fif'), preload=False)

write_raw_bids(raw2, bids_basename, output_path,
               verbose=True, overwrite=True)

bids_dir = op.join(output_path, 'sub-%s' % subject_id,
                   'ses-%s' % session_id, 'eeg')
raw2 = mne.io.read_raw_brainvision(op.join(bids_dir,
                                           bids_basename + '_eeg.vhdr'))

events2 = mne.find_events(raw2)

print(events, events2)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

After lots of trial and error, I figured out that the stim channel in raw was overwriting the events that were passed. Should probably be a pybv issue too. Writing a fix now.