Skip to content

NF - Add DirectionGetter for Flocking Tractography#13

Open
gabknight wants to merge 1 commit intogabknight:masterfrom
JesusMda:flocking-direction-getter
Open

NF - Add DirectionGetter for Flocking Tractography#13
gabknight wants to merge 1 commit intogabknight:masterfrom
JesusMda:flocking-direction-getter

Conversation

@gabknight
Copy link
Owner

@gabknight gabknight commented Jul 7, 2025

Description by Korbit AI

What change is being made?

Add the FlockingDirectionGetter class to enable flocking tractography in the DIPY library.

Why are these changes being made?

This change introduces a new direction getter based on flocking behavior for fiber tracking in diffusion imaging data, allowing for more realistic simulation of particle interactions during tracking. The flocking mechanism is implemented to enhance direction finding capabilities by incorporating parameters like particle count and attraction weights, adding to the existing probabilistic models in the library.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

@korbit-ai
Copy link

korbit-ai bot commented Jul 7, 2025

Based on your review schedule, I'll review this PR if you request it by commenting /korbit-review.

Your admin can turn on auto-reviews in the Korbit Console

Copy link
Owner Author

@gabknight gabknight left a comment

Choose a reason for hiding this comment

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

Thanks @JesusMda. Nice work. Can you check my comments. We will also need to add tests, similar to the PTT tests.

return 0

cdef class FlockingDirectionGetter(PmfGenDirectionGetter):
"""
Copy link
Owner Author

Choose a reason for hiding this comment

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

Can you add a docstring here, similar to other DG

"""

def __init__(self, pmf_gen, max_angle, sphere, pmf_threshold=.1, particle_count = 16, r_min=0.1, r_max=1.0, delta=0.995, alpha=1.0, **kwargs):
"""Direction getter from a pmf generator.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Please describe the flocking method here.

Used to remove direction from the probability mass function for
selecting the tracking direction.
particle_count
Number of particles in a flock
Copy link
Owner Author

Choose a reason for hiding this comment

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

missing "." after the sentences




cdef int get_direction_c(self, double[::1] point, double[::1] direction):
Copy link
Owner Author

Choose a reason for hiding this comment

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

This can be removed if you change the class inheritance to ProbabilisticDirectionGetter (like PTT)

copy_point(&seed[0], point)

terminate = False
r_min = self.r_min
Copy link
Owner Author

Choose a reason for hiding this comment

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

why re-defining those variable here? use directly self.r_min

double N, G, r_min, r_max, delta_1, delta_2, alpha, norma_vec
cnp.float_t[:, :] particles = np.empty((particle_count, 3), dtype=np.float64)
cnp.float_t[:, :] particles_dir = np.empty((particle_count, 3), dtype=np.float64)
cnp.float_t[:, :] u_m = np.empty((particle_count, 3), dtype=np.float64)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Please use a more explicit variable name here

cnp.float_t[:, :] particles_dir = np.empty((particle_count, 3), dtype=np.float64)
cnp.float_t[:, :] u_m = np.empty((particle_count, 3), dtype=np.float64)
cnp.uint8_t[:] particle_values = np.ones(particle_count, dtype=np.uint8)
cnp.float_t[:, :] F_m = np.empty((particle_count, 3), dtype=np.float64)
Copy link
Owner Author

Choose a reason for hiding this comment

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

same here

continue
for k in range(particle_count):
if k != m:
for j in range(3):
Copy link
Owner Author

Choose a reason for hiding this comment

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

Can you document a bit what you are doing here. It is hard to follow. Explicit variable names will help.

copy_point(&newdir[0], &direction[0])
return 0

cdef class FlockingDirectionGetter(PmfGenDirectionGetter):
Copy link
Owner Author

Choose a reason for hiding this comment

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

Can you move the flockingDG to it own file, like for PTT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants