Skip to content

Commit

Permalink
Merge pull request #217 from alexdaniel654/maintenance/dwi_none_mask_…
Browse files Browse the repository at this point in the history
…export_bug

DWI Mask Bug
  • Loading branch information
alexdaniel654 authored Nov 28, 2023
2 parents 2414dab + 2968966 commit be9e2fd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ukat/mapping/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -467,9 +469,11 @@ 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 '
Expand Down

0 comments on commit be9e2fd

Please sign in to comment.