Got incorrect alignment

,

Hi,
I am new to MNE. I am using this code to generate sphere model, source space for MEG source reconstruction but got an incorrect alignment. Could someone please suggest what is the wrong here?

sphere = mne.make_sphere_model(r0='auto', head_radius='auto', info=raw.info, 
                               relative_radii=(0.9, 0.92, 0.97, 1.0), 
                               sigmas=(0.33, 1.0, 0.004, 0 is provided.33), 
                               verbose=True)

src = mne.setup_volume_source_space(subject=None, pos=10., 
                                    bem=sphere, mindist=2., exclude=0.0, verbose=True) 
 
fwd = mne.make_forward_solution(raw.info, 
                                trans=None ,  
                                src=src, bem=sphere, 
                                     eeg=False, n_jobs=n_jobs, verbose=True)

mne.viz.plot_alignment(raw.info, bem=sphere, src=src, dig=True,
                       trans=None, meg=False,
                       )

When I replaced trans=None by trans=mne.transforms.Transform(fro=4, to=5, trans=np.eye(4)), I got

As per my understanding, since the sphere is modeled with digitization points and source space is define as per the sphere model without providing any MRI, all should be in head coordinate frame.
Then why am I getting such miss-alignment?
Thank you.

  • MNE version: 1.4.0
  • operating system: Ubuntu 20.04

There are some parts of your example code that are not valid, such as

sphere = mne.make_sphere_model(r0='auto', head_radius='auto', info=raw.info, 
                               relative_radii=(0.9, 0.92, 0.97, 1.0), 
                               sigmas=(0.33, 1.0, 0.004, 0 is provided.33),  # <- ???
                               verbose=True)

If I correct that (by using the default for relative_radii and sigmas, which is what it seems like you want) and I assume your raw is coming from the MNE sample dataset, your example doesn’t even run for me:

import mne
fname = mne.datasets.sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif"
raw = mne.io.read_raw_fif(fname)
sphere = mne.make_sphere_model(r0="auto", head_radius="auto", info=raw.info)
src = mne.setup_volume_source_space(subject=None, pos=10., bem=sphere, mindist=2., exclude=0.0)
fwd = mne.make_forward_solution(raw.info, trans=None, src=src, bem=sphere, eeg=False)
mne.viz.plot_alignment(raw.info, bem=sphere, src=src, dig=True, trans=None, meg=False)

the above yields

ValueError: A head<->mri transformation matrix (trans) is required to plot a mri-coordinate source space in head coordinates, `trans=None` is not allowed

Please double-check your code and provide a new / updated code sample that will run in a clean python session via copy-paste.

1 Like

I was able to get good alignment by passing mne.setup_volume_source_space(..., sphere=sphere, ...) instead of bem=sphere .

import numpy as np
import mne
fname = mne.datasets.sample.data_path() / "MEG" / "sample" / "sample_audvis_raw.fif"
raw = mne.io.read_raw_fif(fname)
sphere = mne.make_sphere_model(r0="auto", head_radius="auto", info=raw.info)
src = mne.setup_volume_source_space(subject=None, pos=10., sphere=sphere, mindist=2., exclude=0.0)
fwd = mne.make_forward_solution(raw.info, trans=None, src=src, bem=sphere, eeg=False)
trans = mne.transforms.Transform(fro=4, to=5, trans=np.eye(4))
mne.viz.plot_alignment(raw.info, bem=sphere, src=src, dig=True, trans=trans, meg=False)

@drammock
Thank you very much, it perfectly worked.