Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 2afab2c

Browse files
authored
Merge pull request #43 from richford/diminfo
Preserve dim info and use `get_n_slices` to resolve orientation uncertainty
2 parents 4f9c93b + 1ac5307 commit 2afab2c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

dmriprep/run.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def num_outliers(scan, outliers):
407407
return len([d for d in outliers if d['scan'] == scan])
408408

409409
if 0 < threshold < 1:
410-
threshold *= nib.load(dwi_file).shape[2]
410+
img = nib.load(dwi_file)
411+
threshold *= img.shape[img.header.get_n_slices()]
411412

412413
drop_scans = np.array([
413414
s for s in scans
@@ -488,8 +489,19 @@ def drop_outliers_fn(in_file, in_bval, in_bvec, drop_scans):
488489

489490
img = nib.load(op.abspath(in_file))
490491
img_data = img.get_fdata()
491-
img_data_thinned = np.delete(img_data, drop_scans, axis=3)
492-
img_thinned = nib.Nifti1Image(img_data_thinned.astype(np.float64), img.affine, header=img.header)
492+
img_data_thinned = np.delete(img_data,
493+
drop_scans,
494+
axis=3)
495+
if isinstance(img, nib.nifti1.Nifti1Image):
496+
img_thinned = nib.Nifti1Image(img_data_thinned.astype(np.float64),
497+
img.affine,
498+
header=img.header)
499+
elif isinstance(img, nib.nifti2.Nifti2Image):
500+
img_thinned = nib.Nifti2Image(img_data_thinned.astype(np.float64),
501+
img.affine,
502+
header=img.header)
503+
else:
504+
raise TypeError("in_file does not contain Nifti image datatype.")
493505

494506
out_file = fname_presuffix(in_file, suffix="_thinned", newpath=op.abspath('.'))
495507
nib.save(img_thinned, op.abspath(out_file))

0 commit comments

Comments
 (0)