[Eeglablist] Fix for wrong reference channel location

Downey, Ryan J RDowney at bme.ufl.edu
Fri Feb 22 16:40:47 PST 2019

Hi Arno,

I wasn't suggesting to rotate the electrodes back to MNI. I was suggesting that the eeg_checkset function be modified so that the same exact rotation which is already automatically applied by EEGLAB to all of the normal electrodes (EEG.chanlocs) also gets applied to the reference channel location (EEG.chaninfo.nodatchans) immediately after someone uses "look up locs". 

Currently, if someone 1) clicks "edit/Channel Locations", 2) appends their reference channel with standardized name, 3) looks up locs with MNI BEM based on standardized channel names, and finally 4) average re-references their data with the option set to add the reference channel back as a data channel, then all of the topoplots will be incorrect. Specifically, the contribution of the former reference channel (new data channel) to the topoplot will be in the wrong location because eeg_checkset rotated EEG.chanlocs from +Y (MNI) to +X (standard EEGLAB) after the user "looked up locs" and closed pop_chanedit but eeg_checkset didn't touch EEG.chaninfo.nodatchans at all even though it was defined +Y just like all the other channels. When the user later adds the reference channel back, the unrotated (+Y version) of the reference channel's location info simply gets copied from EEG.chaninfo.nodatchans to EEG.chanlocs. So the now the newly concatenated EEG.chanlocs (size N original channels + 1 ref) has all of the original channels defined with respect to nose being +X whereas the newly added channel (old reference) has location information with respect to a different coordinate system (noise +Y). Meanwhile, EEGLAB thinks all channels are defined +X. 

The code I listed previously solves the issue. I simply extended what you guys already wrote. I didn't make any drastic change so there should be no conflict, and the code I provided prevents issues with topoplot rather than introduces them. If for some reason people don't want to incorporate the code into eeg_checkset, a simple work around for users is to make sure they call "look up locs" AFTER they have already added the reference channel back as a data channel. In this case, the existing code in eeg_checkset properly rotates everything together (from +Y to +X) because your original reference channel info is contained in EEG.chanlocs along with all the other channels rather than in EEG.chaninfo.nodatchans when eeg_checkset gets called and sees nosedir temporarily set to +Y. 

Note this issue can still carry over into dipfit results. If users append the reference channel, look up its location, and then add it back after re-referencing (in that specific order), then EEG.chanlocs will have a single channel (old ref) with the wrong coordinates (every channel but one defined with respect to nose +X and then a single channel defined with noise +Y). When you later do co-registration with dipfit, yes you are right that EEGLAB's +X defined EEG.chanlocs gets automatically rotated to +Y to match the MNI head. However, the important thing to remember is that the old ref channel is still wrong in EEG.chanlocs (defined +Y, different from all the other channels). Thus, when EEGLAB rotates everything in EEG.chanlocs to match MNI's +Y definition for dipfit, the already wrong ref location gets rotated just the same and ends up still in an incorrect location. When you later manually coregister to fine tune the placement, it just changes the general rotation, position, and scale of the set electrodes as a whole, so it does nothing to fix your original reference channel which is different from all the other electrodes. I've tested the issue Li Xiang originally described and I've seen topoplots be wrong as well as the location of the old reference channel on the MNI model even after dipfit co-registration. If you're not convinced, I can put together an example .set file and some code to prove the issue I'm describing, but you should be able to try it yourself on any dataset where you have standardized channel names so long as you follow the specific order I described.


Ryan J. Downey
Postdoctoral Associate
Human Neuromechanics Laboratory
University of Florida

-----Original Message-----
From: eeglablist <eeglablist-bounces at sccn.ucsd.edu> On Behalf Of Arnaud Delorme
Sent: Friday, February 22, 2019 1:28 PM
Cc: eeglablist <eeglablist at sccn.ucsd.edu>
Subject: Re: [Eeglablist] Fix for wrong reference channel location

Dear Ryan and others,

Yes, the MNI coordinates in EEGLAB are rotated by 90 degrees when you use the MNI template electrode location file. This is because the convention in EEGLAB is to use the +X axis as the direction for the nose. Historically this did not use to be the case.. The nose direction was not fixed. But the issue is that all functions plotting channels had to know about the nose direction which was not convenient or user friendly. When you use the MNI montage for your electrode locations (look up electrode positions based on labels), it is rotated automatically by 90 degree so nose direction is along +X. 

However, this is only for 2-D plotting of electrode. Whenever you plot in 3-D (headplot) or use source localization (dipfit), your electrode location are coregistered with the model (so rotated back to MNI space if you do source localization in the MNI space). This is even done automatically in EEGLAB: When you use your montage for source localization with the MNI brain, it is rotated back to its original MNI space.

So the constraint of using +X as the nose dimension only apply to 2-D plots. I would not rotate back the electrodes to MNI space in EEGLAB as Ryan suggest, because then the scalp topographies will be wrong (as they assume nose in the +X direction).

Best wishes,


> On Feb 18, 2019, at 11:31 AM, Downey, Ryan J <RDowney at bme.ufl.edu> wrote:
> This fix is in response to the post by Li Xiang (https://urldefense.proofpoint.com/v2/url?u=https-3A__sccn.ucsd.edu_pipermail_eeglablist_2015_010584.html&d=DwIGaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=KssPiEhnhBiSJO8B8Z52FmDLXXIqSZMVgZMN9FykiAE&m=_IJkznl6PDN3IqOiyh2zDO6YGDfK8e_2VmCMsjPsw2M&s=mOL2ZqNnLGHM9dnkhYcPZVFiDLBBFFb2LYuySemP43Q&e=), titled “Wrong channel location with MNI brain model.” I’ve been meaning to share this for a while. Sorry for the delay. Please let me know if there is a better way to respond specifically to old posts rather than creating a new thread.
> Issue: Let’s assume 10-5 electrode naming conventions. If you take raw data, use pop_chanedit to append your reference channel as a “nodatchan”, then “look up locs” with MNI, and and finally close pop_chanedit, then your original reference channel will have the wrong location. 
> Cause: the MNI brain is defined with the nose along +Y and in EEGLAB a rotation is applied to data channel locations to align the nose to +X; however, this same rotation isn’t applied to “nodatchan” entries (i.e. the reference channel you appended). If you click “plot 3-D (xyz)” immediately after “look up locs”, you’ll see that the reference channel appears in what seems like the correct location, but note that even though the reference is correct with respect to the locations of all the normal EEG channels, everything is temporarily aligned with nose set to +Y. When you click “ok” to close pop_chanedit, then the function eeg_checkset gets called. Eeg_checkset notices your channels aren’t aligned how it prefers (line 1078), and it rotates the chanloc information (lines 1086-1098). In the 2015 post by Li Xiang, the thought was that it was related to adding the reference channel back to the data after average referencing, but with my own tests I can see the reference channel location info is wrong before reaching the re-referencing step.
> Fix: add the following code immediately after line 1098 (i.e. after the for loop that goe through all EEG.chanlocs and rotates the location info). The code below is essentially a copy-paste of 1086-1098 but modified for EEG.nodatchans (where your reference location is stored initially).
> %%%%%%%%%%%%%%%%%%%
> for index = 1:length(EEG.chaninfo.nodatchans)
>     if ~isempty(EEG.chaninfo.nodatchans(index).theta)
>         rotategrad = rotate/180*pi;
>         coord = (EEG.chaninfo.nodatchans(index).Y + EEG.chaninfo.nodatchans(index).X*sqrt(-1))*exp(sqrt(-1)*-rotategrad);
>         EEG.chaninfo.nodatchans(index).Y = real(coord);
>         EEG.chaninfo.nodatchans(index).X = imag(coord);
>         EEG.chaninfo.nodatchans(index).theta     = EEG.chaninfo.nodatchans(index).theta    -rotate;
>         EEG.chaninfo.nodatchans(index).sph_theta = EEG.chaninfo.nodatchans(index).sph_theta+rotate;
>         if EEG.chaninfo.nodatchans(index).theta    <-180, EEG.chaninfo.nodatchans(index).theta    =EEG.chaninfo.nodatchans(index).theta    +360; end;
>         if EEG.chaninfo.nodatchans(index).sph_theta>180 , EEG.chaninfo.nodatchans(index).sph_theta=EEG.chaninfo.nodatchans(index).sph_theta-360; end;
>     end;
> end;
> %%%%%%%%%%%%%%%%%%%
> Sincerely,
> Ryan J. Downey
> Postdoctoral Associate
> Human Neuromechanics Laboratory
> University of Florida
> _______________________________________________
> Eeglablist page: 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__sccn.ucsd.edu_eegl
> ab_eeglabmail.html&d=DwIGaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpW
> lZM&r=KssPiEhnhBiSJO8B8Z52FmDLXXIqSZMVgZMN9FykiAE&m=_IJkznl6PDN3IqOiyh
> 2zDO6YGDfK8e_2VmCMsjPsw2M&s=-NV7vvjzZtoSg2bH_ITzrWYLAQq4n6qygnvTrbzJ8a
> 4&e= To unsubscribe, send an empty email to 
> eeglablist-unsubscribe at sccn.ucsd.edu
> For digest mode, send an email with the subject "set digest mime" to 
> eeglablist-request at sccn.ucsd.edu

Eeglablist page: https://urldefense.proofpoint.com/v2/url?u=http-3A__sccn.ucsd.edu_eeglab_eeglabmail.html&d=DwIGaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=KssPiEhnhBiSJO8B8Z52FmDLXXIqSZMVgZMN9FykiAE&m=_IJkznl6PDN3IqOiyh2zDO6YGDfK8e_2VmCMsjPsw2M&s=-NV7vvjzZtoSg2bH_ITzrWYLAQq4n6qygnvTrbzJ8a4&e=
To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu
For digest mode, send an email with the subject "set digest mime" to eeglablist-request at sccn.ucsd.edu

More information about the eeglablist mailing list