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 read_raw_brainvision #4283

Closed
agramfort opened this issue May 25, 2017 · 4 comments · Fixed by #4293
Closed

Bug read_raw_brainvision #4283

agramfort opened this issue May 25, 2017 · 4 comments · Fixed by #4293
Milestone

Comments

@agramfort
Copy link
Member

from mailing list

I am using mne.io.read_raw_brainvision to read bipolar EMG and EKG data saved as brainvision files (vhdr).
I have 4 channels: EMGleft,EMGright,EKG and STI 014 with the triggers.

However, when I import the data in MNE python, the first three channels are not correctly imported.
They all look like a combination of EMG data, however they do not correspond to the original data, particularly even the third channel is not at all EKG. 
You can see attached to the email the images with a portion of imported data from the three channels.

Is it possible that the function is using a reference by default? I don't see this option in the function.
This is how I am using the function:

emg = mne.io.read_raw_brainvision(emgFname,montage=None, misc='auto',scale=1.0,preload=True, verbose=True)

answer by @bburle

Investigating the issue, it appears that mne.io.read_raw_brainvision is
currently not using the information about data orientation in the header
(.vhdr) file:

DataOrientation=VECTORIZED

Apparently, the function assumes that data are multiplexed. It's just a
matter of transposing the matrix while reading. I'll try to pinpoint the
lines in mne.io.read_raw_brainvision where this should be done.

problematic file is here

EMG.zip

@larsoner larsoner added this to the 0.15 milestone May 25, 2017
@bburle
Copy link

bburle commented May 26, 2017

Being not familiar with the "_BaseRaw" object, I haven't (yet) identified where the problem is. But to advance a bit, here is a short piece of code that 1) replicate the problem, 2) open the file correctly (through direct memmap). I haven't been able to get the same (wrong) data as mne through a direct memmap, by transposing and/or reshaping differently the array. Hope this can be useful...

import numpy as np
import pylab as plt
import mne

emgFname = 'sb1b1'

mne_data = mne.io.read_raw_brainvision(emgFname+'.vhdr',montage=None, misc='auto',scale=1.0,preload=True, verbose=True)
plt.subplot(311)
plt.plot(mne_data._data[0,22000:120000]) #portion of data where something interesting occurs
plt.subplot(312)
plt.plot(mne_data._data[1,22000:120000])
plt.subplot(313)
plt.plot(mne_data._data[1,22000:120000])
#wrong data

raw_data = np.memmap(emgFname+'.eeg', np.float32)
rs_data = raw_data.reshape((3,813056)) #hard coded based on the vhdr file
plt.subplot(311)
plt.plot(rs_data[0,22000:120000])
plt.subplot(312)
plt.plot(rs_data[1,22000:120000])
plt.subplot(313)
plt.plot(rs_data[2,22000:120000])
# data OK

@jona-sassenhagen
Copy link
Contributor

Is this on master? IIRC we had a problem with long channel names earlier that should now be fixed. WIll try to look at it later, but might take a while :(

@teonbrooks

@palday
Copy link
Contributor

palday commented May 31, 2017

There's a small copy-paste error in the example:

mne_data = mne.io.read_raw_brainvision(emgFname+'.vhdr',montage=None, misc='auto',scale=1.0,preload=True, verbose=True)
plt.subplot(311)
plt.plot(mne_data._data[0,22000:120000]) #portion of data where something interesting occurs
plt.subplot(312)
plt.plot(mne_data._data[1,22000:120000])
plt.subplot(313)
# this index needs to be a 2
plt.plot(mne_data._data[2,22000:120000])

# reshaping by hand
raw_data = np.memmap(emgFname+'.eeg', np.float32)
rs_data = raw_data.reshape((3,813056)) #hard coded based on the vhdr file
plt.subplot(311)
plt.plot(rs_data[0,22000:120000])
plt.subplot(312)
plt.plot(rs_data[1,22000:120000])
plt.subplot(313)
plt.plot(rs_data[2,22000:120000])
# data OK

@palday
Copy link
Contributor

palday commented May 31, 2017

The fix is relatively straightforward for this example; the trick is that the function that has to be modified isn't in the RawBrainVision class or even brainvision.py.

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

Successfully merging a pull request may close this issue.

5 participants