-
Notifications
You must be signed in to change notification settings - Fork 16
FIX: Housekeeping of the data loader function #92
Conversation
This PR revises the data loading: - Add the possibility to read FSL's bvec/bval files for building the gradient table - Remove reorientations of the data (still thinking why they were there in the first place) - Calculating a b=0 map if none is provided
73aba23
to
dee4fe5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add some testing of this functionality, while you are at it?
src/eddymotion/dmri.py
Outdated
factory=lambda: Path(mkdtemp()) / "em_cache.h5", | ||
repr=False, | ||
) | ||
_filepath = attr.ib(factory=lambda: Path(mkdtemp()) / "em_cache.h5", repr=False,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the black config changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I can roll it back if too annoying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NBD, so long as we don't go back and forth. At some point it will be hard to figure out what actually changed when.
return DWI.from_filename(filename) | ||
|
||
if not gradients_file: | ||
if gradients_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to add some error handling here in case someone foolishly provides both kinds of input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a warning
b0img = nb.load(b0_file) | ||
retval.bzero = np.asanyarray(b0img.dataobj) | ||
elif np.any(~gradmsk): | ||
retval.bzero = np.median(fulldata[..., ~gradmsk], axis=3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never seen anyone use median values as the b0 image before. Is that common?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the median is more robust against outliers, but otherwise, it should be reasonably close to the average.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I know that. But compared to other implementations of some of these models (e.g., in DIPY) we will (sometimes? often?) get numerically different solutions, which is bound to raise questions at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea behind this is to have a fallback to generate a b0 quickly. The assumption is that generally, you will provide the b0_file
argument with a b=0 calculated in a more sophisticated way (e.g., denoising, b1 drift compensation, etc.)
Co-authored-by: Ariel Rokem <[email protected]>
e06de51
to
5553220
Compare
5553220
to
7318a64
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the added tests! I think this could go in now, but just a couple more comments. Feel free to merge after you've addressed (or if you don't they're necessary to address).
b0img = nb.load(b0_file) | ||
retval.bzero = np.asanyarray(b0img.dataobj) | ||
elif np.any(~gradmsk): | ||
retval.bzero = np.median(fulldata[..., ~gradmsk], axis=3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I know that. But compared to other implementations of some of these models (e.g., in DIPY) we will (sometimes? often?) get numerically different solutions, which is bound to raise questions at some point.
src/eddymotion/dmri.py
Outdated
factory=lambda: Path(mkdtemp()) / "em_cache.h5", | ||
repr=False, | ||
) | ||
_filepath = attr.ib(factory=lambda: Path(mkdtemp()) / "em_cache.h5", repr=False,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NBD, so long as we don't go back and forth. At some point it will be hard to figure out what actually changed when.
src/eddymotion/dmri.py
Outdated
nii = nb.Nifti1Image(data, self.affine, None) | ||
nii.header.set_xyzt_units("mm") | ||
nii.to_filename(filename) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this here for a reason?
Oh - sorry - just noticed that the tests are failing. Good thing they're in place 😄 |
This PR revises the data loading: