-
Notifications
You must be signed in to change notification settings - Fork 5
REF: Refactor gradient data checks in DWI data class #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
REF: Refactor gradient data checks in DWI data class #327
Conversation
e406487 to
a378f89
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #327 +/- ##
=======================================
Coverage ? 78.85%
=======================================
Files ? 28
Lines ? 1887
Branches ? 199
=======================================
Hits ? 1488
Misses ? 339
Partials ? 60 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a378f89 to
6cd6e78
Compare
|
A few notes:
where In the direct instantiation case, The above is an inconsistency that needs to be addressed: if we input the same the same data (whether as files or as unprocessed arrays), we should get two instances that hold exactly the same information. I know that for the instantiation case, we should not be providing the b0s in the Although which would mean that we may attempt to do the same job twice. Whatever approach we take to solve this, that should be addressed in a separate PR. |
eecba2a to
c250888
Compare
|
If the changes in this PR are uncontroversial, and not introducing hidden bugs, can we please merge it? The further refactoring to complete #327 (comment) become necessary in PR #305 (it can already be seen what these would look like). |
I'm working on this one 👍, please hold on. |
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
rf: overhaul suggested by nipreps#327's title
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
ee02d74 to
940ed08
Compare
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
940ed08 to
2a57a73
Compare
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
2a57a73 to
3686a5e
Compare
|
Leaving this error to you @oesteban 😔. Thanks. |
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
14d50ac to
cfff5bb
Compare
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
cfff5bb to
c782ac6
Compare
6ab0516 to
f1ebf08
Compare
f1ebf08 to
da1e127
Compare
|
Re: #332 (comment) So, the relevant changes from PR #305 are brought here. PR #305 can be safely closed. |
03dd2c6 to
de9c64d
Compare
Refactor gradient data checks in DWI data class: PR nipreps#325 introduced the row-major convention for gradient data in NiFreeze. However, gradient loading was not tested thoroughly. This resulted in some execution flows that would not guarantee a row-major internal convention or would crash under some circumstances. This commit refactors the gradient data checks and adds thorough testing: - Define all error or warning messages as global variables so that they can be checked exactly in tests. - Ensure that gradients conform to the row-major convention when instantiating the DWI class directly. This allows to separate the gradient reformatting from the dimensionality check with the DWI volume sequence. This simplifies the flow, as the gradient reformatting to the row-major convention does not depend on the number of volumes in the DWI sequence. Also, this makes the flow more consistent with the refactored checks of the NIfTI file-based loading utility function (`from_nii`). - Ensure that the gradients conform to the row-major convention immediately after loading the gradients file in the NIfTI file-based loading utility function (`from_nii`). As opposed to the previous implementation, this allows to load the gradients from a file where data follows either column-major or row-major convention. e.g. In the previous implementation the `if grad.shape[1] < 2:` was making an assumption about the layout and/or one that was wrong because we require 4 columns (direction (x,y,z) + b-value) or rows (if in column-major). The new implementation simplifies the execution flow.
This patch - moves the responsibility of formatting and validating the gradients into the attrs' infrastructure; - removes complexity from ``from_nifti()`` that was completely unnecessary (e.g., motion file can be set after creating the DWI object). - updates tests - skips one test that is unreasonably slow, we need to look into what's going on with ``to_nifti()``.
Improve gradient formatting function robustness by adopting a more defensive approach: - Raise if gradients are `None`. - Raise if gradients are not a numeric homogeneous array-like object. Add the corresponding tests. Take advantage of the commit to test the `validate_gradients` function.
Add additional object instantiation equality checks: check that objects intantiated through reading NIfTI files equal objects instantiated directly.
de9c64d to
7933b75
Compare
Refactor gradient data checks in DWI data class: PR #325 introduced the row-major convention for gradient data in NiFreeze. However, gradient loading was not tested thoroughly. This resulted in some execution flows that would not guarantee a row-major internal convention or would crash under some circumstances.
This commit refactors the gradient data checks and adds thorough testing:
from_nii).from_nii). As opposed to the previous implementation, this allows to load the gradients from a file where data follows either column-major or row-major convention. e.g. In the previous implementation theif grad.shape[1] < 2:was making an assumption about the layout and/or one that was wrong because we require 4 columns (direction (x,y,z) + b-value) or rows (if in column-major). The new implementation simplifies the execution flow.