data.dmri
has mismatches between reading/writting/representation
#79
Labels
bug
Something isn't working
data.dmri
has mismatches between reading/writting/representation
#79
What happened?
The DWI reading/saving/representation logic has some bugs.
test_data_mri::test_load
is reading the bvals/bvecs filesnifreeze/test/test_data_dmri.py
Lines 126 to 129 in 7322e93
that are being written by the test function
nifreeze/test/test_data_dmri.py
Lines 112 to 113 in 7322e93
based on the
grad_table
variable, which is effectively inserting a b0 value to the bvals/bvecs file (having shapes(1, 103)
,(3, 103)
), instead of writing the bval/bvec file pair that is written by theDWI.to_nifti
method, which is what we should be testing.insert_b0
isTrue
, as it is the case in the test, theDWI.to_nifti
method:nifreeze/src/nifreeze/data/dmri.py
Lines 210 to 237 in 7322e93
does not insert any null gradient to the bval/bvecs files (having shapes
(1, 102)
,(3, 102)
). Thus, if we had read those files in the test, the test would be failing due to a shape mismatch error innifreeze/src/nifreeze/data/dmri.py
Line 336 in 7322e93
as the data contained by the NIfTI files will have 103 DWI volumes (102 corresponding to non-b0 data, and the one inserted by virtue of
insert_b0
beingTrue
), and the gradients read will have 102 values. Note that the represented DWI data has non-null (notNone
), built-inbzero
data as well (besides the b0 data that the writer is asked to write following theinsert_b0
flag).However, there is a deeper bug here:
DWI.to_nifti
method to add a null gradient to the bval/bvecs files:and if
insert_b0
isTrue
, the test will pass. However, it will not pass ifinsert_b0
isFalse
. None of the cases on linesnifreeze/src/nifreeze/data/dmri.py
Lines 345 to 356 in 7322e93
True
and thus the readdwi_obj
will have aNone
value in itsbzero
property, whereas the test objectdwi_h5
does have abzero
volume, thusassert np.allclose(dwi_h5.bzero, dwi_from_nifti.bzero)
will fail.So the logic behind this needs to be reworked. Some thoughts:
bzero
, the written file becomes out of sync with its original representation.bzero
value (as the original instance read form theh5
file has), but not to have a 0-valued bval/bvec in the gradients.b0_file
, but nob0_file
is being written. Not writing an additional b0 file seems natural, as one expects the b0 data to be saved together with the non-b0 data, but then allowing to read one does not seem natural.test_load
should be parameterized withinsert_b0
to[False, True]
to test all of the above properly.What command did you use?
What version of the software are you running?
HEAD
(commit 7322e93) with the necessary fixes in PR #72How are you running this software?
Local installation ("bare-metal")
Is your data BIDS valid?
Yes
Are you reusing any previously computed results?
No
Please copy and paste any relevant log output.
For the issue (i.e. not writing the bval/bvec files that should be read, and not writing the null gradient to the bval/bvec files):
For the second issue (having made such that the above passes add a null gradient to the written bval and bvec files but using
False
forinsert_b0
):Additional information / screenshots
X-ref #72 (comment).
The text was updated successfully, but these errors were encountered: