diff --git a/code/utils/scripts/mask_filtered_data.py b/code/utils/scripts/mask_filtered_data.py index 672cca6..16d8f0d 100644 --- a/code/utils/scripts/mask_filtered_data.py +++ b/code/utils/scripts/mask_filtered_data.py @@ -43,28 +43,15 @@ def make_mask_filtered_data(func_path, mask_path): # nib.save(masked_func, 'masked_' + img_name ) return masked_func -def resample_filtered_data(func_path, template_path): - """Resample template to filtered functional dataset - - Parameters - ---------- - func_path: string - path of the 4D filtered data to resample - template_path: string - path to the template to apply on the data - - """ - filtered_func = nib.load(func_path) - filtered_shape = filtered_func.shape[:3] - template_img = nib.load(mni_fname) - template_data = template_img.get_data() - vox2vox = npl.inv(template_img.affine).dot(filtered_func.affine) - M, trans = nib.affines.to_matvec(vox2vox) - resampled = affine_transform(template_data, M, trans, - output_shape=filtered_shape) - froot, ext = splitext(mni_fname) - new_name = froot + '_2mm' + ext - new_img = nib.Nifti1Image(resampled, filtered_func.affine, - template_img.header) - #nib.save(new_img, new_name) - return new_img +if __name__=='__main__': + project_path='../../../' + func_path = \ + project_path+\ + 'data/ds005/sub001/model/model001/task001_run001.feat/filtered_func_data_mni.nii.gz' + img = nib.load(func_path) + mask_path = project_path+'data/mni_icbm152_t1_tal_nlin_asym_09c_mask_2mm.nii' + masked_data = make_mask_filtered_data(func_path, mask_path) + new_data_path = project_path+\ + 'data/ds005/sub001/model/model001/task001_run001.feat/masked_filtered_func_data_mni.nii.gz' + nib.save(masked_data, new_data_path) + #pdb.set_trace() diff --git a/code/utils/scripts/noise-pca_script.py b/code/utils/scripts/noise-pca_script.py index 9ec1bb2..30d6ba6 100644 --- a/code/utils/scripts/noise-pca_script.py +++ b/code/utils/scripts/noise-pca_script.py @@ -41,10 +41,10 @@ # TODO: uncomment for final version #subject_list = [str(i) for i in range(1,17)] #run_list = [str(i) for i in range(1,4)] -run_list = [str(i) for i in range(1,3)] +run_list = [str(i) for i in range(1,2)] subject_list = ['1'] -d = path_dict['data_original'] #OR path_dict['data_filtered'] +d = path_dict['data_filtered'] #OR path_dict['data_filtered'] images_paths = [('ds005' + d['type'] +'_sub' + s.zfill(3) + '_t1r' + r, \ data_path + 'sub%s/'%(s.zfill(3)) + d['run_path'] \ diff --git a/code/utils/scripts/plot_mosaic.py b/code/utils/scripts/plot_mosaic.py index 4214f9f..d579fb8 100644 --- a/code/utils/scripts/plot_mosaic.py +++ b/code/utils/scripts/plot_mosaic.py @@ -6,7 +6,7 @@ import numpy as np import nibabel as nib -def plot_mosaic(img_data): +def plot_mosaic(img_data, transpose=True): """ Return a mosaic plot for each slice of the 3rd dimension of img_data @@ -30,8 +30,12 @@ def plot_mosaic(img_data): for i in range(n_rows): for j in range(n_cols): if z < n_slices: + if transpose==True: + img_data_slice = img_data[:,::-1,z].T + else: + img_data_slice = img_data[:,::-1,z] grid_2D[i*img_data.shape[0]:(i+1)*img_data.shape[0],\ - j*img_data.shape[1]:(j+1)*img_data.shape[1]] = img_data[:,::-1,z].T + j*img_data.shape[1]:(j+1)*img_data.shape[1]] = img_data_slice z += 1 return grid_2D @@ -39,10 +43,19 @@ def plot_mosaic(img_data): import matplotlib.pyplot as plt plt.rcParams['image.cmap'] = 'gray' plt.rcParams['image.interpolation'] = 'nearest' - img = nib.load(\ - '../../../data/ds005/sub001/BOLD/task001_run001/bold.nii.gz') + project_path='../../../' + #img = nib.load(\ + #'../../../data/ds005/sub001/BOLD/task001_run001/bold.nii.gz') + template = nib.load(project_path+\ + 'data/mni_icbm152_t1_tal_nlin_asym_09c_2mm.nii') + template_data = template.get_data() + img = nib.load(project_path+\ + 'data/ds005/sub001/model/model001/task001_run001.feat/' + \ + 'masked_filtered_func_data_mni.nii.gz') img_data = img.get_data() mean_data = np.mean(img_data, axis=-1) - plt.imshow(plot_mosaic(mean_data), cmap='gray', alpha=1) + plt.title('In brain voxels - mean values') + plt.imshow(plot_mosaic(template_data, transpose=False), cmap='gray', alpha=1) + plt.imshow(plot_mosaic(mean_data, transpose=False), cmap='gray', alpha=1) plt.colorbar() plt.show() diff --git a/data/mni_icbm152_t1_tal_nlin_asym_09c_mask_2mm.nii b/data/mni_icbm152_t1_tal_nlin_asym_09c_mask_2mm.nii new file mode 100644 index 0000000..feebeb4 Binary files /dev/null and b/data/mni_icbm152_t1_tal_nlin_asym_09c_mask_2mm.nii differ