mne-tools / mne-python

MNE: Magnetoencephalography (MEG) and Electroencephalography (EEG) in Python
https://mne.tools
BSD 3-Clause "New" or "Revised" License
2.72k stars 1.32k forks source link

read_raw_brainvision stim channel not properly imported to annotations #5995

Closed alexrockhill closed 5 years ago

alexrockhill commented 5 years ago

I'm not sure where there is a sample brainvision raw file, but if you read it in:

raw = read_raw_brainvision(f,preload=True)

Then the annotations aren't showing up with the data that was contained by the stim channel before:

raw.annotations only gives New Segment/ (1) and Time 0/ (1) whereas this should contain stim channels.

raw.annotations <Annotations | 2 segments : New Segment/ (1), Time 0/ (1), orig_time : 2019-02-19 19:39:42.681951>

alexrockhill commented 5 years ago

I should add that this the annotations are properly imported in 0.17.1.

Used Annotations descriptions: ['Response/R 15', 'Response/R 7']

raw.annotations <Annotations | 601 segments : new (1), response/r (600), orig_time : 2019-02-19 19:28:37.906419>

larsoner commented 5 years ago

@massich can you look into it?

massich commented 5 years ago

it is weird that our test suite does not capture this. @alexrockhill can you share the file with me? (or even better do you have an MWE that replicates the problem that we can ship with our testdata?)

alexrockhill commented 5 years ago

In the MNE-sample-data set, I don't see any .vhdr files. If you point me to one, I can make a MWE. Otherwise, I'll send you a file and a gist shortly.

massich commented 5 years ago

~yes I don't find a .vhdr file with annotations in our test suite either. We have the annotations in the .vmrk.~ EDIT: The annotations are in .vmrk reading a .vhdr file with an associated .vmrk file loads properly.

We should definitely fix this. But meanwhile:

alexrockhill commented 5 years ago

https://gist.github.com/alexrockhill/9a0e85a38956740ff63d70677d2ca6ad

It's not my data file, it's from the test dataset, but from the warning messages it looks like there are 'Sync On' events.

alexrockhill commented 5 years ago

In both versions, I just read in the raw file with read_raw_brainvision and then printed to output raw.annotations, I'll check on the read annotations.

Edit: When I run read_annotations on the vmrk file I get the correct stim channel event markers

<Annotations | 601 segments : New Segment/ (1), Response/R 15 (300), Response/R 7 (300), orig_time : 2019-02-19 19:28:37.906419>

mne.version '0.18.dev0'

massich commented 5 years ago

This passes in master

    sfreq = 1000.0
    raw = read_raw_brainvision(vhdr_path, preload=True)
    assert raw.annotations.orig_time == 1384359243.794231
    expected = np.array([0, 486., 496., 1769., 1779., 3252., 3262., 4935.,
                         4945., 5999., 6619., 6629., 7629., 7699.]) / sfreq
    description = ['New Segment/',
                   'Stimulus/S253', 'Stimulus/S255', 'Stimulus/S254',
                   'Stimulus/S255', 'Stimulus/S254', 'Stimulus/S255',
                   'Stimulus/S253', 'Stimulus/S255', 'Response/R255',
                   'Stimulus/S254', 'Stimulus/S255',
                   'SyncStatus/Sync On', 'Optic/O  1']
    assert_array_almost_equal(raw.annotations.onset,
                              expected, decimal=7)
    assert_array_equal(raw.annotations.description, description)
cbrnr commented 5 years ago

@alexrockhill you mentioned that this works in 0.17.1 - do you get the issue with the current master?

alexrockhill commented 5 years ago

I apologize, I didn't record my versions earlier and now with mne 0.18.dev0 I am not able to replicate the same issue, the event markers are coming out fine. I'm not sure why that happened before. If I figure it out I will reopen, sorry!

I thought it was with 0.18.dev0... I was also preloading on disk so it might have been that.

Edit: No, works with preloading onto disk. I'm not sure how I got the error.