def save_frmi_color_per_subject(out_file, threshold=2): # subjects_folders = utils.get_subfolders(SPM_ROOT) good_subjects = ['pp002', 'pp003', 'pp004', 'pp005', 'pp006'] subjects_folders = [os.path.join(SPM_ROOT, sub) for sub in good_subjects] subjects_colors = utils.get_spaced_colors(len(subjects_folders)) # subjects_colors = utils.arr_to_colors(range(len(subjects_folders)), colors_map='Set1')[:, :3] for hemi in ['rh', 'lh']: first = True all_colors = [] for sub_id, (subject_fol, subject_color) in enumerate( zip(subjects_folders, subjects_colors)): subject = utils.namebase(subject_fol) print(hemi, subject) # if subject not in good_subjects: # continue fs_hemi_map = os.path.join( subject_fol, FS_HEMI_MAP_TEMPLATE.format(subject=subject, hemi=hemi)) old, brain = get_hemi_data(FS_SUBJECT, hemi, fs_hemi_map, 'pial') x = old.mlab_data brain.close() # x = nib.load(fs_hemi_map).get_data().squeeze() # plt.hist(x, bins=50) # plt.show() subject_colors = np.ones((len(x), 3)) print(sum(x > threshold)) # print(np.unique(x[np.where(x)])) subject_colors[x > threshold, :] = subject_color all_colors.append(subject_colors) all_colors = np.array(all_colors).mean(0) all_colors = np.hstack((np.ones( (all_colors.shape[0], 1)) * 10, all_colors)) np.save(out_file.format(hemi=hemi), all_colors)
def save_frmi_color_per_subject(out_file, threshold=2): # subjects_folders = utils.get_subfolders(SPM_ROOT) good_subjects = ["pp002", "pp003", "pp004", "pp005", "pp006"] subjects_folders = [os.path.join(SPM_ROOT, sub) for sub in good_subjects] subjects_colors = utils.get_spaced_colors(len(subjects_folders)) # subjects_colors = utils.arr_to_colors(range(len(subjects_folders)), colors_map='Set1')[:, :3] for hemi in ["rh", "lh"]: first = True all_colors = [] for sub_id, (subject_fol, subject_color) in enumerate(zip(subjects_folders, subjects_colors)): subject = utils.namebase(subject_fol) print(hemi, subject) # if subject not in good_subjects: # continue fs_hemi_map = os.path.join(subject_fol, FS_HEMI_MAP_TEMPLATE.format(subject=subject, hemi=hemi)) old, brain = get_hemi_data(FS_SUBJECT, hemi, fs_hemi_map, "pial") x = old.mlab_data brain.close() # x = nib.load(fs_hemi_map).get_data().squeeze() # plt.hist(x, bins=50) # plt.show() subject_colors = np.ones((len(x), 3)) print(sum(x > threshold)) # print(np.unique(x[np.where(x)])) subject_colors[x > threshold, :] = subject_color all_colors.append(subject_colors) all_colors = np.array(all_colors).mean(0) all_colors = np.hstack((np.ones((all_colors.shape[0], 1)) * 10, all_colors)) np.save(out_file.format(hemi=hemi), all_colors)
def check_colors(): subjects_folders = utils.get_subfolders(SPM_ROOT) good_subjects = ['pp002', 'pp003', 'pp004', 'pp005', 'pp006'] subjects_folders = [os.path.join(SPM_ROOT, sub) for sub in good_subjects] subjects_colors = utils.get_spaced_colors(len(subjects_folders)) # subjects_colors = utils.arr_to_colors(range(len(subjects_folders)), colors_map='Set1') plt.figure() for subject_fol, color in zip(subjects_folders, subjects_colors): subject = utils.namebase(subject_fol) plt.scatter([0], [0], label='{} {}'.format(subject, color), c=color) plt.legend() plt.show()
def check_colors(): subjects_folders = utils.get_subfolders(SPM_ROOT) good_subjects = ["pp002", "pp003", "pp004", "pp005", "pp006"] subjects_folders = [os.path.join(SPM_ROOT, sub) for sub in good_subjects] subjects_colors = utils.get_spaced_colors(len(subjects_folders)) # subjects_colors = utils.arr_to_colors(range(len(subjects_folders)), colors_map='Set1') plt.figure() for subject_fol, color in zip(subjects_folders, subjects_colors): subject = utils.namebase(subject_fol) plt.scatter([0], [0], label="{} {}".format(subject, color), c=color) plt.legend() plt.show()
def plot_3dscatter(points, labels, n_classes=None): plt.switch_backend('agg') fig = plt.figure() ax = fig.gca(projection='3d') points -= points.min(axis=0) points = points / points.max() xs = points[:, 0] ys = points[:, 1] zs = points[:, 2] if n_classes is None: n_classes = len(np.unique(labels)) colors = np.array(get_spaced_colors(n_classes)) for cl in range(n_classes): i = np.where(labels == cl) if len(i[0]) == 0: continue ax.scatter(xs[i], ys[i], zs[i], c=colors[cl], s=50, label=cl) #ax.scatter(xs, ys, zs, c=colors[labels], s=50) plt.axis('off') plt.axis('equal') ax.set_xlim(0, 1) ax.set_ylim(0, 1) ax.set_zlim(0, 1) ax.view_init(-30., 70.) ax.legend() #plt.show() #print('ax.azim {}'.format(ax.azim)) #print('ax.elev {}'.format(ax.elev)) return fig