soft-matter / trackpy

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

issue in Imsd results #705

Open Alex-code-lab opened 2 years ago

Alex-code-lab commented 2 years ago

Hello everyone,

I'm working on tracking cells during 1 hour. I need to plot msd, so I'm using the imsd function.

However, some results are strange. So I decided to code my own msd function :

def msd_tot_perso_mieu ( Traj, lag_time, experiment_time) :
    msd = pd.DataFrame(index = list(range(lag_time,experiment_time,lag_time)))
    msd = pd.DataFrame(index = list(range(30,30*33,30)))

    # msd['lag_time'] = list(range(30,30*35,30))(.set_index('column') pour modifier plus tard)

    for num in range(0,max(Traj['particle'].values)+1):
        if len(Traj[Traj['particle']==num])==0 : continue;
        msd['part_{}'.format(num)] = [0]*32

        for i in range(1,33) : 
            XT = Traj[Traj['particle']==num]['x'].shift(0)
            YT = Traj[Traj['particle']==num]['y'].shift(0)  
            XTi = Traj[Traj['particle']==num]['x'].shift(-i)
            YTi = Traj[Traj['particle']==num]['y'].shift(-i)
            # delta_t = (time_frame/60)*(Traj.groupby(['particle'])['frame'].shift(-1)-Traj.groupby(['particle'])['frame'].shift(0))
            msd['part_{}'.format(num)][30*i] = np.nanmean((((XT-XTi)*micronperpixel)**2  +  (((YT-YTi))*micronperpixel)**2))# ou .mean()
        msd['part_{}'.format(num)].dropna()

I know that it's note the most beautiful function ever, but I'm new with pandas so I did my best.

Here is my issue : the results with IMSD function and this function are really different for my tracking.

Is it possible that IMSD does't take in account that some particles might go out and go in in different frames?

That's what it seems like, but I don't understant very well the code under Imsd.

If my function is right, I think it could be a real problem for some people, so I share this observation.

Thank you everyone,

Alex