2828 assert_inputs_exist , assert_outputs_exist )
2929from scilpy .utils .bvec_bval_tools import extract_dwi_shell
3030
31- # TODO switch from parser to p
32- # TODO switch to in_*
33- # TODO switch to out_*
31+
3432def _build_arg_parser ():
35- parser = argparse .ArgumentParser (
33+ p = argparse .ArgumentParser (
3634 description = __doc__ ,
3735 formatter_class = argparse .RawTextHelpFormatter )
3836
39- parser .add_argument ('dwi ' ,
40- help = 'The DW image file to split.' )
37+ p .add_argument ('in_dwi ' ,
38+ help = 'The DW image file to split.' )
4139
42- parser .add_argument ('bvals ' ,
43- help = 'The b-values in FSL format.' )
40+ p .add_argument ('in_bval ' ,
41+ help = 'The b-values file in FSL format (.bval) .' )
4442
45- parser .add_argument ('bvecs ' ,
46- help = 'The b-vectors in FSL format.' )
43+ p .add_argument ('in_bvec ' ,
44+ help = 'The b-vectors file in FSL format (.bvec) .' )
4745
48- parser .add_argument ('bvals_to_extract' , nargs = '+' ,
49- metavar = 'bvals-to-extract' , type = int ,
50- help = 'The list of b-values to extract. For example '
51- '0 2000.' )
46+ p .add_argument ('in_bvals_to_extract' , nargs = '+' ,
47+ type = int ,
48+ help = 'The list of b-values to extract. For example 0 2000.' )
5249
53- parser .add_argument ('output_dwi ' ,
54- help = 'The name of the output DWI file.' )
50+ p .add_argument ('out_dwi ' ,
51+ help = 'The name of the output DWI file.' )
5552
56- parser .add_argument ('output_bvals ' ,
57- help = 'The name of the output b-values .' )
53+ p .add_argument ('out_bval ' ,
54+ help = 'The name of the output b-value file (.bval) .' )
5855
59- parser .add_argument ('output_bvecs ' ,
60- help = 'The name of the output b-vectors ' )
56+ p .add_argument ('out_bvec ' ,
57+ help = 'The name of the output b-vector file (.bvec). ' )
6158
62- parser .add_argument ('--block-size' , '-s' ,
63- metavar = 'INT' , type = int ,
64- help = 'Loads the data using this block size. '
65- 'Useful\n when the data is too large to be '
66- 'loaded in memory.' )
59+ p .add_argument ('--block-size' , '-s' ,
60+ metavar = 'INT' , type = int ,
61+ help = 'Loads the data using this block size. '
62+ 'Useful\n when the data is too large to be '
63+ 'loaded in memory.' )
6764
68- parser .add_argument ('--tolerance' , '-t' ,
69- metavar = 'INT' , type = int , default = 20 ,
70- help = 'The tolerated gap between the b-values to '
71- 'extract\n and the actual b-values.' )
65+ p .add_argument ('--tolerance' , '-t' ,
66+ metavar = 'INT' , type = int , default = 20 ,
67+ help = 'The tolerated gap between the b-values to '
68+ 'extract\n and the actual b-values.' )
7269
73- add_verbose_arg (parser )
74- add_overwrite_arg (parser )
70+ add_verbose_arg (p )
71+ add_overwrite_arg (p )
7572
76- return parser
73+ return p
7774
7875
7976def main ():
@@ -83,28 +80,28 @@ def main():
8380 if args .verbose :
8481 logging .basicConfig (level = logging .INFO )
8582
86- assert_inputs_exist (parser , [args .dwi , args .bvals , args .bvecs ])
87- assert_outputs_exist (parser , args , [args .output_dwi , args .output_bvals ,
88- args .output_bvecs ])
83+ assert_inputs_exist (parser , [args .in_dwi , args .in_bval , args .in_bvec ])
84+ assert_outputs_exist (parser , args , [args .out_dwi , args .out_bval ,
85+ args .out_bvec ])
8986
90- bvals , bvecs = read_bvals_bvecs (args .bvals , args .bvecs )
87+ bvals , bvecs = read_bvals_bvecs (args .in_bval , args .in_bvec )
9188
9289 # Find the volume indices that correspond to the shells to extract.
9390 tol = args .tolerance
9491
95- img = nib .load (args .dwi )
92+ img = nib .load (args .in_dwi )
93+
94+ outputs = extract_dwi_shell (img , bvals , bvecs , args .in_bvals_to_extract ,
95+ tol , args .block_size )
9696
97- outputs = extract_dwi_shell (img , bvals , bvecs , args .bvals_to_extract , tol ,
98- args .block_size )
9997 indices , shell_data , new_bvals , new_bvecs = outputs
10098
10199 logging .info ("Selected indices: {}" .format (indices ))
102100
103- np .savetxt (args .output_bvals , new_bvals , '%d' )
104- np .savetxt (args .output_bvecs , new_bvecs .T , '%0.15f' )
105- # use named argument header=
106- nib .save (nib .Nifti1Image (shell_data , img .affine , img .header ),
107- args .output_dwi )
101+ np .savetxt (args .out_bval , new_bvals , '%d' )
102+ np .savetxt (args .out_bvec , new_bvecs .T , '%0.15f' )
103+ nib .save (nib .Nifti1Image (shell_data , img .affine , header = img .header ),
104+ args .out_dwi )
108105
109106
110107if __name__ == "__main__" :
0 commit comments