@@ -110,37 +110,39 @@ def test_main(datadir):
110
110
assert isinstance (load (input_file ), DWI )
111
111
112
112
113
- def test_load (datadir , tmp_path ):
113
+ @pytest .mark .parametrize ("insert_b0" , (False , True ))
114
+ def test_load (datadir , tmp_path , insert_b0 ):
114
115
dwi_h5 = DWI .from_filename (datadir / "dwi.h5" )
115
116
dwi_nifti_path = tmp_path / "dwi.nii.gz"
116
117
gradients_path = tmp_path / "dwi.tsv"
117
- bvecs_path = tmp_path / "dwi.bvecs"
118
- bvals_path = tmp_path / "dwi.bvals"
119
118
120
- grad_table = np .hstack ((np .zeros ((4 , 1 )), dwi_h5 .gradients ))
121
-
122
- dwi_h5 .to_nifti (dwi_nifti_path , insert_b0 = True )
123
- np .savetxt (str (gradients_path ), grad_table .T )
124
- np .savetxt (str (bvecs_path ), grad_table [:3 ])
125
- np .savetxt (str (bvals_path ), grad_table [- 1 ])
119
+ dwi_h5 .to_nifti (dwi_nifti_path , insert_b0 = insert_b0 )
126
120
127
121
with pytest .raises (RuntimeError ):
128
122
from_nii (dwi_nifti_path )
129
123
130
- # Try loading NIfTI + gradients table
131
- dwi_from_nifti1 = from_nii (dwi_nifti_path , gradients_file = gradients_path )
132
-
133
- assert np .allclose (dwi_h5 .dataobj , dwi_from_nifti1 .dataobj )
134
- assert np .allclose (dwi_h5 .bzero , dwi_from_nifti1 .bzero )
135
- assert np .allclose (dwi_h5 .gradients , dwi_from_nifti1 .gradients )
136
-
137
124
# Try loading NIfTI + b-vecs/vals
138
- dwi_from_nifti2 = from_nii (
125
+ out_root = dwi_nifti_path .parent / dwi_nifti_path .name .replace (
126
+ "" .join (dwi_nifti_path .suffixes ), ""
127
+ )
128
+ bvecs_path = out_root .with_suffix (".bvec" )
129
+ bvals_path = out_root .with_suffix (".bval" )
130
+ dwi_from_nifti1 = from_nii (
139
131
dwi_nifti_path ,
140
132
bvec_file = bvecs_path ,
141
133
bval_file = bvals_path ,
142
134
)
143
135
136
+ assert np .allclose (dwi_h5 .dataobj , dwi_from_nifti1 .dataobj )
137
+ assert np .allclose (dwi_h5 .bzero , dwi_from_nifti1 .bzero )
138
+ assert np .allclose (dwi_h5 .gradients , dwi_from_nifti1 .gradients , atol = 1e-6 )
139
+
140
+ grad_table = np .hstack ((np .zeros ((4 , 1 )), dwi_h5 .gradients ))
141
+ np .savetxt (str (gradients_path ), grad_table .T )
142
+
143
+ # Try loading NIfTI + gradients table
144
+ dwi_from_nifti2 = from_nii (dwi_nifti_path , gradients_file = gradients_path )
145
+
144
146
assert np .allclose (dwi_h5 .dataobj , dwi_from_nifti2 .dataobj )
145
147
assert np .allclose (dwi_h5 .bzero , dwi_from_nifti2 .bzero )
146
148
assert np .allclose (dwi_h5 .gradients , dwi_from_nifti2 .gradients )
0 commit comments