Skip to content

Instantly share code, notes, and snippets.

@bloyl
Created January 31, 2018 14:55
Show Gist options
  • Save bloyl/13cc7e78625ab8b262ab43dab8a05175 to your computer and use it in GitHub Desktop.
Save bloyl/13cc7e78625ab8b262ab43dab8a05175 to your computer and use it in GitHub Desktop.
from mne import read_trans
from mne import io
import os.path as op
from mne.io.constants import FIFF
from mne.transforms import apply_trans, combine_transforms
ds_fname = 'test.ds'
meas_fname = '%s-info.fif' % op.splitext(ds_fname)[0]
# save the measurement info so use in mne coreg...
raw = io.read_raw_ctf(ds_fname, preload=False)
io.write_info(meas_fname, raw.info)
# run mne coreg...
# read in the transformation that you save in mne coreg
trans_fname = 'test-trans.fif'
trans = read_trans(trans_fname)
# Print out the points
# collect points and labels to write.
info = raw.info
labels = []
pts = []
for p in info['dig']:
if p['kind'] not in [FIFF.FIFFV_POINT_CARDINAL,
FIFF.FIFFV_POINT_EXTRA]:
continue
# pick label
if p['kind'] == FIFF.FIFFV_POINT_CARDINAL:
if p['ident'] == FIFF.FIFFV_POINT_LPA:
labels.append('MEG_HPI_LPA')
elif p['ident'] == FIFF.FIFFV_POINT_NASION:
labels.append('MEG_HPI_NASION')
elif p['ident'] == FIFF.FIFFV_POINT_RPA:
labels.append('MEG_HPI_RPA')
else:
labels.append('MEG_HPI_OTHER?')
elif p['kind'] == FIFF.FIFFV_POINT_EXTRA:
if p['ident'] == 2000:
labels.append('POL_HPI_LPA')
elif p['ident'] == 2001:
labels.append('POL_HPI_NASION')
elif p['ident'] == 2002:
labels.append('POL_HPI_RPA')
else:
labels.append('POL_EXTRA_%d' % p['ident'])
# pick point FIFFV_MNE_COORD_CTF_HEAD
if p['coord_frame'] == FIFF.FIFFV_COORD_HEAD:
pts.append(apply_trans(trans, p['r']))
elif p['coord_frame'] == FIFF.FIFFV_COORD_MRI:
pts.append(p['r'])
elif p['coord_frame'] == FIFF.FIFFV_MNE_COORD_CTF_HEAD:
pts.append(apply_trans(trans, p['r']))
# pts.append(apply_trans(ctf_trans, p['r']))
for l, p in zip(labels, pts):
print ("%15s - %0.3f, %0.3f, %0.3f" % (l, p[0], p[1], p[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment