From 7e4122572d9998ca2842d33f18ec30e9e90c330c Mon Sep 17 00:00:00 2001 From: Felix Liu Date: Thu, 22 Jul 2021 11:07:58 -0700 Subject: [PATCH 1/2] Return 3 vars from load_nifti instead of tuple load_nifti returns a tuple and the rest of the code uses the 3rd value which is the nibabel nifti img object. Subsequent calls for the object methods fail. It is probably okay to change to ignore the nibabel object and instead use the data, affine, and other outputs from load_nifti directly, except for gpu_tracker.dump_streamlines uses img.header.get_zooms() which returns a 4-length tuple while load_nifti with return_voxsize=True would return a 3-length tuple; not sure of any implications to .dump_streamlines. --- run_dipy_gpu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run_dipy_gpu.py b/run_dipy_gpu.py index ca51cba..ae5473d 100644 --- a/run_dipy_gpu.py +++ b/run_dipy_gpu.py @@ -85,10 +85,10 @@ help="default: 0.5") args = parser.parse_args() -img = load_nifti(args.nifti_file, return_img=True) +img_data, img_affine, img = load_nifti(args.nifti_file, return_img=True) voxel_order = "".join(aff2axcodes(img.affine)) gtab = gradient_table(args.bvals, args.bvecs) -mask = load_nifti(args.mask_nifti, return_img=True) +mask_data, mask_affine, mask = load_nifti(args.mask_nifti, return_img=True) data = img.get_fdata() # resample mask if necessary @@ -122,7 +122,7 @@ # resample roi if necessary if args.roi_nifti is not None: - roi_data, roi = load_nifti(args.roi_nifti, + roi_data, roi_affine, roi = load_nifti(args.roi_nifti, return_img=True, as_ndarray=True) else: From 800ffd709029ddf13d97c9078b9d0a6bed8bb0e5 Mon Sep 17 00:00:00 2001 From: Felix Liu Date: Thu, 29 Jul 2021 11:39:04 -0700 Subject: [PATCH 2/2] Fix argument fa_file and add nifti loading for FA Fix issue when expecting old argument variable fa_numpy. Changed references to fa_file instead and add check for numpy or nifti loading. --- run_dipy_gpu.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/run_dipy_gpu.py b/run_dipy_gpu.py index ae5473d..b417bd9 100644 --- a/run_dipy_gpu.py +++ b/run_dipy_gpu.py @@ -103,8 +103,14 @@ mask = mask.get_fdata() # load or compute and save FA file -if (args.fa_numpy is not None) and os.path.isfile(args.fa_numpy): - FA = np.load(args.fa_numpy, allow_pickle=True) +if (args.fa_file is not None) and os.path.isfile(args.fa_file): + _, fa_extension = os.path.splitext(filename) + if fa_extension in ['.npy', '.npz', '.pkl']: + FA = np.load(args.fa_file, allow_pickle=True) + elif fa_extension in ['.nii','.gz']: + FA, FA_affine = load_nifti(args.fa_file) + else: + raise TypeError('FA filename is not one of the supported format (.npy, .npz, .pkl, .nii, .gz).') else: # Fit tenmodel = dti.TensorModel(gtab, fit_method='WLS') @@ -114,8 +120,8 @@ FA = tenfit.fa FA[np.isnan(FA)] = 0 - if args.fa_numpy is not None: - np.save(args.fa_numpy, FA) + if args.fa_file is not None: + np.save(args.fa_file, FA) # Setup tissue_classifier args metric_map = np.asarray(FA, 'float64')