@@ -679,9 +679,17 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
679
679
safe_movefile (res .outputs .bvecs , outname_bvecs , overwrite )
680
680
safe_movefile (res .outputs .bvals , outname_bvals , overwrite )
681
681
else :
682
- os .remove (res .outputs .bvecs )
683
- os .remove (res .outputs .bvals )
684
- lgr .debug ("%s and %s were removed since not dwi" , res .outputs .bvecs , res .outputs .bvals )
682
+ if bvals_are_zero (res .outputs .bvals ):
683
+ os .remove (res .outputs .bvecs )
684
+ os .remove (res .outputs .bvals )
685
+ lgr .debug ("%s and %s were removed since not dwi" , res .outputs .bvecs , res .outputs .bvals )
686
+ else :
687
+ lgr .info ("Diffusion-weighted image saved in non dwi folder (%s)" , prefix_dirname )
688
+ lgr .info (".bvec and .bval files will be generated. This is NOT BIDS compliant" )
689
+ outname_bvecs , outname_bvals = prefix + '.bvec' , prefix + '.bval'
690
+ safe_movefile (res .outputs .bvecs , outname_bvecs , overwrite )
691
+ safe_movefile (res .outputs .bvals , outname_bvals , overwrite )
692
+
685
693
686
694
if isinstance (res_files , list ):
687
695
res_files = sorted (res_files )
@@ -811,3 +819,23 @@ def add_taskname_to_infofile(infofiles):
811
819
812
820
# write to outfile
813
821
save_json (infofile , meta_info )
822
+
823
+
824
+ def bvals_are_zero (bval_file , threshold = 5 ):
825
+ """Checks if all entries in a bvals file are zero (or below the threshold).
826
+ Returns True if that is the case, otherwise returns False
827
+
828
+ Parameters
829
+ ----------
830
+ bval_file : file with the bvals
831
+ threshold : b-value below which they are considered to be zero. (Default: 5)
832
+
833
+ Returns
834
+ -------
835
+ True if all are zero; False otherwise.
836
+ """
837
+
838
+ with open (bval_file ) as f :
839
+ bvals = f .read ().split ()
840
+
841
+ return all (float (b ) <= threshold for b in bvals )
0 commit comments