-
-
Save dengemann/dbacc6e4941ca1082540 to your computer and use it in GitHub Desktop.
This file contains 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
cfg = read_study_file(op.join(path, 'study.json')) | |
# select conditions | |
conditions = cfg.EVENTS.CONDITIONS.sm_sanity_button | |
cov_type = 'eroom' | |
# organize averages along subjects for each conditions | |
stcs = OrderedDict([(k, {}) for k in conditions._asdict()]) | |
for sub in subjects: | |
stcnames = [f for f in os.listdir(sub) if '.stc' in f and 'fsaverage' in f] | |
for cond, stcs_ in stcs.items(): | |
for name in stcnames: | |
if all([k in name for k in cond, cov_type, '-lh']): | |
fname = op.join(path, sub, name) | |
stc = read_source_estimate(fname) | |
stc.comment = op.split(fname)[-1][:-4] | |
stc.crop(0, stc.times[-1]) | |
stcs_.update({sub: stc}) | |
fsave_vertices = [np.arange(10242)] * 2 | |
X = make_group_matrix(stcs) # custom function to construct data matrix from stc dict | |
X = np.abs(X) | |
X = X[:, :, :, 0] - X[:, :, :, 1] | |
X = np.transpose(X, [2, 1, 0]) | |
# adapted example code starts here. | |
# Now let's actually do the clustering. This can take a long time... | |
# Here we set the threshold quite high to reduce computation. | |
connectivity = spatial_tris_connectivity(grade_to_tris(5)) | |
# p_threshold = cfg.STATS.p_threshold | |
p_threshold = 0.05 | |
df = len(subjects) - 1 | |
t_threshold = -stats.distributions.t.ppf(p_threshold / 2., df) | |
print 'Clustering.' | |
T_obs, clusters, cluster_p_values, H0 = \ | |
spatio_temporal_cluster_1samp_test(X, connectivity=connectivity, | |
n_jobs=-1, | |
threshold=t_threshold) | |
# Now select the clusters that are sig. at p < 0.05 (note that this value | |
# is multiple-comparisons corrected). | |
good_cluster_inds = np.where(cluster_p_values < 0.05)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment