Created
August 21, 2015 21:41
-
-
Save matt-erhart/ac4556330ff262f6ee5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path as op | |
import numpy as np | |
import mne | |
from mne import spatial_tris_connectivity, grade_to_tris | |
from mne.datasets import sample | |
from sklearn import cluster | |
from collections import Counter | |
from surfer import Brain, TimeViewer | |
############################################################################### | |
# Set parameters | |
data_path = sample.data_path() | |
stc_fname = data_path + '/MEG/sample/sample_audvis-meg' | |
subjects_dir = data_path + '/subjects' | |
# Load stc to in common cortical space (fsaverage) | |
stc = mne.read_source_estimate(stc_fname) | |
stc.resample(50) | |
stc = mne.morph_data('sample', 'fsaverage', stc, grade=5, smooth=20, | |
subjects_dir=subjects_dir,n_jobs=-1) | |
n_vertices_fsave, n_times = stc.data.shape | |
tstep = stc.tstep | |
connectivity = spatial_tris_connectivity(grade_to_tris(5)) | |
model = cluster.FeatureAgglomeration(n_clusters=200,connectivity=connectivity | |
,linkage='average',affinity='cityblock') | |
fit = model.fit(stc.data.T) | |
counts = Counter(fit.labels_) | |
an_roi = np.zeros(fit.labels_.shape) | |
an_roi[fit.labels_==1] = 10 | |
cluster_stc = mne.SourceEstimate(an_roi[:,None],vertices=stc.vertices,tmin=1,tstep=1) | |
# plot movies | |
brain = cluster_stc.plot(subject='fsaverage',hemi='split', colormap="jet", | |
subjects_dir=subjects_dir,views=['lat', 'med'], | |
config_opts=dict(width=2500, height=1400)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment