@@ -208,7 +208,13 @@ def to_filename(
208208 with h5py .File (filename , "r+" ) as out_file :
209209 out_file .attrs ["Type" ] = "dmri"
210210
211- def to_nifti (self , filename : Path | str , insert_b0 : bool = False ) -> None :
211+ def to_nifti (
212+ self ,
213+ filename : Path | str ,
214+ insert_b0 : bool = False ,
215+ bvals_dec_places : int = 2 ,
216+ bvecs_dec_places : int = 6 ,
217+ ) -> None :
212218 """
213219 Write a NIfTI file to disk.
214220
@@ -218,6 +224,10 @@ def to_nifti(self, filename: Path | str, insert_b0: bool = False) -> None:
218224 The output NIfTI file path.
219225 insert_b0 : :obj:`bool`, optional
220226 Insert a :math:`b=0` at the front of the output NIfTI.
227+ bvals_dec_places : :obj:`int`, optional
228+ Decimal places to use when serializing b-values.
229+ bvecs_dec_places : :obj:`int`, optional
230+ Decimal places to use when serializing b-vectors.
221231
222232 """
223233 if not insert_b0 :
@@ -242,8 +252,8 @@ def to_nifti(self, filename: Path | str, insert_b0: bool = False) -> None:
242252
243253 # Save bvecs and bvals to text files
244254 # Each row of bvecs is one direction (3 rows, N columns).
245- np .savetxt (bvecs_file , self .bvecs , fmt = "%.6f " )
246- np .savetxt (bvals_file , self .bvals [np .newaxis , :], fmt = "%.6f " )
255+ np .savetxt (bvecs_file , self .bvecs , fmt = f "%.{ bvecs_dec_places } f " )
256+ np .savetxt (bvals_file , self .bvals [np .newaxis , :], fmt = f "%.{ bvals_dec_places } f " )
247257
248258
249259def load (
0 commit comments