Skip to content

Instantly share code, notes, and snippets.

@dengemann
Last active December 13, 2015 20:48
Show Gist options
  • Save dengemann/4972638 to your computer and use it in GitHub Desktop.
Save dengemann/4972638 to your computer and use it in GitHub Desktop.
""" How to add measurment info to bti files.
Warning, this is example code. Trivially, you need to change paths but also
this code assumes you already exported the weights to .txt files and your
path is organized like this:
subjects_dir/subject{here are the weights}/kind{main, resting state, rempty room}/run/files{raw.fif}
"""
import os
import os.path as op
import glob
from commands import getstatusoutput
subjects = glob.glob('20*')
make_comp = 'mne_create_comp_data --in %s --out %s'
add_to_meas = 'mne_add_to_meas_info --add %s --dest %s'
src = '/data/meg_store1/exp/SOMO01'
for sub in subjects:
fis = sorted([fi for fi in glob.glob(op.join(src, sub, '*.txt'))])
for fi, name in zip(fis, ('rest', 'main', 'room')):
fname = op.join(src, sub, name, 'run', 'weights.fif')
print fi, fname
cmd = make_comp % (fi.replace(' ', '\ '), fname)
res, msg = getstatusoutput(cmd)
if res > 0:
raise Exception('%s returned with error code %i' % (cmd, res))
dest = op.join(src, sub, name, 'run', name + '_raw.fif')
cmd = add_to_meas % (fname, dest)
res, msg = getstatusoutput(cmd)
if res > 0:
raise Exception('%s returned with error code %i' % (cmd, res))
print msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment