@@ -29,6 +29,39 @@ def read_json_file(json_file):
29
29
30
30
return json_data
31
31
32
+ def read_bval_file (bval_file ):
33
+ """
34
+ For reading the bval file
35
+ """
36
+ if not os .path .exists (bval_file ):
37
+ raise FileNotFoundError (f"File '{ bval_file } ' not found." )
38
+
39
+ with open (bval_file , "r" ) as f :
40
+ try :
41
+ bval_data = [int (val ) for val in f .read ().split ()]
42
+ except ValueError as e :
43
+ raise ValueError (f"Error reading bval file '{ bval_file } ': { e } " )
44
+
45
+ return bval_data
46
+
47
+ def read_bvec_file (bvec_file ):
48
+ """
49
+ For reading the bvec file
50
+ """
51
+ if not os .path .exists (bvec_file ):
52
+ raise FileNotFoundError (f"File '{ bvec_file } ' not found." )
53
+
54
+ with open (bvec_file , "r" ) as f :
55
+ try :
56
+ lines = f .readlines ()
57
+ bvec_data = []
58
+ for line in lines :
59
+ bvec_data .append ([float (val ) for val in line .split ()])
60
+ except ValueError as e :
61
+ raise ValueError (f"Error reading bvec file '{ bvec_file } ': { e } " )
62
+
63
+ return bvec_data
64
+
32
65
def save_nifti_file (data , output_file , affine = None , ** kwargs ):
33
66
"""
34
67
For saving the 3d nifti images of the output of the algorithm
@@ -58,9 +91,10 @@ def loop_over_first_n_minus_1_dimensions(arr):
58
91
if __name__ == "__main__" :
59
92
parser = argparse .ArgumentParser (description = "Read a 4D NIfTI phantom file along with BIDS JSON, b-vector, and b-value files." )
60
93
parser .add_argument ("input_file" , type = str , help = "Path to the input 4D NIfTI file." )
61
- parser .add_argument ("bids_dir" , type = str , help = "Path to the BIDS directory." )
94
+ parser .add_argument ("bvec_file" , type = str , help = "Path to the b-vector file." )
95
+ parser .add_argument ("bval_file" , type = str , help = "Path to the b-value file." )
62
96
parser .add_argument ("--affine" , type = float , nargs = "+" , help = "Affine matrix for NIfTI image." )
63
- parser .add_argument ("--algorithm" , type = str , choices = ["algorithm1" , "algorithm2" ], default = "algorithm1 " , help = "Select the algorithm to use." )
97
+ parser .add_argument ("--algorithm" , type = str , choices = ["algorithm1" , "algorithm2" ], default = "OJ_GU_seg " , help = "Select the algorithm to use." )
64
98
parser .add_argument ("algorithm_args" , nargs = argparse .REMAINDER , help = "Additional arguments for the algorithm." )
65
99
66
100
args = parser .parse_args ()
@@ -69,15 +103,9 @@ def loop_over_first_n_minus_1_dimensions(arr):
69
103
# Read the 4D NIfTI file
70
104
data , _ = read_nifti_file (args .input_file )
71
105
72
- # Construct the full paths for the JSON, b-vector, and b-value files
73
- json_file = os .path .join (args .bids_dir , "dataset_description.json" )
74
- bvec_file = os .path .join (args .bids_dir , "bvecs.json" )
75
- bval_file = os .path .join (args .bids_dir , "bvals.json" )
76
-
77
- # Read the JSON, b-vector, and b-value files
78
- json_data = read_json_file (json_file )
79
- bvecs = read_json_file (bvec_file )
80
- bvals = read_json_file (bval_file )
106
+ # Read the b-vector, and b-value files
107
+ bvecs = read_bvec_file (args .bvec_file )
108
+ bvals = read_bval_file (args .bval_file )
81
109
82
110
# Pass additional arguments to the algorithm
83
111
fit = OsipiBase (algorithm = args .algorithm )
0 commit comments