@@ -46,40 +46,38 @@ def tens_mod_fa_est(gtab_file, dwi_file, B0_mask):
4646
4747 gtab = load_pickle (gtab_file )
4848
49- data = nib .load (dwi_file ).get_fdata ()
49+ data = nib .load (dwi_file , mmap = False ).get_fdata ()
5050
5151 print ("Generating tensor FA image to use for registrations..." )
52- nodif_B0_img = nib .load (B0_mask )
53- nodif_B0_mask_data = np .nan_to_num (np .asarray (
54- nodif_B0_img .dataobj )).astype ("bool" )
52+ nodif_B0_img = nib .load (B0_mask , mmap = False )
53+ nodif_B0_mask_data = nodif_B0_img .get_fdata ().astype ("bool" )
5554 model = TensorModel (gtab )
5655 mod = model .fit (data , nodif_B0_mask_data )
5756 FA = fractional_anisotropy (mod .evals )
58- MD = mean_diffusivity (mod .evals )
59- FA_MD = np .logical_or (
60- FA >= 0.2 , (np .logical_and (
61- FA >= 0.08 , MD >= 0.0011 )))
62- FA [np .isnan (FA )] = 0
63- FA_MD [ np .isnan ( FA_MD )] = 0
57+ # MD = mean_diffusivity(mod.evals)
58+ # FA_MD = np.logical_or(
59+ # FA >= 0.2, (np.logical_and(
60+ # FA >= 0.08, MD >= 0.0011)))
61+ # FA_MD [np.isnan(FA_MD )] = 0
62+ FA = np .nan_to_num ( np . asarray ( FA . astype ( 'float32' )))
6463
6564 fa_path = f"{ os .path .dirname (B0_mask )} { '/tensor_fa.nii.gz' } "
6665 nib .save (
6766 nib .Nifti1Image (
68- FA .astype (
69- np .float32 ),
67+ FA ,
7068 nodif_B0_img .affine ),
7169 fa_path )
7270
73- md_path = f"{ os .path .dirname (B0_mask )} { '/tensor_md.nii.gz' } "
74- nib .save (
75- nib .Nifti1Image (
76- MD .astype (
77- np .float32 ),
78- nodif_B0_img .affine ),
79- md_path )
71+ # md_path = f"{os.path.dirname(B0_mask)}{'/tensor_md.nii.gz'}"
72+ # nib.save(
73+ # nib.Nifti1Image(
74+ # MD.astype(
75+ # np.float32),
76+ # nodif_B0_img.affine),
77+ # md_path)
8078
8179 nodif_B0_img .uncache ()
82- del FA , FA_MD
80+ del FA
8381
8482 return fa_path , B0_mask , gtab_file , dwi_file
8583
0 commit comments