Standard montages and coordinate systems

Hello,

I am trying to create an EEG forward model using

   1. anatomy from the sample dataset
   2. source space from sample_audvis-meg-oct-6-meg-inv.fif
   3. standard 1005 montage

When I check the consistency of the coordinate systems with plot_alignment, I
see that the electrode locations are off.

I think that I need to add transformation information to the info I make
based off the standard montage. Am I right? If yes, could you please advise
me what transformation should I use? And if no, what should I do instead?

Any help will be greatly appreciated.

Sincerely, Laura Novelinkova

Additional info: I am on Windows 7, Python version is 2.7, mne version is
15, I run the code in iPython console. Below is my current code and the
output of plot_alignment:

from mayavi import mlab # without this the windows show nothing and hang python
import mne
from mne.datasets import sample
import os

%gui qt

subject = 'sample'
data_path = sample.data_path()
inverse_operator_file_path = os.path.join(data_path, 'MEG', 'sample',
'sample_audvis-meg-oct-6-meg-inv.fif')
subjects_dir = os.path.join(data_path, 'subjects')

montage_1005 = mne.channels.read_montage(kind='standard_1005')
fake_info = mne.create_info(ch_names=montage_1005.ch_names,
sfreq=1000, ch_types='eeg', montage=montage_1005)
trans = os.path.join(data_path, 'MEG', 'sample', 'sample_audvis_raw-trans.fif')
source_space = mne.read_source_spaces(inverse_operator_file_path)

mne.viz.plot_alignment(info=fake_info, trans=trans, subject=subject, dig=True,
                       meg=False, src=source_space, subjects_dir=subjects_dir)

[image: Inline image 1]

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20171126/b6bb691f/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: misaligned_electrodes.png
Type: image/png
Size: 203303 bytes
Desc: not available
Url : http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20171126/b6bb691f/attachment-0001.png

Hi Laura,

Are you sure you want to use the `sample` subject as your anatomy? If you?re aiming at some sort of ?template brain? source localisation approach, would something like the ?fsaverage? brain be more appropriate?

The problem is that the transformation you load is between sample?s fiducial head coordinates and sample?s MRI. The default montage you load is however not in sample?s head frame, so your coreg is off.

For the fsaverage-approach, something like the following might work. NB: there?s a small bug that?s being fixed on github (see [1]). You can either wait until it?s in master, or check out the fix yourself.

[1](https://github.com/mne-tools/mne-python/issues/4783)

/Chris

subject = 'fsaverage'
subjects_dir = '/Users/cjb/tmp/subs_dir? # change appropriately
mne.create_default_subject(subjects_dir=subjects_dir)

montage_1005 = mne.channels.read_montage(kind='standard_1005')
fake_info = mne.create_info(ch_names=montage_1005.ch_names, sfreq=1000, ch_types='eeg', montage=montage_1005)

# need to write a file to load into coregistration, not possible to pass info directly
fake_raw = mne.io.RawArray(np.zeros((len(fake_info['ch_names']), 1)), fake_info)
fake_raw.save('fake_raw.fif', overwrite=True)

# coregister and save trans
mne.gui.coregistration(inst='fake_raw.fif', subject=subject, subjects_dir=subjects_dir)

trans = _path_to_saved_trans.fif_

# set src=None, or calculate a source space, e.g.
# src = mne.setup_source_space(subject, subjects_dir=subjects_dir,
                               spacing='oct5?)

mne.viz.plot_alignment(info=fake_info, trans=trans, subject=subject, dig=True,
                       meg=False, src=None, subjects_dir=subjects_dir)

Hi Chris,

thank you for replying.

I want(ed) to use the 'sample' subject as my default brain because I
already used it for the MEG data and wanted to do the same analysis on my
EEG data and use the same source space. 'fsaverage' approach would have
probably been more appropriate and I plan to go this route in future when I
get my hands on a Linux machine. create_default_subject requires me to have
freesurfer as far as I understood and my machine is not powerful enough to
run a Freesurfer virtual machine. I could probably do the copying manually
on Windows but I would rather do it normally once I have Linux.

For now, I think, I want to stick to the 'sample' subject. So, I have two
ways to proceed the way I see it:

1) Do two coregistrations of MEG and EEG montages writing down the
coordinates of the fiducials on the first run so that the coregistrations
are the same. I am not sure about this because in the mne's manual and
elsewhere I read that it is not something that should be done by someone as
inexperienced as I am.

2) Find the information about fiducials somewhere in the sample's files.
Use it to manually construct transformation,

To me, the second route seems to be the better one because I am more
familiar with linear algebra than anatomy. I am still not sure about what
transformations are applied to what in mne though. When I ran
mne.viz.plot_alignment with the sample data but with trans=None, nothing
was co-aligned. Then I changed trans to 'sample_audvis_raw-trans.fif'. As
the result, source space and the head became co-aligned, but electrodes did
not because, as you wrote, their coordinates are not in the head coordinate
system as mne.viz.plot_alignment assumes.

So what I need is to transform the locations from the standard montage to
the head coordinate system, for which I need the coordinate of fiducial
points in that coordinate system.

I guess my question is this: does any of the sample's files contain the
coordinates of the fiducials in the head coordinate system (or MRI) that
were used during the construction of the inverse solution?

Hi Laura,

I?ll have to defer your question about sample?s fiducials to the dev?s. There?s no file in the sample data, as you point out, and I?m not certain where such information get saved, if indeed they do. But you could always just use mne.gui.coregistration; in your use case the precise locations on the MR won?t matter much.

Yes, you?d first need to transform the standard montage coordinates to sample?s head frame. Following your option 1), you could generate MEG(head) -> MRI, and EEG(no frame) -> MRI, then invert the former and apply on the latter (montage -> MRI -> head; I haven?t tested this, but it might work??). Then you?ll have to hack the EEG electrode coordinates in fake_info['chs?] to match. Important elements to focus on are ?loc? and ?coord_frame?, but Here be Dragons? I?m pretty sure neither linear algebra nor anatomy are the sticking points here, but certainly understanding how mne deals with sensor locations and transformations will be :wink:

I can?t send this without repeating (to posterity) that IMHO using a single-subject brain as a template for source reconstruction will not result in ?localisations? that are meaningful (they may be pretty, though). I would argue that the information that can be gleaned on spatial source distribution in a case like yours is fully contained in sensor-level topographies. Many would disagree :wink: Good luck!

/Chris