Skip to content

Commit

Permalink
Merge pull request #253 from soazig/soazig-Tests
Browse files Browse the repository at this point in the history
Updating Test branch with noise-pca, plot function, mask
  • Loading branch information
soazig committed Dec 14, 2015
2 parents 9959b7e + ecaf3af commit e9fc920
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
37 changes: 12 additions & 25 deletions code/utils/scripts/mask_filtered_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions code/utils/scripts/noise-pca_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] \
Expand Down
23 changes: 18 additions & 5 deletions code/utils/scripts/plot_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,19 +30,32 @@ 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

if __name__=='__main__':
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()
Binary file not shown.

0 comments on commit e9fc920

Please sign in to comment.