Skip to content
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

RF - Moved tracking.localtrack._local_tracker to DirectionGetter.generate_streamline. #2368

Merged
merged 12 commits into from
May 8, 2021

Conversation

gabknight
Copy link
Contributor

@gabknight gabknight commented Apr 12, 2021

This is the first PR to generalized DIPY's tracking framework.

This PR moved the code from dipy.tracking.localtrack._local_tracker() to the DirectionGetter.generate_streamline(). This will allow for DirectionGetters to override how streamlines are generated in the local tracking framework. DIPY's DirectionGetters select the next tracking based on the current position and previous direction until a stopping criterion is reached. This modification will allow new DirectionGetters to use, e.g., the whole sequence of previous directions and positions to select the next tracking direction.

This doesn't have any effect on the generated streamlines or interfaces.

The ParticleFileteringTracking is not affected by the change. Future PR should modify PFT to leave streamline generation to DirectionGetters in a similar fashion, such that it can benefit from future overriding DirectionGetter.generate_streamline.

@pep8speaks
Copy link

pep8speaks commented Apr 12, 2021

Hello @gabknight, Thank you for updating !

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated at 2021-05-07 15:48:22 UTC

@codecov
Copy link

codecov bot commented May 3, 2021

Codecov Report

Merging #2368 (b3e5856) into master (07d7d5d) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2368      +/-   ##
==========================================
+ Coverage   85.21%   85.24%   +0.02%     
==========================================
  Files         125      125              
  Lines       16569    16581      +12     
  Branches     2686     2686              
==========================================
+ Hits        14120    14134      +14     
  Misses       1762     1762              
+ Partials      687      685       -2     
Impacted Files Coverage Δ
dipy/tracking/local_tracking.py 95.83% <100.00%> (ø)
dipy/reconst/csdeconv.py 86.83% <0.00%> (+0.04%) ⬆️
dipy/denoise/gibbs.py 97.39% <0.00%> (+0.04%) ⬆️
dipy/segment/bundles.py 89.16% <0.00%> (+0.07%) ⬆️
dipy/direction/peaks.py 84.50% <0.00%> (+0.15%) ⬆️
dipy/workflows/reconst.py 77.59% <0.00%> (+0.22%) ⬆️
dipy/workflows/denoise.py 86.66% <0.00%> (+0.30%) ⬆️
dipy/viz/app.py 77.50% <0.00%> (+0.48%) ⬆️

@gabknight gabknight changed the title WIP - move tracking.localtrack._local_tracker to DirectionGetter.generate_streamline. RF - Moved tracking.localtrack._local_tracker to DirectionGetter.generate_streamline. May 3, 2021
@gabknight
Copy link
Contributor Author

@skoudoro @guaje

Can you give me feedback on this? I moved the generate_streamline() code to the abstract DirectionGetter class. It was previously wrongly in BasePmfDirectionGetter, it needed to be in the parent class to work EuDXDirrectionGetter, which derives directly from DirectionGetter. Thanks!

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gabknight,

See below some of my comments. I agree that generate_streamlines should be on DirectionGetter. we need to rename generate_streamlines from now. it is really confusing with the one in tracking.py

Overall, it looks good to me.

dipy/direction/closest_peak_direction_getter.pyx Outdated Show resolved Hide resolved
dipy/direction/closest_peak_direction_getter.pxd Outdated Show resolved Hide resolved
dipy/direction/probabilistic_direction_getter.pyx Outdated Show resolved Hide resolved
dipy/tracking/direction_getter.pxd Outdated Show resolved Hide resolved
dipy/tracking/direction_getter.pyx Outdated Show resolved Hide resolved
dipy/tracking/direction_getter.pyx Show resolved Hide resolved
dipy/tracking/localtrack.pyx Show resolved Hide resolved
dipy/tracking/localtrack.pyx Outdated Show resolved Hide resolved
@gabknight gabknight force-pushed the RF_tracking_framework branch 2 times, most recently from 165a3cd to 723b9f3 Compare May 7, 2021 09:10
@gabknight
Copy link
Contributor Author

@skoudoro thx for the feedback. I believe all is fixed. I also suggested changing _generate_streamlines(.) to _generate_tractogram(.) in dipy.tracking.local_tracking.py.

I don't need to add deprecated warnings for internal function changes, do I?

Copy link
Member

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gabknight,

Thank you for the update.

I like the strategy to rename _generate_streamlines(.) to _generate_tractogram(.) in dipy.tracking.local_tracking.py. it makes more sense to me.

Apart from that, there are some functions in closest_peaks not used so not necessary?

I don't need to add deprecated warnings for internal function changes, do I?

No you don't, no needs

dipy/tracking/direction_getter.pyx Show resolved Hide resolved
Comment on lines 60 to 126
cdef extern from "dpy_math.h" nogil:
int dpy_signbit(double x)
double dpy_rint(double x)
double fabs(double)

@cython.cdivision(True)
cdef inline double stepsize(double point, double increment) nogil:
"""Compute the step size to the closest boundary in units of increment."""
cdef:
double dist
dist = dpy_rint(point) + .5 - dpy_signbit(increment) - point
if dist == 0:
# Point is on an edge, return step size to next edge. This is most
# likely to come up if overstep is set to 0.
return 1. / fabs(increment)
else:
return dist / increment

cdef void step_to_boundary(double * point, double * direction,
double overstep) nogil:
"""Takes a step from point in along direction just past a voxel boundary.

Parameters
----------
direction : c-pointer to double[3]
The direction along which the step should be taken.
point : c-pointer to double[3]
The tracking point which will be updated by this function.
overstep : double
It's often useful to have the points of a streamline lie inside of a
voxel instead of having them lie on the boundary. For this reason,
each step will overshoot the boundary by ``overstep * direction``.
This should not be negative.

"""
cdef:
double step_sizes[3]
double smallest_step

for i in range(3):
step_sizes[i] = stepsize(point[i], direction[i])

smallest_step = step_sizes[0]
for i in range(1, 3):
if step_sizes[i] < smallest_step:
smallest_step = step_sizes[i]

smallest_step += overstep
for i in range(3):
point[i] += smallest_step * direction[i]

cdef void fixed_step(double * point, double * direction, double step_size) nogil:
"""Updates point by stepping in direction.

Parameters
----------
direction : c-pointer to double[3]
The direction along which the step should be taken.
point : c-pointer to double[3]
The tracking point which will be updated by this function.
step_size : double
The size of step in units of direction.

"""
for i in range(3):
point[i] += direction[i] * step_size

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why you need this block in close_peak_direction_getter.pyx. it is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need it. This should have been removed when we moved generate_streamline(.) to the parent class DirectionGetter. thx.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Great! This PR is ready for me.

There are 2-3 things that can be improved (unnecessary copy) but we can do that in a new PR.

@skoudoro
Copy link
Member

skoudoro commented May 7, 2021

I think this PR is ready to go! I will wait until tomorrow evening for additional comments. Feel free to review this PR!

@skoudoro skoudoro added this to the 1.5.0 milestone May 8, 2021
@skoudoro skoudoro merged commit 00d0524 into dipy:master May 8, 2021
@skoudoro
Copy link
Member

skoudoro commented May 8, 2021

Thank you @gabknight!

@gabknight gabknight deleted the RF_tracking_framework branch December 8, 2023 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants