From 3d06a8a15316535f88999ff772af8612dec641cc Mon Sep 17 00:00:00 2001 From: Alex Daniel Date: Tue, 28 Nov 2023 11:38:23 +0000 Subject: [PATCH 1/2] Fix for DWI None mask export --- ukat/mapping/diffusion.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ukat/mapping/diffusion.py b/ukat/mapping/diffusion.py index 8bb8055c..012ac60b 100644 --- a/ukat/mapping/diffusion.py +++ b/ukat/mapping/diffusion.py @@ -467,9 +467,10 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output', nib.save(color_fa_nifti, base_path + '_color_fa_map.nii.gz') elif result == 'mask': - mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16), - affine=self.affine) - nib.save(mask_nifti, base_path + '_mask.nii.gz') + if self.mask is not None: + mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16), + affine=self.affine) + nib.save(mask_nifti, base_path + '_mask.nii.gz') else: raise ValueError('No NIFTI file saved. The variable "maps" ' 'should be "all" or a list of maps from ' From 296896652a0196a1692722bad3ef5afbaccf2ef6 Mon Sep 17 00:00:00 2001 From: Alex Daniel Date: Tue, 28 Nov 2023 12:06:01 +0000 Subject: [PATCH 2/2] pep8 fixes --- ukat/mapping/diffusion.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ukat/mapping/diffusion.py b/ukat/mapping/diffusion.py index 012ac60b..ca3be275 100644 --- a/ukat/mapping/diffusion.py +++ b/ukat/mapping/diffusion.py @@ -57,7 +57,7 @@ def make_gradient_scheme(bvals, bvecs, normalize=True, one_bzero=True): if normalize: # Rescale bvecs to have norm 1 - bvecs = [v/np.linalg.norm(v) for v in bvecs] + bvecs = [v / np.linalg.norm(v) for v in bvecs] bvecs = [np.round(x, 8) for x in bvecs] @@ -120,6 +120,7 @@ class ADC: contains six volumes acquired with b=600 s/mm^2 in different directions, these six volumes will be averaged together. """ + def __init__(self, pixel_array, affine, bvals, mask=None, ukrin_b=False): """Initialise a ADC class instance. @@ -195,7 +196,7 @@ def __mean_over_directions__(self): """ pixel_array_mean = np.zeros((*self.shape, self.n_bvals)) for ind, bval in enumerate(self.u_bvals): - pixel_array_mean[..., ind]\ + pixel_array_mean[..., ind] \ = np.mean(self.pixel_array[..., self.bvals == bval], axis=-1) return pixel_array_mean @@ -364,6 +365,7 @@ class DTI: tensor_fit : dipy TensorModel after fitting The fit dipy tensor model, can be used to recall additional parameters. """ + def __init__(self, pixel_array, affine, bvals, bvecs, mask=None, ukrin_b=False): """Initialise a DTI class instance. @@ -468,8 +470,9 @@ def to_nifti(self, output_directory=os.getcwd(), base_file_name='Output', '_color_fa_map.nii.gz') elif result == 'mask': if self.mask is not None: - mask_nifti = nib.Nifti1Image(self.mask.astype(np.uint16), - affine=self.affine) + mask_nifti = ( + nib.Nifti1Image(self.mask.astype(np.uint16), + affine=self.affine)) nib.save(mask_nifti, base_path + '_mask.nii.gz') else: raise ValueError('No NIFTI file saved. The variable "maps" '