def plot_maps(plot_params, anat_fn, anat_slice_def, fig_dir, orientation=['axial','sagittal'], crop_extension=None, plot_anat=True, plot_fontsize=25, fig_dpi=75): ldata = [] for p in plot_params: c = xndarray.load(p['fn']).sub_cuboid(**p['slice_def']) c.set_orientation(orientation) ldata.append(c.data) c_anat = xndarray.load(anat_fn).sub_cuboid(**anat_slice_def) c_anat.set_orientation(orientation) resolution = c_anat.meta_data[1]['pixdim'][1:4] slice_resolution = resolution[MRI4Daxes.index(orientation[0])], \ resolution[MRI4Daxes.index(orientation[1])] all_data = np.array(ldata) if 'prl' in plot_params[0]['fn']: norm = normalize(all_data.min(), all_data.max()*1.05) print 'norm:', (all_data.min(), all_data.max()) else: norm = normalize(all_data.min(), all_data.max()) print 'norm:', (all_data.min(), all_data.max()) for data, plot_param in zip(all_data, plot_params): fn = plot_param['fn'] plt.figure() print 'fn:', fn print '->', (data.min(), data.max()) if plot_anat: anat_data = c_anat.data else: anat_data = None plot_func_slice(data, anatomy=anat_data, parcellation=plot_param.get('mask'), func_cmap=cmap, parcels_line_width=1., func_norm=norm, resolution=slice_resolution, crop_extension=crop_extension) set_ticks_fontsize(plot_fontsize) fig_fn = op.join(fig_dir, '%s.png' %op.splitext(op.basename(fn))[0]) output_fig_fn = plot_param.get('output_fig_fn', fig_fn) print 'Save to: %s' %output_fig_fn plt.savefig(output_fig_fn, dpi=fig_dpi) autocrop(output_fig_fn) return norm
def plot_estimation_results(fig_dir, poi, jde_roi, cond, plot_label, glm_fir_output_dir, rfir_output_dir, jde_output_dir, ymin=-1.55, ymax=1.05, plot_fontsize=25): ## HRF plots fn = op.join(glm_fir_output_dir, 'glm_fir_hrf.nii.gz') fir = xndarray.load(fn).sub_cuboid(condition=cond, **poi) #fir /= (fir**2).sum()**.5 fir /= fir.max() fn = op.join(rfir_output_dir, 'rfir_ehrf.nii.gz') rfir = xndarray.load(fn).sub_cuboid(condition=cond, **poi) #rfir /= (rfir**2).sum()**.5 rfir /= rfir.max() fn = op.join(jde_output_dir, 'jde_mcmc_hrf_pm.nii.gz') jde = xndarray.load(fn).sub_cuboid(ROI=jde_roi) jde /= jde.max() plt.figure() pargs = {'linewidth' : 2.7} plot_cub_as_curve(fir, show_axis_labels=False, plot_kwargs=pargs) plot_cub_as_curve(rfir, show_axis_labels=False, plot_kwargs=pargs) plot_cub_as_curve(jde, show_axis_labels=False, plot_kwargs=pargs) from pyhrf.boldsynth.hrf import getCanoHRF time_points, hcano = getCanoHRF() hcano /= hcano.max() plt.plot(time_points, hcano, 'k.-',linewidth=1.5) set_ticks_fontsize(plot_fontsize) plt.xlim(0,25) plt.ylim(ymin, ymax) plt.gca().xaxis.grid(True, 'major', linestyle='--', linewidth=1.2, color='gray') hrf_fig_fn = op.join(fig_dir, 'real_data_hrfs_%s.png' %plot_label) print 'hrf_fig_fn:', hrf_fig_fn plt.savefig(hrf_fig_fn) autocrop(hrf_fig_fn)