Skip to content

FIX: properly handle V4 .PAR files with diffusion info #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2016
Merged
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
10 changes: 9 additions & 1 deletion bin/parrec2nii
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def proc_file(infile, opts):

bvals, bvecs = pr_hdr.get_bvals_bvecs()
if not opts.keep_trace: # discard Philips DTI trace if present
if bvals is not None:
if bvecs is not None:
bad_mask = np.logical_and(bvals != 0, (bvecs == 0).all(axis=1))
if bad_mask.sum() > 0:
pl = 's' if bad_mask.sum() != 1 else ''
Expand Down Expand Up @@ -229,6 +229,14 @@ def proc_file(infile, opts):
if opts.bvs:
if bvals is None and bvecs is None:
verbose('No DTI volumes detected, bvals and bvecs not written')
elif bvecs is None:
verbose('DTI volumes detected, but no diffusion direction info was'
'found. Writing .bvals file only.')
with open(basefilename + '.bvals', 'w') as fid:
# np.savetxt could do this, but it's just a loop anyway
for val in bvals:
fid.write('%s ' % val)
fid.write('\n')
else:
verbose('Writing .bvals and .bvecs files')
# Transform bvecs with reorientation affine
Expand Down
4 changes: 3 additions & 1 deletion nibabel/parrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ def get_q_vectors(self):
acquisition.
"""
bvals, bvecs = self.get_bvals_bvecs()
if bvals is None and bvecs is None:
if bvals is None or bvecs is None:
return None
return bvecs * bvals[:, np.newaxis]

Expand All @@ -728,6 +728,8 @@ def get_bvals_bvecs(self):
# All bvals within volume should be the same
assert not np.any(np.diff(bvals, axis=0))
bvals = bvals[0]
if 'diffusion' not in self.image_defs.dtype.names:
return bvals, None
bvecs = self.image_defs['diffusion'][reorder].reshape(
(n_slices, n_vols, 3), order='F')
# All 3 values of bvecs should be same within volume
Expand Down
Loading