mne-tools / mne-python

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

How to apply ica on brainvision raw data #8432

Closed arthurlgk closed 3 years ago

arthurlgk commented 3 years ago

I am getting this error when trying to fit the data:

ValueError: picks (NoneNone, treated as "data") yielded no channels, consider passing picks explicitly

How to resolve this issue?

hoechenberger commented 3 years ago

Hello @arthurlgk, we'd need a little more information how you got there.

Thanks!

arthurlgk commented 3 years ago

I am currently using mne 0.21.0. And the code is the following:

fname = "demo_3.vhdr"
bv_raw = mne.io.read_raw_brainvision(dirname+fname)
ica = ICA(n_components=63, random_state=97)
ica.fit(bv_raw)

Thank you.

hoechenberger commented 3 years ago

@arthurlgk Ok, this seems a little odd to me (the behavior you're seeing, not your code, which looks ok) @cbrnr Maybe you have an idea?

@arthurlgk Could you (privately) share with me one of the datasets that produces this problem? So I can try look into this myself. My email address is richard.hoechenberger@gmail.com

arthurlgk commented 3 years ago

@hoechenberger Sent. Did you receive it?

cbrnr commented 3 years ago

Not sure, but maybe the channel types are not EEG/MEG? @arthurlgk can you post the output of bv_raw.info?

hoechenberger commented 3 years ago

@hoechenberger Sent. Did you receive it?

Thank you, I received the email. Will look into this within the next 2 hours.

hoechenberger commented 3 years ago

@arthurlgk I just looked at the .vhdr file you included, and there's something off.

Your file looks something like this:

...
Ch1=Channel 1,,1,
Ch2=Channel 2,,1,
Ch3=Channel 3,,1,
...

while it's supposed to look like this:

...
Ch1=FP1,,0.5,µV
Ch2=FP2,,0.5,µV
Ch3=F3,,0.5,µV
...

i.e., there are no units specified in your file. I'm not sure if that's even valid (but I'm not an expert on BV data). How did you generate those files?

hoechenberger commented 3 years ago

@sappelhoff Maybe you would know which unit is the default if not explicitly specified in the vhdr file? µV, I suppose?

sappelhoff commented 3 years ago

yep, seems to me like that.

pdf source: https://www.brainproducts.com/filedownload.php?path=products/more/BVCDF-1.0_DocVersion-2.5_2019-12-12.pdf

See screenshot:

image

hoechenberger commented 3 years ago

Yes just found out the same. Thanks for looking. I will now try to figure out whether pybv or MNE is doing something wrong when reading @arthurlgk's file.

hoechenberger commented 3 years ago

… just to realize that pybv only writes, apparently ;) So it must be something in MNE

hoechenberger commented 3 years ago

Ok found it. Working on a fix.

sappelhoff commented 3 years ago

… just to realize that pybv only writes, apparently

yes :-) better to make the MNE reader great, than have a second and less complete/battle-tested version in pybv.

hoechenberger commented 3 years ago

(strictly speaking, @abramhindle's file does not follow the specification. Because as I read the specs: if you don't have a unit, also the comma separating unit from the rest of props must go. but it's easy to deal with this, so… still it would be interesting to know which software @abramhindle used to create this file, because either it's buggy or the specs need to be amended)

hoechenberger commented 3 years ago

(Am I right? Or am I reading this incorrectly? it says ...[,<unit>], so the comma should only be there if there's a unit, right?)

sappelhoff commented 3 years ago

Am I right?

I agree. it might be a typo :-/ coul be worth looking into how they handle the remaining optional trailing fields ... if they all go away including the comma, it may be legit.

To me it'd make much more sense to leave the comma in any case (even when unit is empty)

sappelhoff commented 3 years ago

We have the same for "markers" -> the last (trailing) optional parameter seems to remove the final comma if it's not present:

image

cbrnr commented 3 years ago

I wouldn't trust these specs too much but try to catch as many cases as possible (so in this case I'd try to handle a trailing comma even though it's technically invalid).

hoechenberger commented 3 years ago

We have the same for "markers" -> the last (trailing) optional parameter seems to remove the final comma if it's not present:

Ok so this seems to be a conscious decision in the specs, then.

sappelhoff commented 3 years ago

I am still interest in how @arthurlgk obtained the file

hoechenberger commented 3 years ago

I am still interest in how @arthurlgk obtained the file

The header they sent me starts with

Brain Vision Data Exchange Header File Version 1.0
; Data created by the Vision Recorder

I wonder which version of BV Recorder that was.

hoechenberger commented 3 years ago

@arthurlgk This problem has now been fixed in the development version of MNE-Python. The fix will be included in the next bugfix release, for which we haven't determined a release date yet.

arthurlgk commented 3 years ago

@hoechenberger Thank you very much. Is it possible for me to access this version now?

hoechenberger commented 3 years ago

@hoechenberger Thank you very much. Is it possible for me to access this version now?

Yes. How did you install MNE?

Also: I'd still be interested to know how you got your hands on those files :) Do you know which version of BV recorder was used?

arthurlgk commented 3 years ago

@hoechenberger Thank you very much. Is it possible for me to access this version now?

Yes. How did you install MNE?

Also: I'd still be interested to know how you got your hands on those files :) Do you know which version of BV recorder was used?

I used pip install in the terminal. Could you please tell me how to install the development version? Thank you. The file is given from my professor. Because now I have no access to the lab computer, I will ask him about that.

hoechenberger commented 3 years ago

I used pip install in the terminal.

Ok, it's easy then. I suggest you install our maintenance branch (which will soon become 0.21.1) with my fix. To do that, simply run:

pip install -U https://github.com/hoechenberger/mne-python/archive/backport-8434.zip

The file is given from my professor. Because now I have no access to the lab computer, I will ask him about that.

That would be great! Thank you

arthurlgk commented 3 years ago

I used pip install in the terminal.

Ok, it's easy then. I suggest you install our maintenance branch (which will soon become 0.21.1) with my fix. To do that, simply run:

pip install -U https://github.com/hoechenberger/mne-python/archive/backport-8434.zip

The file is given from my professor. Because now I have no access to the lab computer, I will ask him about that.

That would be great! Thank you

It is working now. Thank you very much. But when I am trying to run plot_component function, it cannot find electrode locations. Is this a problem with my recorder?

WARNING:root:Did not find any electrode locations (in the info object), will attempt to use digitization points instead. However, if digitization points do not correspond to the EEG electrodes, this will lead to bad results. Please verify that the sensor locations in the plot are accurate.
RuntimeError: No digitization points found.
hoechenberger commented 3 years ago

But when I am trying to run plot_component function, it cannot find electrode locations. Is this a problem with my recorder?

No, it's not a problem with your recorder, but you need to tell MNE which montage (i.e., which cap) was used when recording. Since it's a BrainProducts system, I assume you used some kind of EasyCap or ActiCap. You need to ask your professor which cap they used specifically. Once you have that info, we can show you how to tell MNE about it.

arthurlgk commented 3 years ago

But when I am trying to run plot_component function, it cannot find electrode locations. Is this a problem with my recorder?

No, it's not a problem with your recorder, but you need to tell MNE which montage (i.e., which cap) was used when recording. Since it's a BrainProducts system, I assume you used some kind of EasyCap or ActiCap. You need to ask your professor which cap they used specifically. Once you have that info, we can show you how to tell MNE about it.

Oh it’s actiCap

hoechenberger commented 3 years ago

You'd still need to find out the specific type of ActiCap.

But I can share with you the template montage I generated for what we used in our old lab. (attached)

You can load the montage and visualize it:

fname_montage = base_dir / 'achtiCHamp_64_channels_and_fiducials_Theta_Phi.txt'
dig_montage = mne.channels.read_custom_montage(fname_montage)
dig_montage.plot()

When you assign it to your raw data:

raw.set_montage(dig_montage)

you will get:

ValueError: DigMontage is only a subset of info. There are 64 channel positions not present in the DigMontage. The required channels are:
...

This is because in your VHDR file, the channels are named Channel 1 etc., which doesn't match the names in the montage file (proper channel locations like Fp1, Oz). So that's something you'll need to fix in your input data, otherwise there's no way to know where those channels used to be located on a participant's head.

achtiCHamp_64_channels_and_fiducials_Theta_Phi.txt

arthurlgk commented 3 years ago

Hi @hoechenberger , so we were using pycorder with python 2.7 to record the data. For the montage plot, we have our own sfp file. In 3d, it looks fine. But in the 2D plot, it looks like they are congregated and off center. Do I need to worry about it? Is this issue caused by the head _size?

hoechenberger commented 3 years ago

so we were using pycorder with python 2.7 to record the data.

Good to know, thanks!

For the montage plot, we have our own sfp file. In 3d, it looks fine. But in the 2D plot, it looks like they are congregated and off center. Do I need to worry about it? Is this issue caused by the head _size?

The off-center positioning shouldn't be related to the head size. It's really hard to tell what's going on without looking at the montage file. Could you share it here?

arthurlgk commented 3 years ago

@hoechenberger It doesn't support sfp file here. So I shared the file with you via email. Thank you for your help.