-
Notifications
You must be signed in to change notification settings - Fork 26
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
ENH: Remove dependency on nibabel.trackvis
#64
base: master
Are you sure you want to change the base?
ENH: Remove dependency on nibabel.trackvis
#64
Conversation
5ac0c52
to
8adff56
Compare
Remove dependency on `nibabel.trackvis`: the module was deprecated in `NiBabel` 2.5.0 and removed in version 4.0.0. So this patch set adapts the `tractography.trackvis` code so that it uses the modern API. Add a tolerance when comparing streamline data in `equal_tracts` to account for some precision loss since data is transformed to `float32` (vs `float64`) when applying the operations of the `NiBabel` API. Fixes: ``` tract_querier/tractography/tests/test_tractography.py::test_saveload_trk site-packages/nibabel/deprecated.py:35: DeprecationWarning: The trackvis interface has been deprecated and will be removed in v4.0; please use the 'nibabel.streamlines' interface. mod = __import__(self._module_name, fromlist=['']) ``` and ``` tract_querier/tractography/trackvis.py:7: in <module> from nibabel import trackvis E ImportError: cannot import name 'trackvis' from 'nibabel' (/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/nibabel/__init__.py) ``` and related errors raised for example in: https://github.com/demianw/tract_querier/actions/runs/12195905001/job/34022456528#step:6:85 and https://github.com/demianw/tract_querier/actions/runs/12195905001/job/34022456201#step:6:32
Commit 8adff56 makes the Python 3.9, 3.10, and 3.11 That commit checks as well the old NiBabel To avoid missing the code, I've also put it into a gist: I will push a commit removing the checks and the dependency on the old NiBabel |
8adff56
to
c977552
Compare
Commit c977552 makes CIs happier: Python 3.12 I am not sure whether the which I had to borrow from is currently used in with no assignments. I think Following the That said, @demianw best would be to try the 93ab73f version against the one in here (c977552) with some known, in vivo data with known results. I do not have any known data/known results, so leaving this up to you @demianw if you can afford the time. Otherwise, this is good to go on my end. |
Converting back to draft; will check one more thing. |
So I converted this back to draft because I wanted to check the solution with a non-identity affine, and as I was suspecting the proposed solution does not work, unfortunately. The affine I used:
was one that I created with the following arbitrary values
It turns out that debugging (I changed the IMO this has to do with the trackvis data assuming that the origin of the coordinates is at the center of the voxel: When trying to deal with that and considering what the StatefulTractogram does: inserting the code below in to the gist (see below for the link):
The two sets of streamlines (original I have left the entire modified I have spent some time trying to fix this without success. So @demianw if you happen to have some insight on what is happening, it would be much appreciated. |
@MarcCote I hate to bother you, but if anybody might instantly see the issue here, it would be you. |
Hey @effigies no problem. I vaguely recall that the old nibabel's trackvis implementation might have not considered that Trackvis (the software, hence the file format) assume (0,0,0) is at the center of the voxel. If I understand correctly the "issue" here is why the transformation (similar to what is done in the StatefulTractogram) does not bring the two tractograms on top of each other? What software are you using to do the visualization? Some software will take into account the metadata contains in the header of the .trk. Lighting up the tractogram's beacon @frheault |
Thanks for chiming in @effigies and @MarcCote.
Somehow; I do not fully see where the underlying issue lies. Using the non-identity, arbitrary affine I posted, the
Mi-Brain. |
Hello, Sadly, I am not familiar (and/or I forgot) with how the TRK was written in the older version of Babel. The load_tractogram() function assumes a lot of things. It is pretty common when I deal with older file that I need to load the streamline with nib.streamlines.load() and then create a StatefulTractogram This is common because some software saves the TRK assuming the wrong origin but uses software with the same assumption. This is not a problem with the affine (the affine should be identical to the NIFTI that match with the TRK). There is an even worse possibility, sometimes a VOX space shift is made in RASMM (adding 0.5 but when the streamlines are in their final RASMM space) or vice versa (A RASMM shift is made while the streamlines are in VOX). This is more complex and requires a lot of tinkering to fix the TRK so they have no negative coordinates in VOX space and align on top of their matching NIFTI. |
Remove dependency on
nibabel.trackvis
: the module was deprecated inNiBabel
2.5.0 and removed in version 4.0.0. So this patch set adapts thetractography.trackvis
code so that it uses the modern API.Add a tolerance when comparing streamline data in
equal_tracts
to account for some precision loss since data is transformed tofloat32
(vsfloat64
) when applying the operations of theNiBabel
API.Fixes:
and
and related errors raised for example in:
https://github.com/demianw/tract_querier/actions/runs/12195905001/job/34022456528#step:6:85 and
https://github.com/demianw/tract_querier/actions/runs/12195905001/job/34022456201#step:6:32