soft-matter / trackpy

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

How to determine MAX_SUB_NET_SIZE? #599

Open loomcode opened 4 years ago

loomcode commented 4 years ago

I'm getting the following error:

trackpy.linking.utils.SubnetOversizeException: Subnetwork contains 10316 points

All the images in my stack have ~ 10k points.

f = tp.batch(frames[:], 5, minmass=20, invert=False); t = tp.link(f, 15, memory=3)

As the documentation indicates, I can circumvent the error by setting the maximum displacement from 15 to 5, but it seems to make no difference what I set "tp.linking.Linker.MAX_SUB_NET_SIZE" equal to. By the way, is maximum displacement, the maximum displacement across all frames in my stack or the maximum displacement between adjacent frames?

Thanks.

danielballan commented 4 years ago

Hi, @loomcode. The maximum displacement is the maximum displacement between adjacent frames.

Could you elaborate on:

but it seems to make no difference what I set "tp.linking.Linker.MAX_SUB_NET_SIZE" equal to.

loomcode commented 4 years ago

Daniel,

Thanks for the clarification. According to the documentation here: http://soft-matter.github.io/trackpy/v0.3.0/generated/trackpy.SubnetOversizeException.html

If you get this then either reduce your search range or increase Linker.MAX_SUB_NET_SIZE

It looks like the default Linker.MAX_SUB_NET_SIZE is 30. If I set this to for instance 10000, it returns the same "SubnetOversizeException" error. I cannot seem to avoid this error by increasing MAX_SUB_NET_SIZE but I can by reducing the max displacement value.

danielballan commented 4 years ago

Are you setting that parameter on a Linker instance or on the Linker class? Can you share a minimal code snippet showing you create and configure the linker?

joaomamede commented 2 years ago

Did you solve this? I have a massive 54 field panel to link and my max distance is very short for what is needed and I wanted to increase the sub net size and it doesn't matter how I increase it tp.link doesn't use the value stored in tp.linking.Linker.MAX_SUB_NET_SIZE

joaomamede commented 2 years ago

The max_sub_net_size,etc seem to be hardcoded into the Class linker().

I might be reading it wrong though.

    # Largest subnet we will attempt to solve.
    MAX_SUB_NET_SIZE = 30
    # For adaptive search, subnet linking should fail much faster.
    MAX_SUB_NET_SIZE_ADAPTIVE = 15
    # Maximum number of candidates per particle
    MAX_NEIGHBORS = 10

https://github.com/soft-matter/trackpy/blob/d69452d8cff273681b6f3a0e91773ef5b3c132b6/trackpy/linking/linking.py#L357

nkeim commented 2 years ago

It looks like they are class attributes, and the code ultimately passes the parameter to numba_link. Setting tp.linking.Linker.MAX_SUB_NET_SIZE and then calling e.g. tp.link() ought to work.

What kind of behavior are you getting that leads you to believe that this parameter isn’t used? Could MAX_NEIGHBORS be an issue?

The other thing to keep in mind is that the worst-case time to solve a subnet scales as the factorial of its size. So it’s very rare that you can solve a problem by increasing MAX_SUB_NET_SIZE, without making linking take forever. Have you looked at the adaptive search tutorial?

joaomamede commented 2 years ago

I am wrong btw. tp.linking.Linker.MAX_SUB_NET_SIZE and max_neighbors works.

I tried the adaptive, it still failed. (I hardcoded more max_candidates somewhere and somewhat increased what I could do, but not by much) Basically I'm trying to link viruses in a 9x6 panel with 5000particles in the sttiched imaging more than 30 pixels (6um) I can't link anymore. All Trackmate algorithm worked okay in Fiji with the dataset obtained from tp.locate that's what is bugging me.