soft-matter / trackpy

Python particle tracking toolkit
http://soft-matter.github.io/trackpy
Other
445 stars 131 forks source link

How to increase max_candidates #622

Open zizhaowillwang opened 4 years ago

zizhaowillwang commented 4 years ago

I saw in the source code the max_candidates limit is set as 9, and in my analysis, the code gave me an error message saying there are 10 forward candidates when it tries to link particles between frames. I know the method to adjust subnet size and max neighbor, but what is the method to change the max_candidates limit?

nkeim commented 4 years ago

That is hard-coded. You may be the first person to run into that error message! If the density of particles is very heterogeneous, you may wish to check out the "adaptive search" tutorial.

Alternately, you can try installing trackpy from GitHub and edit the number by hand. In a future version of trackpy, it might make sense to make this a module-level variable that can be changed.

tacaswell commented 4 years ago

If I recall correctly, that number is set as both a limit on the run time (as the algorithm scales very badly with the number of candidates) and as a science judgement that if you have that many candidates I am not convinced that the results should be trusted (as the argument that the minimal displacement assignment is the most likely starts to break down).

If your features are moving order their average separation (and you can't de-flow the positions) I am not sure tracking is going to work. If your features are moving << the average seperation and you are seeing that many connection candidates I suspect your max displacement is too big OR too small with a too-long memory.

zizhaowillwang commented 4 years ago

Thank you so much for both of your replies! I noticed the displacement of my particles is not uniform. Let's say, most particles move around 0.03 between frames, while a few move 0.12. So in order to track everything, I set the search range to 0.12. The regions for small and large displacements are mixed. There shouldn't be a drift in my data, and I set memory = 0 in tracking.

I understand your point. It seems the search range is too large. Is it possible to search for small displacements first and then large displacements in trackpy? Something like the iterative tracking presented in this paper. I'll also try to see if I can add this feature locally when running trackpy.

Thanks!

nkeim commented 4 years ago

This is essentially the idea behind adaptive search, so you may want to read that tutorial and see if that could meet your needs. As @tacaswell points out, if displacements are frequently comparable to particle spacings, the entire premise of trackpy (and Crocker-Grier tracking algorithms) is violated. Adaptive search is ideal only when you have widely-spaced particles that tend to be moving faster, and closely-spaced particles that tend to be moving slower.

If your displacements are not random (for example, neighboring particles move in the same direction), then you should also read the prediction tutorial. That can be highly effective in allowing you to reduce search_range.

zizhaowillwang commented 4 years ago

I see! I think the last time I used the adaptive search, I set the lower limit too high. I should try it again with the new understanding. Thank you so much!

zizhaowillwang commented 4 years ago

On a second look, if there are small and large moves between two time steps, is adaptive search going to solve the problem? I thought adaptive search is powerful when displacement is not uniform among different time steps, but what if the heterogeneity exists in one frame?

nkeim commented 4 years ago

Yes, adaptive search works at the subnet level, not at the frame level. If a subnet is too big, adaptive search reduces search_range for just those particles until at least one smaller subnet is created. It then recursively does the same thing with whatever particles remain in the subnet. In other words, it tries to do as little as possible.

zizhaowillwang commented 4 years ago

Got it. Thank you!