def test_smooth(): # Read in the image data. img = nib.load(pathtoclassdata + "ds114_sub009_t2r1.nii") data = img.get_data()[..., 4:] # Run the smoothvoxels function with fwhm = 0 (No smoothing) at time 7 non_smoothed_data = smoothvoxels(data, 0, 7) # assert that data at time 7 and non_smoothed_data are equal since fwhm = 0 assert_almost_equal(data[..., 7], non_smoothed_data) # Run the smoothvoxels function with fwhm = 5 at time 7 smoothed_data = smoothvoxels(data, 5, 7) # assert that data at time 7 and smoothed_data are not equal assert_not_equals(data[..., 7].all(), smoothed_data.all())
# Load the image data for subject 1. img = nib.load(pathtodata+"BOLD/task001_run001/bold.nii.gz") data = img.get_data() data = data[...,6:] # Knock off the first 6 observations. ####################### # a. (my) smoothing # ####################### # Kind of arbitrary chosen time time = 7 original_slice = data[..., 7] # full width at half maximum (FWHM) fwhm = 1.5 smoothed_slice = smoothvoxels(data, fwhm, time) # visually compare original_slice to smoothed_slice plt.imshow(present_3d(smoothed_slice)) plt.colorbar() plt.title('Smoothed Slice') plt.clim(0,1600) plt.savefig(location_of_images+"smoothed_slice.png") plt.close() plt.imshow(present_3d(original_slice)) plt.colorbar() plt.title('Original Slice') plt.clim(0,1600) plt.savefig(location_of_images+"original_slice.png")
data = data[...,num_TR_cut:] ######################### # smoothing per slice # ######################### smoothed_data =np.zeros(data.shape) for time in np.arange(data.shape[-1]): # Kind of arbitrary chosen time sigma = 1.5 fwhm = (2*np.sqrt(2 *np.log(2))) * sigma smoothed_data[...,time]= smoothvoxels(data, sigma, time) smoothed_data img = nib.Nifti1Image(smoothed_data, affine) nib.save(img,os.path.join(final_data + "smooth/",str(name)+"_bold_smoothed.nii")) ### 266.3 MB for first one sys.stdout.write("-") sys.stdout.flush() sys.stdout.write("\n")
# Load the image data for subject 1. img = nib.load(pathtodata + "BOLD/task001_run001/bold.nii.gz") data = img.get_data() data = data[..., 6:] # Knock off the first 6 observations. ####################### # a. (my) smoothing # ####################### # Kind of arbitrary chosen time time = 7 original_slice = data[..., 7] # full width at half maximum (FWHM) fwhm = 1.5 smoothed_slice = smoothvoxels(data, fwhm, time) # visually compare original_slice to smoothed_slice plt.imshow(present_3d(smoothed_slice)) plt.colorbar() plt.title('Smoothed Slice') plt.clim(0, 1600) plt.savefig(location_of_images + "smoothed_slice.png") plt.close() plt.imshow(present_3d(original_slice)) plt.colorbar() plt.title('Original Slice') plt.clim(0, 1600) plt.savefig(location_of_images + "original_slice.png")
data = data[...,num_TR_cut:] ######################### # Smoothing per slice # ######################### smoothed_data = np.zeros(data.shape) for time in np.arange(data.shape[-1]): # Kind of arbitrary chosen time sigma = 1 smoothed_data[..., time] = smoothvoxels(data, sigma, time) smoothed_data img = nib.Nifti1Image(smoothed_data, affine) nib.save(img,os.path.join(final_data + "smooth/", str(name) + "_bold_smoothed.nii")) ### 266.3 MB for first one sys.stdout.write("-") sys.stdout.flush() sys.stdout.write("\n")