Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.

Conversation

oesteban
Copy link
Member

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

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
@oesteban oesteban force-pushed the fix/data-loader-revision branch from 73aba23 to dee4fe5 Compare November 23, 2022 20:56
Copy link
Collaborator

@arokem arokem left a 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?

factory=lambda: Path(mkdtemp()) / "em_cache.h5",
repr=False,
)
_filepath = attr.ib(factory=lambda: Path(mkdtemp()) / "em_cache.h5", repr=False,)
Copy link
Collaborator

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?

Copy link
Member Author

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

Copy link
Collaborator

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:
Copy link
Collaborator

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?

Copy link
Member Author

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)
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.)

@oesteban oesteban force-pushed the fix/data-loader-revision branch from e06de51 to 5553220 Compare November 24, 2022 18:26
@oesteban oesteban force-pushed the fix/data-loader-revision branch from 5553220 to 7318a64 Compare November 24, 2022 18:27
Copy link
Collaborator

@arokem arokem left a 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)
Copy link
Collaborator

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.

factory=lambda: Path(mkdtemp()) / "em_cache.h5",
repr=False,
)
_filepath = attr.ib(factory=lambda: Path(mkdtemp()) / "em_cache.h5", repr=False,)
Copy link
Collaborator

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.

nii = nb.Nifti1Image(data, self.affine, None)
nii.header.set_xyzt_units("mm")
nii.to_filename(filename)
return
Copy link
Collaborator

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?

@arokem
Copy link
Collaborator

arokem commented Nov 25, 2022

Oh - sorry - just noticed that the tests are failing. Good thing they're in place 😄

@arokem arokem merged commit b171b46 into main Nov 25, 2022
@oesteban oesteban deleted the fix/data-loader-revision branch October 29, 2024 21:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants