EtienneCmb / visbrain

A multi-purpose GPU-accelerated open-source suite for brain data visualization
http://visbrain.org
Other
241 stars 64 forks source link

Reading BrainVision file in with float numbers #68

Closed nbeliy closed 4 years ago

nbeliy commented 4 years ago

Dear experts,

I have a BrainVision eeg sample with DataFormat set as IEEE_FLOAT_32 when I try to load it, the Sleep crashes with an assertion error:

File "/home/beliy/Memodyn/visbrain/vis_env/lib/python3.6/site-packages/visbrain/io/read_sleep.py", line 507, in read_bva
    assert "INT_16" in binary_format
AssertionError

It looks easy to fix in read_sleep.py by changing the type in np.ndarray, but will be this the only place to change?

When I change data from '<i2' to float32, I have following warnings and error:

/home/beliy/Memodyn/visbrain/vis_env/lib/python3.6/site-packages/visbrain/io/read_sleep.py:213: UserWarning: Wrong channel data amplitude. 
  warn("Wrong channel data amplitude. ")
/home/beliy/Memodyn/visbrain/vis_env/lib/python3.6/site-packages/visbrain/gui/sleep/visuals/marker.py:569: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  ('a_edgewidth', np.float32, 1)])
/home/beliy/Memodyn/visbrain/vis_env/lib/python3.6/site-packages/visbrain/gui/sleep/visuals/visuals.py:499: RuntimeWarning: divide by zero encountered in log10
  mesh = 20 * np.log10(mesh)
File already dowloaded (/home/beliy/visbrain_data/topo/eegref.npz).
WARNING | Ignored channels for topoplot : EKG, Chin
File already dowloaded (/home/beliy/visbrain_data/topo/eegref.npz).
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/beliy/Memodyn/visbrain/vis_env/lib/python3.6/site-packages/vispy/app/canvas.py", line 505, in __repr__
    self.app.backend_name, hex(id(self))))
AttributeError: 'Sleep' object has no attribute 'app'

Can you tell what causes these problems? I've put the vhdr file in attachement (changed extention to txt eeg.txt ).

raphaelvallat commented 4 years ago

Hi @nbeliy ,

I would strongly recommend using the mne.io.read_raw_brainvision to load your BrainVision file into memory, and then using the following lines to extract the data and sampling frequency:

from visbrain.gui import Sleep
from mne.io import read_raw_brainvision

raw = read_raw_brainvision("YOURFILE.vhdr", preload=True)
data = raw.get_data() * 1e6  # Convert Volts to uV
sf = raw.info['sfreq']
channels = raw.ch_names
Sleep(data=data, sf=sf, channels=channels).show() 

Hope this helps!

nbeliy commented 4 years ago

It worked! Thanks a lot!