label='Sphere parameter') fig = ax.get_figure() fig.set_size_inches([10, 5]) ax.set_xlim([0, 1]) ax.set_xlabel('Parameter value') ax.set_ylabel('# voxels') ax.legend() fig.savefig( '/Users/arokem/Dropbox/DWI_figures/MultiCanonicalTensor_params_%s.png' % b) idx = np.logical_and(to_hist1 < 1, to_hist2 < 1) T1 = ni.load(data_path + 'FP_t1_resampled_to_dwi.nii.gz').get_data() fig = viz.mosaic(T1.T, cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(Model1.model_params[:, :, :, 1].T, fig=fig, cmap=matplotlib.cm.hot, vmax=1) fig.set_size_inches([12, 8]) fig.savefig( '/Users/arokem/Dropbox/DWI_figures/MultiCanonicalTensor_tensor_param%s.png' % b) fig = viz.mosaic(T1.T, cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(Model1.model_params[:, :, :, 2].T, fig=fig, cmap=matplotlib.cm.hot, vmax=1) fig.set_size_inches([12, 8])
# Set the background to black: t1_d[~np.isfinite(t1_d)] = 0 fig_hist_rmse, ax_hist_rmse = plt.subplots(1) fig_hist_snr, ax_hist_snr = plt.subplots(1) for bval_idx, bval in enumerate([1000, 2000, 4000]): snr_file_name = "%ssnr_b%s.nii.gz" % (data_path, bval) rmse_file_name = "%ssignal_rmse_b%s.nii.gz" % (data_path, bval) signal_rmse = ni.load(rmse_file_name).get_data() snr = ni.load(snr_file_name).get_data() vol = ozu.nans(signal_rmse.shape) vol[mask_idx] = signal_rmse[mask_idx] fig = viz.mosaic(t1_d.T[23:-12], cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(vol.T[23:-12], fig=fig, cmap=matplotlib.cm.hot) fig.set_size_inches([15, 10]) fig.savefig("%ssignal_rmse_b%s.png" % (figure_path, bval)) vol = ozu.nans(snr.shape) vol[mask_idx] = snr[mask_idx] fig = viz.mosaic(t1_d.T[23:-12], cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(vol.T[23:-12], fig=fig, cmap=matplotlib.cm.hot) fig.set_size_inches([15, 10]) fig.savefig("%ssignal_snr_b%s.png" % (figure_path, bval)) rmse_mask = signal_rmse[mask_idx] fig_hist_rmse = viz.probability_hist( rmse_mask[np.isfinite(rmse_mask)], bins=100, fig=fig_hist_rmse, label="b=%s" % bval )
# Set the background to black: t1_d[~np.isfinite(t1_d)] = 0 fig_hist_rmse, ax_hist_rmse = plt.subplots(1) fig_hist_snr, ax_hist_snr = plt.subplots(1) for bval_idx, bval in enumerate([1000, 2000, 4000]): snr_file_name = '%ssnr_b%s.nii.gz' % (data_path, bval) rmse_file_name = '%ssignal_rmse_b%s.nii.gz' % (data_path, bval) signal_rmse = ni.load(rmse_file_name).get_data() snr = ni.load(snr_file_name).get_data() vol = ozu.nans(signal_rmse.shape) vol[mask_idx] = signal_rmse[mask_idx] fig = viz.mosaic(t1_d.T[23:-12], cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(vol.T[23:-12], fig=fig, cmap=matplotlib.cm.hot) fig.set_size_inches([15, 10]) fig.savefig('%ssignal_rmse_b%s.png' % (figure_path, bval)) vol = ozu.nans(snr.shape) vol[mask_idx] = snr[mask_idx] fig = viz.mosaic(t1_d.T[23:-12], cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(vol.T[23:-12], fig=fig, cmap=matplotlib.cm.hot) fig.set_size_inches([15, 10]) fig.savefig('%ssignal_snr_b%s.png' % (figure_path, bval)) rmse_mask = signal_rmse[mask_idx] fig_hist_rmse = viz.probability_hist(rmse_mask[np.isfinite(rmse_mask)], bins=100, fig=fig_hist_rmse,
for b_idx, file_root in enumerate(file_roots): vol = np.ones((81,106,76,4)) * np.nan for chunk in range(n_chunks): if vox_per_chunk*chunk+1 > brain_idx.shape[-1]: this_idx = brain_idx[:,vox_per_chunk * chunk:] else: this_idx = brain_idx[:,vox_per_chunk * chunk:vox_per_chunk*(chunk+1)] mask_array = np.zeros((81, 106, 76)) mask_array[(this_idx[0], this_idx[1], this_idx[2])] = 1 params_file = '/home/arokem/data/ModelFits/MultiCanonicalTensor2/MultiCanonicalTensorb%s_%03d.nii.gz'%(all_bvals[b_idx], chunk+1) this_params = ni.load(params_file).get_data() mask_idx = np.where(mask_array) vol[mask_idx] = this_params[mask_idx] fig = viz.mosaic(vol[:,:,:,-1]) fig.set_size_inches([20,18]) ni.Nifti1Image(vol, ni.load(params_file).get_affine()).to_filename( '/home/arokem/data/ModelFits/MultiCanonicalTensor/MultiCanonicalTensorCombinedb%s.nii.gz'%all_bvals[b_idx])
# Force a save of the params to file: Model.model_params for b_idx, file_root in enumerate(file_roots): vol = np.ones((81, 106, 76, 4)) * np.nan for chunk in range(n_chunks): if vox_per_chunk * chunk + 1 > brain_idx.shape[-1]: this_idx = brain_idx[:, vox_per_chunk * chunk:] else: this_idx = brain_idx[:, vox_per_chunk * chunk:vox_per_chunk * (chunk + 1)] mask_array = np.zeros((81, 106, 76)) mask_array[(this_idx[0], this_idx[1], this_idx[2])] = 1 params_file = '/home/arokem/data/ModelFits/MultiCanonicalTensor2/MultiCanonicalTensorb%s_%03d.nii.gz' % ( all_bvals[b_idx], chunk + 1) this_params = ni.load(params_file).get_data() mask_idx = np.where(mask_array) vol[mask_idx] = this_params[mask_idx] fig = viz.mosaic(vol[:, :, :, -1]) fig.set_size_inches([20, 18]) ni.Nifti1Image( vol, ni.load(params_file).get_affine() ).to_filename( '/home/arokem/data/ModelFits/MultiCanonicalTensor/MultiCanonicalTensorCombinedb%s.nii.gz' % all_bvals[b_idx])
# equivalent TensorModel, using the # method outlined in Stikov et al. 2011): # Add [0,1] to force the axes to be [0,1] fig = viz.scatter_density(np.hstack([to_hist1[idx],[0,1]]), np.hstack([TM1.fiber_volume_fraction[Model1.mask][idx], [0,1]])) fig.axes[0].set_xlabel('Tensor parameter') fig.axes[0].set_ylabel('FVF') fig.set_size_inches([10,10]) fig.axes[0].plot([100,0],[0,100],'--k') fig.savefig('/home/arokem/Dropbox/DWI_figures/CanonicalTensor_fvf%s.png'%b) T1 = ni.load(data_path + 'FP_t1_resampled_to_dwi.nii.gz').get_data() fig = viz.mosaic(T1.T, cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(Model1.model_params[:,:,:,1].T, fig=fig, cmap=matplotlib.cm.hot, vmax=1) fig.set_size_inches([12,8]) fig.savefig('/home/arokem/Dropbox/DWI_figures/CanonicalTensor_tensor_param%s.png'%b) fig = viz.mosaic(T1.T, cmap=matplotlib.cm.bone, cbar=False) fig = viz.mosaic(Model1.model_params[:,:,:,2].T, fig=fig, cmap=matplotlib.cm.hot, vmax=1) fig.set_size_inches([12,8]) fig.savefig('/home/arokem/Dropbox/DWI_figures/CanonicalTensor_sphere_param%s.png'%b) fractional_anisotropy = (