import osmosis
osmosis.__file__
'/home/arokem/usr/local/lib/python2.7/site-packages/osmosis/__init__.pyc'
import osmosis.io as oio
import osmosis.model.isotropic as mdm
import nibabel as nib
import os
%matplotlib inline
subject_id = "103414"
data_path = "/biac4/wandell/data/klchan13/hcp_data_q3/%s/T1w/Diffusion/"%subject_id
data_file = nib.load(os.path.join(data_path, "data.nii.gz"))
data = data_file.get_data()
wm_data_file = nib.load(os.path.join(data_path,"wm_mask_no_vent.nii.gz"))
wm_data = wm_data_file.get_data()
bvals = np.loadtxt(os.path.join(data_path, "bvals"))
bvecs = np.loadtxt(os.path.join(data_path, "bvecs"))
Create a white matter mask using the ribbon file from freesurfer.
def wm_mask(ribbon_file, data_path, file_name=False):
"""
Takes a ribbon file and creates a white matter mask.
"""
ribbon_data = ribbon_file.get_data()
ribbon_affine = ribbon_file.get_affine()
wm_mask_out = np.zeros(ribbon_data.shape)
# These are labels that should be included in the white matter mask.
labels = [2, 41, 16, 17, 28, 60, 51, 53, 12, 52, 13, 18, 54, 50, 11, 251, 252, 253, 254, 255, 10, 49, 46, 7]
for label in labels:
wm_mask_out[np.where(ribbon_data == label)] = 1
nii = nib.Nifti1Image(wm_mask_out, ribbon_affine)
if file_name:
nii.to_filename(os.path.join(data_path, file_name))
return wm_mask_out
Extract a white matter mask from all the brains
sid_list = ["103414", "105115", "110411", "111312", "113619",
"115320", "117122", "118730", "118932", "110411"]
for sid in sid_list:
data_path1 = "/biac4/wandell/data/klchan13/hcp_data_q3/%s/T1w/Diffusion/"%sid
ribbon_file = nib.load(os.path.join(data_path1, "wm_mask.nii.gz"))
wm_mask_out = wm_mask(ribbon_file, data_path1, file_name="wm_mask_no_vent.nii.gz")
wm_mask_no_vent = oio.rm_ventricles(wm_data_file, bvals, bvecs, data, data_path)
SSH to proclus and navigate to the file directory with all the file pieces. Open up ipython and load all the data as well as the io module then enter the following. The COD file pieces are used as an example.
file_names = ["sfm_cod_multi_se", "sfm_cod_multi_be"]
missing_files, vol_list = place_files(file_names, 2000, 65, wm_data, data, bvals)