#import numpy as np import matplotlib.pyplot as plt import nibabel as nib import smooth_gaussian #possibly put in os function to specify path later #this file was more of a test, but since can easily adapt it into a more useful #script i left it in utils img = nib.load("../../data/ds005/sub001/BOLD/task001_run001/bold.nii.gz") data = img.get_data() #just plot a random slice to see if works spatial2 = smooth_gaussian.smooth_spatial(data, fwhm = 5)[:, :, 16, 50] spatial3 = smooth_gaussian.smooth_spatial(data,fwhm = 4)[:, :, 16, 50] spatial4 = smooth_gaussian.smooth_spatial(data,fwhm = 3)[:, :, 16, 50] f, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex = True, sharey = True) ax1.imshow(data[:, :, 16, 50], cmap = 'gray') ax1.set_title('Original') ax2.imshow(spatial2, cmap = 'gray') ax2.set_title('fwhm = 5 mm') ax3.imshow(spatial3, cmap = 'gray') ax3.set_title('fwhm = 4 mm') ax4.imshow(spatial4, cmap = 'gray') ax4.set_title('fwhm = 3mm')
import nibabel as nib import matplotlib.pyplot as plt import numpy as np import sys sys.path.append('../utils/functions') import smooth_gaussian import os os.chdir("../../data") plot_number = 1 fig = plt.figure(figsize = (50, 70)) for subject in range(1, 17): for run in range(1, 4): path = 'ds005/sub0' + str(subject).zfill(2) + '/BOLD/task001_run00' + str(run) + '/bold.nii.gz' img = nib.load(path) data = img.get_data() data = smooth_gaussian.smooth_spatial(data) mean_data = np.mean(data, axis = -1) axis = fig.add_subplot(16, 3, plot_number ) axis.hist(np.ravel(mean_data), bins = 100) axis.set_title('Subject ' + str(subject) + ', Run ' + str(run)) plot_number += 1 #fig.tight_layout() fig.savefig('../paper/figures/mean_hists.png')
#import numpy as np import matplotlib.pyplot as plt import nibabel as nib import smooth_gaussian #possibly put in os function to specify path later #this file was more of a test, but since can easily adapt it into a more useful #script i left it in utils img = nib.load("../../data/ds005/sub001/BOLD/task001_run001/bold.nii.gz") data = img.get_data() #just plot a random slice to see if works spatial2 = smooth_gaussian.smooth_spatial(data, fwhm=5)[:, :, 16, 50] spatial3 = smooth_gaussian.smooth_spatial(data, fwhm=4)[:, :, 16, 50] spatial4 = smooth_gaussian.smooth_spatial(data, fwhm=3)[:, :, 16, 50] f, (ax1, ax2, ax3, ax4) = plt.subplots(4, sharex=True, sharey=True) ax1.imshow(data[:, :, 16, 50], cmap='gray') ax1.set_title('Original') ax2.imshow(spatial2, cmap='gray') ax2.set_title('fwhm = 5 mm') ax3.imshow(spatial3, cmap='gray') ax3.set_title('fwhm = 4 mm') ax4.imshow(spatial4, cmap='gray') ax4.set_title('fwhm = 3mm') plt.savefig("smoothed_images.png") plt.close()
import nibabel as nib import matplotlib.pyplot as plt import numpy as np import sys sys.path.append('../utils') import smooth_gaussian import os os.chdir("../../data") plot_number = 1 fig = plt.figure(figsize = (50, 70)) for subject in range(1, 17): for run in range(1, 4): path = 'ds005/sub0' + str(subject).zfill(2) + '/BOLD/task001_run00' + str(run) + '/bold.nii.gz' img = nib.load(path) data = img.get_data() data = smooth_gaussian.smooth_spatial(data) mean_data = np.mean(data, axis = -1) axis = fig.add_subplot(16, 3, plot_number ) axis.hist(np.ravel(mean_data), bins = 100) axis.set_title('Subject ' + str(subject) + ', Run ' + str(run)) plot_number += 1 #fig.tight_layout() fig.savefig('../code/scripts/mean_hists.png')
fd_out = json.load(open("../results/texts/fdOutliers.txt")) # Threshold cutoff from histogram observation threshold = 7500 for i in range(1,17): # first three dimension for data shape is 91, 109, 91. # create array to store the combined dataset of three runs data_full = np.empty([91, 109, 91, 0]) gain_full = np.empty([0,]) loss_full = np.empty([0,]) for j in range(1,4): boldname='ds005/sub0'+str(i).zfill(2)+'/model/model001/task001_run00'+`j`+'.feat/filtered_func_data_mni.nii.gz' img=nib.load(boldname) data=img.get_data() data=smooth_spatial(data) run = j behav_cond = 'ds005/sub0'+str(i).zfill(2)+'/behav/task001_run00'+`j`+'/behavdata.txt' task_cond1 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond001.txt' task_cond2 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond002.txt' task_cond3 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond003.txt' task_cond4 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond004.txt' parameters = merge_cond(behav_cond, task_cond1, task_cond2, task_cond3, task_cond4) neural_prediction = events2neural_extend(parameters,TR, n_vols) gain, loss, linear_dr, quad_dr = getRegressor(TR, n_vols, hrf_at_trs, neural_prediction, standard = True) data, gain, loss, linear_dr, quad_dr = deleteOutliers(data, gain, loss, i, run, dvars_out, fd_out) data_full = np.concatenate((data_full,data),axis=3) gain_full = np.concatenate((gain_full,gain),axis=0) loss_full = np.concatenate((loss_full,loss),axis=0) # mea=calcMRSS(data_full, gain_full, loss_full, None, None, threshold) X, Y, beta=calcBeta(data_full, gain_full, loss_full, None, None, threshold)
threshold = 400 for i in range(1,17): # first three dimension for data shape is 64, 64, 34. # create array to store the combined dataset of three runs data_full = np.empty([64, 64, 34, 0]) gain_full = np.empty([0,]) loss_full = np.empty([0,]) linear_full = np.empty([0,]) quad_full = np.empty([0,]) for j in range(1,4): direct='ds005/sub0'+str(i).zfill(2)+'/BOLD/task001_run00'+`j`+'/' boldname = direct+'bold.nii.gz' img=nib.load(boldname) data=img.get_data() data=smooth_spatial(data) run = j behav_cond = 'ds005/sub0'+str(i).zfill(2)+'/behav/task001_run00'+`j`+'/behavdata.txt' task_cond1 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond001.txt' task_cond2 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond002.txt' task_cond3 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond003.txt' task_cond4 = 'ds005/sub0'+str(i).zfill(2)+'/model/model001/onsets/task001_run00'+`j`+'/cond004.txt' parameters = merge_cond(behav_cond, task_cond1, task_cond2, task_cond3, task_cond4) neural_prediction = events2neural_extend(parameters,TR, n_vols) gain, loss, linear_dr, quad_dr = getRegressor(TR, n_vols, hrf_at_trs, neural_prediction) data, gain, loss, linear_dr, quad_dr = deleteOutliers(data, gain, loss, linear_dr, quad_dr, i, run, dvars_out, fd_out) data_full = np.concatenate((data_full,data),axis=3) gain_full = np.concatenate((gain_full,gain),axis=0) loss_full = np.concatenate((loss_full,loss),axis=0) linear_full = np.concatenate((linear_full,linear_dr),axis=0) quad_full = np.concatenate((quad_full,quad_dr),axis=0)