soft-matter / trackpy

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

`memory` not stable between runs #776

Open freemansw1 opened 4 weeks ago

freemansw1 commented 4 weeks ago

It seems that memory, under certain conditions, is not stable/deterministic. I've put an example below. At some times, the value of particle at index 10 is 3, and at others it is 4. Both are reasonable choices, but it should always select one or the other, not both.

I've tried to dig into the source code with an eye to a PR, but frankly I'm struggling to understand how the memory module works. I'm happy to put some effort into a PR, but need a bit more insight there before putting one together.

I'm on an M2 Mac, Python 3.12.7, trackpy version 0.6.4.

import pandas as pd
import trackpy
import numpy as np

y_coords = [2, 3, 0, 10, 3, 1, 11, 4, 1, 2, 12, 5, 0]
x_coords = [3, 4, 4, 14, 4, 5, 15, 5, 2, 6, 16, 6, 1]
frame =    [2, 2, 2,  2, 3, 3,  3, 4, 4, 4,  4, 5, 5]

trackpy_df = pd.DataFrame({"y": y_coords, "x": x_coords, "frame": frame})
pred = trackpy.predict.NearestVelocityPredict(                
        initial_guess_positions=[[1,2],[4,5]],
        initial_guess_vels=[[1,1],[-1,-1]],
        pos_columns=['y', 'x'],
        span=1,
)
out = pred.link_df(trackpy_df, search_range = 1.8, memory=1, t_column="frame", neighbor_strategy="BTree",
                adaptive_step=None,
                adaptive_stop=None,
)