Get back a reference channel from acticap

External Email - Use Caution

Dear mne users,

I used an acticap system to collect data. This system has a common reference electrode localized on the FCz location. I would like to retrieve this electrode for further analysis,

What I would like to do is as follow:
- adding back the reference channel by using mne.add_reference_channels(raw, 'FCz'), which I guess should add this channel with values equal to zeros;
- then computing the average reference of all channel by using raw.set_eeg_reference('average') So I guess the values on the FCz channels should just be 0 minus the mean of all other channels;;
- then well maybe I will use the linked mastoid average or I will stay with the average one.

OK so the issues I have right now:
- could anyone confirm my rationale makes sense?
- second I have troubles with ?mne.add_reference_channels. For some reasons when I apply it I get an error "RuntimeWarning: the locations of multiple reference channels are ignored (set to zeros)". And apparently it is not updating the info structure.

Thank you for any help!

Sylvain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20181016/099a8df3/attachment.html

External Email - Use Caution

I'm not familiar with the processing pipeline, but if you drop us an
example file I'll try to see why FCz is dropped.

External Email - Use Caution

Ok I will try to find a space for holding a file if I do not manage to solve
the issues before, but here is some observations:

- the error "RuntimeWarning: The locations of multiple reference channels
are ignored (set to zero)" appearing when I use
mne.io.add_reference_channels is there only if previously I import the
brainvision data by specifying a montage. For some reasons specifying a
montage is creating a list called "dig" (I do not exactly know what it is),
and the presence of this list is causing issue in the code
there?https://github.com/mne-tools/mne-python/blob/master/mne/io/reference.py
line 219;

- so what I did is not importing the data by not specifying a montage. Then
concerning the fact that the Info was not updated I am sorry I did a mistake
in using mne.add_reference_channels instead of?mne.io.add_reference_channels
. Without io well it does not update anything.

Now still if anyone had an idea if the rationale of my original question is
ok I would be interested.

Thank you!

Sylvain

External Email - Use Caution

please share a file and code snippet so we better understand the issue
and we can document it and eventually help people not having this problem again.

if you have an issue, it's very likely someone else will have it too.

Alex

External Email - Use Caution

Ok here is the code for replicating the error:

import mne
import pandas as pd
import numpy as np
from mayavi import mlab
%matplotlib inline
%gui qt

# Open EEG file
data_path = '/home/sylvain/Desktop/Participant01'
raw_fname = data_path + '/Participant01.vhdr'

## Error further in the code (when adding reference channel) if I open the
file this way
#raw_file = mne.io.read_raw_brainvision(raw_fname,
# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? event_id={"actiCAP Data On": 9999},
# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? montage = 'standard_1020',
# ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? preload=True)

# The error diseapear if i just use this
raw_file = mne.io.read_raw_brainvision(raw_fname,
   ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? event_id={"actiCAP Data On": 9999},
   ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? preload=True)

raw_file = mne.io.add_reference_channels(raw_file, ['FCz'])

raw_file.set_montage('standard_1020')
raw_file.plot_sensors()

Do you know where I could stock the file it is quite big?

Thank you

Sylvain

External Email - Use Caution

maybe you can adjust this script usign our testing file

https://github.com/mne-tools/mne-python/tree/master/mne/io/brainvision/tests/data

?

External Email - Use Caution

Hi Sylvain!

Can you upload your file to your Dropbox or Google Drive and share the link?

In general, your approach makes sense to me, but I don't really understand why your Brainamp has an average reference electrode. This doesn't make sense, because an average reference is by definition the average of all involved channels, which means you cannot have a dedicated electrode for this. Maybe the data are collected with a FCz reference, and then they are re-referenced to average afterwards?

Anyway, I think the actual file would help us track down your issue.

Clemens

External Email - Use Caution

Hello Clemens!

Well I am saying exactly what you are saying:
- data are acquired with FCz as the reference channel on the brainvision
system. I want to retrieve FCz;
- so I was just about adding back FCz (zeros values), computing the average
reference (so the new FCz value will be zero minus the mean of other
channel);
- then either staying with the average reference or switching to linked
mastoid.

Now apart from the issues I had with various functions depicted in my
previous mail I am not 100% sure my rationale is ok.

Now concerning a file here is one (it is compressed) so maybe you can see
what I was refering to with functions causing issues.
https://www.dropbox.com/s/9rnf5o391vbxwr6/File_EEG.rar?dl=0

Thanks!

Sylvain

External Email - Use Caution

Dear Sylvain, Clemens, and Alex,

regarding the rationale:

- Say you recorded from 10 electrodes and referenced against another
electrode

- You thus have 11 electrodes, one of which contains a "zero" signal
(the reference)

- If you now apply the average reference, you are reducing the "rank" of
the data by one (see:
https://sccn.ucsd.edu/wiki/Linear_Representations_and_Basis_Vectors#EEG_Data_Reference_and_Re-referencing)

- Usually, the reference electrode is not included in the re-referenced
data ... so then you will have 10 electrodes and "full rank" data

- The problem arises by including the 11th electrode, because then you
would have rank deficient data.

- If you then re-reference the rank-deficient, average-re-referenced
data to mastoids again, you might run into problems (e.g., when trying
to run ICA).

I am not entirely sure about my reasoning, so another opinion would be
appreciated.

Best,

Stefan

External Email - Use Caution

        External Email - Use Caution

Hi Sylvain!

Can you upload your file to your Dropbox or Google Drive and share the link?

In general, your approach makes sense to me, but I don't really understand why your Brainamp has an average reference electrode. This doesn't make sense, because an average reference is by definition the average of all involved channels, which means you cannot have a dedicated electrode for this. Maybe the data are collected with a FCz reference, and then they are re-referenced to average afterwards?

This is exactly what happens on the actichamp system. Depending on your
cap layout and hardware revision, FCz is either a "normal" electrode or
a blue reference electrode that is in a separate cable strand like the
ground electrode is. You can see this when you're setting up the cap and
doing impedance measurements -- all of your impedances will be really
horrible until you set up FCz.

As Stefan hypothesized later, FCz is then left out after the internal
reference is applied (their terminology, see
actiCHamp series | Brain Products GmbH > Solutions ; but I
suspect that it's essentially an average reference or an approximate way
of doing the reference at infinity like in REST) so that the data are
full rank and "reference free".

(I really, really hate that term -- I think some BioSemi systems use it
to, but their physical reference electrode is labeled "CMS" for
"common-mode sensor".)

Phillip

External Email - Use Caution

Hello Stefan,

I somewhat get your idea but isn't rank deficiency occurring anyway when one
use average reference? Since all electrode are becoming a linear combination
of all the other one?
I mean I get your point but I am not sure if it is linked to the fact of
adding back a reference.

Thanks,

Sylvain

External Email - Use Caution

Hi!

Well I am saying exactly what you are saying:
- data are acquired with FCz as the reference channel on the brainvision
system. I want to retrieve FCz;
- so I was just about adding back FCz (zeros values), computing the average
reference (so the new FCz value will be zero minus the mean of other
channel);
- then either staying with the average reference or switching to linked
mastoid.

OK, I must have misread your initial question. Yes, this approach looks perfectly fine.

Regarding the issue you encounter, this seems to be a bug. The problem seems to be order in which you perform setting the montage and setting/adding a reference channel. It looks like if you set the montage before you add a reference, this warning message is produced (and the location of the newly added reference channel is incorrect). If you do it the other way round (first adding the reference and then setting the montage), everything is OK. I'm pretty sure this is unintended behavior so I've opened an issue with an example using one of our example data sets: Adding a reference does not work after a montage has been set · Issue #5619 · mne-tools/mne-python · GitHub

Let's continue the discussion related to this behavior on GitHub.

Regarding the recording setup, we have a BioSemi system which uses a CMS and DRL electrode. I never fully understood how this works, but my intuition was that this electrode(s) serve(s) as a reference. So all other (normal) channels record voltages referenced to that reference electrode, which is not part of the recorded channels because it is by definition always zero. I'm pretty sure that this is not doing an average reference though.

What Stefan is saying is correct, but I disagree that there is a problem with adding back a reference channel. This is just a particular issue with ICA, which cannot deal with rank deficient data. Average referenced data is rank deficient, but this does not have anything to do with whether you added a reference channel or not before the average reference computation.

Whether or not you add back the (all zero) reference channel depends on what you want. If the reference channel happens to be in a location you're interested in, you need to add it back to the data before computing the average reference. If the reference channel is in a location you're not interested in anyways (e.g. on a mastoid), you don't need to add it to the data and you just compute the average reference using the electrodes you have. In either case, you end up with rank-deficient data, which might be problematic for ICA if you don't explicitly reduce the dimensionality by 1 beforehand.

Clemens

External Email - Use Caution

Hey Philip,

Sadly I have a system with the reference being plugged with an external
strand and located on FCz.
I have trouble understanding the difference between an "internal" reference
and FCz itself. I do not know but to me it seems that at the end the voltage
recorded at every electrode is just the difference with FCz. What is the
difference with it being internal?

I really prefer the way it is working with Biosemi since CMS is not located
on a position of the standard1020. Anyway I disgress but just for maybe
further acquisition do you think it would be ok if I just plug the REF (so
the FCz electrode supposedly) to a mastoid (since I wont use the mastoid for
any analysis).

I know it is not directly linked to MNE so please apologize if I disgress.

Sylvain

External Email - Use Caution

Hello,

Thank you for your answer Clemens.

So in order to be clear in getting back FCz, referencing to average and then
reducing dimensionality:

- first I add back FCz as a zeros channel;
- I compute the mean of each other channel and I substract 0 to this mean
for FCz;
- I then compute the average reference (will be rank deficient);
- I use the function mne.preprocessing.ICA specifying that
I?want?max_pca_components and?n_pca_components to be equal to my number of
channel minus 1.

Does it sound right?

Sorry for all the questions and thank so much for all these answers!

Sylvain

External Email - Use Caution

        External Email - Use Caution

Hey Philip,

Sadly I have a system with the reference being plugged with an external
strand and located on FCz.
I have trouble understanding the difference between an "internal" reference
and FCz itself. I do not know but to me it seems that at the end the voltage
recorded at every electrode is just the difference with FCz. What is the
difference with it being internal?

That's a very good question -- I haven't found anything in the Brain
Products documentation to make it clear what exactly their internal
reference is. If you have an explicitly marked FCz reference electrode
though and are using the standard workspaces, then it's the reference
channel and it's safe to add it back in as a bunch of zeros.

I really prefer the way it is working with Biosemi since CMS is not located
on a position of the standard1020.

It actually doesn't matter too much where your online reference is (as
long as you have electrodes at where your final reference will be),
because of the math of re-referencing. Voltage is inherently a
difference, so if your online reference is FCz then the voltage at every
channel is:

v_chan = efield_chan - efield_fcz

(and by definition, v_fcz is 0).

Then to re-reference, you just subtract out the voltage at the desired ref

v_chan_newref = v_chan - v_newref = efield_chan - efield_fcz -
(efield_newref - efield_fcz) = efield_chan - efield_newref

And then

v_fcz_newref = 0 - v_newref

v_newref = v_newref - v_newref = 0

So if you have electrodes on the mastoids and an online FCz reference,
then you can just re-reference to the mastoids offline.

Anyway I disgress but just for maybe
further acquisition do you think it would be ok if I just plug the REF (so
the FCz electrode supposedly) to a mastoid (since I wont use the mastoid for
any analysis).

That's fine -- in PyCorder and BrainVision Recorder, you can even
relabel the channel to reflect your actual recording setup.

Phillip

External Email - Use Caution

Hi!

So in order to be clear in getting back FCz, referencing to average and then
reducing dimensionality:

- first I add back FCz as a zeros channel;

Yes.

- I compute the mean of each other channel and I substract 0 to this mean
for FCz;

I'd say you compute the mean of all channels (which now include FCz).

- I then compute the average reference (will be rank deficient);

Yes.

- I use the function mne.preprocessing.ICA specifying that
I want max_pca_components and n_pca_components to be equal to my number of
channel minus 1.

Yes.

Clemens

External Email - Use Caution

Thanks Clemens!