|
1 | 1 | import os.path as op |
2 | 2 | from shutil import copyfile |
3 | | -import warnings |
4 | | - |
5 | | -# Filter warnings that are visible whenever you import another package that |
6 | | -# was compiled against an older numpy than is installed. |
7 | | -warnings.filterwarnings("ignore", message="numpy.dtype size changed") |
8 | | -warnings.filterwarnings("ignore", message="numpy.ufunc size changed") |
9 | 3 |
|
10 | 4 |
|
11 | 5 | def run_dmriprep(dwi_file, bvec_file, bval_file, |
@@ -407,7 +401,8 @@ def num_outliers(scan, outliers): |
407 | 401 | return len([d for d in outliers if d['scan'] == scan]) |
408 | 402 |
|
409 | 403 | if 0 < threshold < 1: |
410 | | - threshold *= nib.load(dwi_file).shape[2] |
| 404 | + img = nib.load(dwi_file) |
| 405 | + threshold *= img.shape[img.header.get_n_slices()] |
411 | 406 |
|
412 | 407 | drop_scans = np.array([ |
413 | 408 | s for s in scans |
@@ -488,8 +483,19 @@ def drop_outliers_fn(in_file, in_bval, in_bvec, drop_scans): |
488 | 483 |
|
489 | 484 | img = nib.load(op.abspath(in_file)) |
490 | 485 | 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) |
| 486 | + img_data_thinned = np.delete(img_data, |
| 487 | + drop_scans, |
| 488 | + axis=3) |
| 489 | + if isinstance(img, nib.nifti1.Nifti1Image): |
| 490 | + img_thinned = nib.Nifti1Image(img_data_thinned.astype(np.float64), |
| 491 | + img.affine, |
| 492 | + header=img.header) |
| 493 | + elif isinstance(img, nib.nifti2.Nifti2Image): |
| 494 | + img_thinned = nib.Nifti2Image(img_data_thinned.astype(np.float64), |
| 495 | + img.affine, |
| 496 | + header=img.header) |
| 497 | + else: |
| 498 | + raise TypeError("in_file does not contain Nifti image datatype.") |
493 | 499 |
|
494 | 500 | out_file = fname_presuffix(in_file, suffix="_thinned", newpath=op.abspath('.')) |
495 | 501 | nib.save(img_thinned, op.abspath(out_file)) |
|
0 commit comments