FIL-OPMEG / OPyM

OPM data in MNE-Python
GNU General Public License v3.0
3 stars 1 forks source link

Sensor / alignmnet shenanigans #4

Closed georgeoneill closed 2 years ago

georgeoneill commented 2 years ago

There appears to be something strange afoot with going on with the registration between the anatomy and the sensors where the fiducials (spheres in figures) are floating away from the head. The diamonds are just estimates from fsaverage but these are at least on the scalp.

image

Code below:


import mne
from opym import read_raw_ucl
import os.path as op

data_root = op.abspath('D:\masters_example_data\data')
data_bin = op.join(data_root,'sub-001_ses-001_task-motor4way_run-001_meg.bin')

raw = read_raw_ucl(data_bin)
info = raw.info;

# Lets have a look at trying to align data in the source space

subjects_dir = op.abspath('D:\\recons')
subject = 'masters-22-001'
# fs_dir = mne.datasets.fetch_fsaverage(verbose=True)
# subjects_dir = op.dirname(fs_dir)
# subject = 'fsaverage'

# set up the coreg object (this doesnt initialise it)
coreg =  mne.coreg.Coregistration(info, subject, subjects_dir,fiducials=info['dig'])

# first alignment
plot_kwargs = dict(subject=subject, subjects_dir=subjects_dir, dig=True, eeg=[],
                   meg='sensors', show_axes=True,
                   coord_frame='mri',mri_fiducials='estimated') #debugging with estimated
view_kwargs = dict(azimuth=45, elevation=90, distance=0.6,
                   focalpoint=(0., 0., 0.))
fig = mne.viz.plot_alignment(info, trans=coreg.trans, **plot_kwargs)

# do the initial fit with the fiducials
coreg.fit_fiducials(verbose=True)
# do the initial fit with the fiducials
fig = mne.viz.plot_alignment(info, trans=coreg.trans, **plot_kwargs)
print(coreg.trans)

Also confirm from coreg.trans that it is indeed an identy transform in this case, as its a headcast derived from an MRI.

I have a hunch its CRAS.

georgeoneill commented 2 years ago

Yeah the CRAS offset was precisely the problem.

image

Reference code for future me


# set up the coreg object (this doesnt initialise it)
dig = copy.deepcopy(info['dig'])

# hack to shift by CRAS
lol = mne.read_surface(op.join(subjects_dir,subject,'bem','watershed',subject+'_brain_surface'),read_metadata=True)
cras = lol[2]['cras']/1000
for ii in range(3):
    dig[ii]['r']=dig[ii]['r']-cras

coreg =  mne.coreg.Coregistration(info, subject, subjects_dir,fiducials=dig)