Skip to content

Instantly share code, notes, and snippets.

@wronk
Created October 28, 2015 22:09
Show Gist options
  • Select an option

  • Save wronk/593bfc29687e61e72cde to your computer and use it in GitHub Desktop.

Select an option

Save wronk/593bfc29687e61e72cde to your computer and use it in GitHub Desktop.
Convert epochs to stc and save as array for use in Blender.
"""
epochsToStc
@author:wronk
Convert epochs to stc and save as array for use in Blender.
"""
import mne
import numpy as np
from mne.minimum_norm import apply_inverse as inv_evoked
from os import path as op
from os import environ
import fnmatch
import os
subj_list = ['fsaverage']
subj_info_dir = op.join(environ['CODE_ROOT'], 'switchBCIFiles')
subjListFName = op.join(subj_info_dir, 'SoP_MEG.txt')
struct_dir = op.join(environ['SUBJECTS_DIR'])
subj_d = []
stc_dir = '/media/Toshiba/Blender/Ross_AudVis/stcs/'
save_dir = '/media/Toshiba/Blender/Ross_AudVis/'
##############################################################################
### Load inverse, forward, and epochs
print 'Reading stcs'
f_names = ['Masker', 'Target']#, 'Visual']
#f_names = ['Visual']
stc_list = []
for fi, f_name in enumerate(f_names):
print '\t' + f_name,
temp_stc = mne.read_source_estimate(op.join(stc_dir, f_name),
subject=subj_list[0])
temp_stc.tmin += 0.050
temp_stc.crop(-0.050, None)
temp_stc = temp_stc.morph('fsaverage', grade=None, smooth=10)
stc_list.append(temp_stc)
print ' ... Done'
##############################################################################
### Calculate inverse and save as array
print 'Saving stcs to npy for:'
for si, stc in enumerate(stc_list):
print '\t' + f_names[si],
# Morph to fill the entire surface
#s_d['stc'] = temp_stc.morph(s_d['name'], grade=None, smooth=5)
# Save arrays with the stc data
# Data for both hemispheres is saved in each
np.save(op.join(save_dir, 'stcs/data', f_names[si] + '-lh'), stc.lh_data)
np.save(op.join(save_dir, 'stcs/data', f_names[si] + '-rh'), stc.rh_data)
np.save(op.join(save_dir, 'stcs/vertices', f_names[si] + '-lh'),
stc.vertices[0])
np.save(op.join(save_dir, 'stcs/vertices', f_names[si] + '-rh'),
stc.vertices[1])
#stc_data = np.load(op.join(save_dir, 'stcs/data', 'Visual-lh.npy'))
print ' ... Done'
#stc = mne.read_source_estimate(op.join(save_dir, 'stcs/data', f_names[0] + 'debug'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment