def save_ttest_result_for_blender(events_id, cm_big='YlOrRd', cm_small='PuBu', threshold=2, norm_by_percentile=True, norm_percs=(1,99), inverse_method='dSPM', do_print=False, n_jobs=1): for cond_id, cond_name in enumerate(events_id.keys()): for patient in get_patients(): results_file_name = op.join(LOCAL_ROOT_DIR, 'results_for_blender', '{}_{}_{}'.format(patient, cond_name, inverse_method)) if op.isfile('{}-stc.h5'.format(results_file_name)): print('{}, {}'.format(patient, cond_name)) stc = mne.read_source_estimate(results_file_name) data_max, data_min = utils.get_activity_max_min(stc, norm_by_percentile, norm_percs, threshold) print(data_max, data_min) scalar_map_big = utils.get_scalar_map(threshold, data_max, cm_big) scalar_map_small = utils.get_scalar_map(data_min, -threshold, cm_small) for hemi in ['rh', 'lh']: utils.check_stc_vertices(stc, hemi, op.join(BLENDER_DIR, 'fsaverage', '{}.pial.ply'.format(hemi))) data = utils.stc_hemi_data(stc, hemi) fol = '{}'.format(os.path.join(BLENDER_DIR, 'fsaverage', '{}_{}'.format(patient, cond_name), 'activity_map_{}').format(hemi)) utils.delete_folder_files(fol) params = [(data[:, t], t, fol, scalar_map_big, scalar_map_small, threshold, do_print) for t in xrange(data.shape[1])] utils.parallel_run(pool, _calc_activity_colors, params, n_jobs) else: print('no results for {} {}'.format(patient, cond_name))
def scatter_plot_perm_ttest_results(points, values, fs_pts, max_vals, fol): fig = plt.figure() ax = Axes3D(fig) ax.scatter(fs_pts[0, :, 0], fs_pts[0, :, 1], fs_pts[0, :, 2], c='white', edgecolors='none', alpha=0.01) ax.scatter(fs_pts[1, :, 0], fs_pts[1, :, 1], fs_pts[1, :, 2], c='white', edgecolors='none', alpha=0.01) m = utils.get_scalar_map(1, max_vals, color_map='YlOrRd') for ind, t in enumerate(points.keys()): print(t) colors = utils.arr_to_colors(values[t], 1, max_vals, colors_map='YlOrRd') sca = ax.scatter(points[t][:, 0], points[t][:, 1], points[t][:, 2], c=colors) if ind == 0: m.set_array(colors) plt.colorbar(m, ticks=range(1, max_vals + 1), shrink=.5, aspect=10) title_obj = plt.title('t={}'.format(t)) else: plt.setp(title_obj, text='t={}'.format(t)) plt.savefig(op.join(fol, '{}.jpg'.format(t))) sca.remove() plt.close()