def plot_distrbution_of_values(main_file, mask_file, xlabel, distribution=None, xlabel2=None, figsize=(11.7, 8.3)): data = _get_values_inside_a_mask(main_file, mask_file) fig = Figure(figsize=figsize) FigureCanvas(fig) gs = GridSpec(2, 1) ax = fig.add_subplot(gs[0, 0]) sns.distplot( np.array(data, dtype=np.double), kde=False, bins=100, ax=ax ) #sns.distplot(data.astype(np.double), kde=False, bins=100, ax=ax) ax.set_xlabel(xlabel) ax = fig.add_subplot(gs[1, 0]) sns.distplot(np.array(distribution, dtype=np.double), ax=ax) #sns.distplot(np.array(distribution).astype(np.double), ax=ax) cur_val = np.median(data) label = "%g" % cur_val plot_vline(cur_val, label, ax=ax) ax.set_xlabel(xlabel2) return fig
def plot_distrbution_of_values(main_file, mask_file, xlabel, distribution=None, xlabel2=None, figsize=(11.7,8.3)): data = _get_values_inside_a_mask(main_file, mask_file) fig = Figure(figsize=figsize) FigureCanvas(fig) gs = GridSpec(2, 1) ax = fig.add_subplot(gs[0, 0]) sns.distplot(data.astype(np.double), kde=False, bins=100, ax=ax) ax.set_xlabel(xlabel) ax = fig.add_subplot(gs[1, 0]) sns.distplot(np.array(distribution).astype(np.double), ax=ax) cur_val = np.median(data) label = "%g"%cur_val plot_vline(cur_val, label, ax=ax) ax.set_xlabel(xlabel2) return fig
def plot_frame_displacement(realignment_parameters_file, parameter_source, mean_FD_distribution=None, figsize=(11.7, 8.3)): FD_power = calc_frame_dispalcement(realignment_parameters_file, parameter_source) fig = Figure(figsize=figsize) FigureCanvas(fig) if mean_FD_distribution: grid = GridSpec(2, 4) else: grid = GridSpec(1, 4) ax = fig.add_subplot(grid[0, :-1]) ax.plot(FD_power) ax.set_xlim((0, len(FD_power))) ax.set_ylabel("Frame Displacement [mm]") ax.set_xlabel("Frame number") ylim = ax.get_ylim() ax = fig.add_subplot(grid[0, -1]) sns.distplot(FD_power, vertical=True, ax=ax) ax.set_ylim(ylim) if mean_FD_distribution: ax = fig.add_subplot(grid[1, :]) sns.distplot(mean_FD_distribution, ax=ax) ax.set_xlabel("Mean Frame Displacement (over all subjects) [mm]") MeanFD = FD_power.mean() label = "MeanFD = %g" % MeanFD plot_vline(MeanFD, label, ax=ax) fig.suptitle('motion', fontsize='14') return fig
def plot_epi_T1_corregistration( mean_epi_file, wm_file, reg_file, fssubjects_dir, subject_id, similarity_distribution=None, figsize=(11.7, 8.3), ): fig = plt.figure(figsize=figsize) if similarity_distribution: ax = plt.subplot(2, 1, 2) sns.distplot(similarity_distribution.values(), ax=ax) ax.set_xlabel( "EPI-T1 similarity after coregistration (over all subjects)") cur_similarity = similarity_distribution[subject_id] label = "similarity = %g" % cur_similarity plot_vline(cur_similarity, label, ax=ax) ax = plt.subplot(2, 1, 1) #changed from (2,1,0) to (2,1,1) else: ax = plt.subplot(1, 1, 1) res = ApplyVolTransform(source_file=mean_epi_file, reg_file=reg_file, fs_target=True, subjects_dir=fssubjects_dir, terminal_output="none").run() func = nb.load(res.outputs.transformed_file).get_data() func_affine = nb.load(res.outputs.transformed_file).get_affine() # ribbon_file = "%s/%s/mri/ribbon.mgz"%(fssubjects_dir, subject_id) # ribbon_nii = nb.load(ribbon_file) # ribbon_data = ribbon_nii.get_data() # ribbon_data[ribbon_data > 1] = 1 # ribbon_affine = ribbon_nii.get_affine() wm_nii = nb.load(wm_file) wm_data = wm_nii.get_data() wm_data[wm_data > 1] = 1 wm_affine = wm_nii.get_affine() slicer = viz.plot_anat( np.asarray(func), np.asarray(func_affine), black_bg=True, cmap=cm.Greys_r, # @UndefinedVariable figure=fig, axes=ax, draw_cross=False) slicer.contour_map(np.asarray(wm_data), np.asarray(wm_affine), linewidths=[0.1], colors=[ 'r', ]) fig.suptitle('coregistration', fontsize='14') return fig plt.show(fig)