Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/buildTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def antsMult(caselist, outPrefix):
'-o', outPrefix,
caselist]), shell= True, stdout= f, stderr= sys.stdout)

if f.name!='<sys.stdout>':
if f is not sys.stdout:
f.close()

def dti_stat(siteName, imgs, masks, templatePath, templateHdr):
Expand Down
2 changes: 1 addition & 1 deletion lib/consistencyCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def check_resolution(ref_imgs, ref_res):

res= load(imgPath._path).header['pixdim'][1:4]

if (res-ref_res).sum()<=10e-6:
if (res-ref_res).sum()<=0.001:
print('spatial resolution matched for', imgPath.name)

else:
Expand Down
9 changes: 6 additions & 3 deletions lib/joinBshells.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from plumbum import cli, local
from conversion import read_bvals, read_imgs, read_imgs_masks
from nibabel import load
from util import abspath, pjoin, save_nifti, copyfile, RAISE, basename, dirname, isfile
from util import abspath, pjoin, save_nifti, copyfile, basename, dirname, isfile
import numpy as np
from multiprocessing import Pool
from findBshells import BSHELL_MIN_DIST
Expand Down Expand Up @@ -86,13 +86,16 @@ def joinAllBshells(tar_csv, ref_bvals_file, separatedPrefix=None, ncpu=4):
imgs = read_imgs(tar_csv)

pool = Pool(int(ncpu))
results = []
for imgPath in imgs:
pool.apply_async(joinBshells, kwds=({'imgPath': imgPath, 'ref_bvals': ref_bvals, 'sep_prefix': separatedPrefix}),
error_callback=RAISE)
results.append(pool.apply_async(joinBshells, kwds=({'imgPath': imgPath, 'ref_bvals': ref_bvals, 'sep_prefix': separatedPrefix})))

pool.close()
pool.join()

for r in results:
r.get()



class joinDividedShells(cli.Application):
Expand Down
2 changes: 1 addition & 1 deletion lib/reconstSignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def antsReg(img, mask, mov, outPrefix):
'-e', '123456']), shell= True, stdout= f, stderr= sys.stdout)
p.wait()

if f.name!='<sys.stdout>':
if f is not sys.stdout:
f.close()


Expand Down
33 changes: 23 additions & 10 deletions lib/separateBshells.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from plumbum import cli, local
from conversion import read_bvals, read_bvecs, write_bvals, write_bvecs, read_imgs, read_imgs_masks
from nibabel import load
from util import abspath, pjoin, save_nifti, RAISE, isfile
from util import abspath, pjoin, save_nifti, isfile
import numpy as np
from multiprocessing import Pool
from findBshells import BSHELL_MIN_DIST
Expand Down Expand Up @@ -51,13 +51,19 @@ def separateBshells(imgPath, ref_bvals_file=None, ref_bvals=None):
if bval==0.:
b0 = find_b0(dwi, ind)

if isfile(bPrefix + '.nii.gz'):
continue

nii_file = bPrefix + '.nii.gz'
bval_file = bPrefix + '.bval'
bvec_file = bPrefix + '.bvec'

if bval==0.:
save_nifti(bPrefix + '.nii.gz', b0, img.affine, img.header)
if isfile(nii_file):
continue
save_nifti(nii_file, b0, img.affine, img.header)

else:
if isfile(nii_file) and isfile(bval_file) and isfile(bvec_file):
continue

b0_bshell = np.zeros((dwi.shape[0],dwi.shape[1],dwi.shape[2],N_b+1), dtype='float32')
b0_bshell[:,:,:,0]= b0
b0_bshell[:,:,:,1:]= dwi[:,:,:,ind]
Expand All @@ -67,9 +73,12 @@ def separateBshells(imgPath, ref_bvals_file=None, ref_bvals=None):
b0_bvecs= np.zeros((N_b+1,3), dtype='float32')
b0_bvecs[1:,]= bvecs[ind,: ]

save_nifti(bPrefix+'.nii.gz', b0_bshell, img.affine, img.header)
write_bvals(bPrefix+'.bval', b0_bvals)
write_bvecs(bPrefix+'.bvec', b0_bvecs)
if not isfile(nii_file):
save_nifti(nii_file, b0_bshell, img.affine, img.header)
if not isfile(bval_file):
write_bvals(bval_file, b0_bvals)
if not isfile(bvec_file):
write_bvecs(bvec_file, b0_bvecs)



Expand All @@ -84,13 +93,17 @@ def separateAllBshells(ref_csv, ref_bvals_file, ncpu=4, outPrefix= None):
masks = None

pool = Pool(int(ncpu))
results = []
for imgPath in imgs:
pool.apply_async(separateBshells,
kwds={'imgPath': imgPath, 'ref_bvals': ref_bvals}, error_callback=RAISE)
results.append(pool.apply_async(separateBshells,
kwds={'imgPath': imgPath, 'ref_bvals': ref_bvals}))

pool.close()
pool.join()

for r in results:
r.get()


if outPrefix:
outPrefix = abspath(outPrefix)
Expand Down
10 changes: 7 additions & 3 deletions lib/tests/shellEquate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from plumbum import cli, local
from conversion import read_bvals, read_bvecs, write_bvals, write_bvecs, read_imgs, read_imgs_masks
from nibabel import load
from util import abspath, pjoin, save_nifti, RAISE, isfile
from util import abspath, pjoin, save_nifti, isfile
import numpy as np
from multiprocessing import Pool
from findBshells import BSHELL_MIN_DIST
Expand Down Expand Up @@ -83,12 +83,16 @@ def separateAllBshells(ref_csv, ref_bvals_file, ncpu=4, outPrefix= None):
masks = None

pool = Pool(int(ncpu))
results = []
for imgPath in imgs:
pool.apply_async(separateBshells,
kwds={'imgPath': imgPath, 'ref_bvals': ref_bvals}, error_callback=RAISE)
results.append(pool.apply_async(separateBshells,
kwds={'imgPath': imgPath, 'ref_bvals': ref_bvals}))

pool.close()
pool.join()

for r in results:
r.get()


if outPrefix:
Expand Down