python - Calculating MSD of a Brownian particle using trackpy vs manually - Stack Overflow

I am trying to understand the trackpy algorithm for calculating MSD in comparison to a simple manual me

I am trying to understand the trackpy algorithm for calculating MSD in comparison to a simple manual method of calculating it. My intention is to use trackpy to analyze the tracks of Brownian diffusing particles captured on video.

I first generate the trajectory of a 2D Brownian diffusing particle using the following code:

#time interval for steps (comparable to camera  fps)
dt = 1/485                             
#total measurement time (comparable to video length)
totalT = 4850                         
#Theoretical diffusion constant for a particle of  size 30nm
diffC = 16e-12           
              
track = np.zeros((totalT,3))

for i in range(1,len(track)):
    track[i,0] = track[i-1,0]+dt
    track[i,1] = track[i-1,1] + np.sqrt(2*diffC*dt)*np.random.normal(0,1)
    track[i,2] = track[i-1,2] + np.sqrt(2*diffC*dt)*np.random.normal(0,1) 

I then manually calculate the MSD over all possible time intervals using the following code:

MSD = np.zeros((len(track),4))

for tau in range(1,len(track)):
    step = 1
    displacements = track[0:-tau:step,1:]-track[tau::step,1:]
    MSD[tau,0] = tau*dt
    MSD[tau,1] = np.mean(displacements[:,0]**2)-np.mean(displacements[:,0])**2
    MSD[tau,2] = np.mean(displacements[:,1]**2)-np.mean(displacements[:,1])**2
    MSD[tau,3] = MSD[tau, 1] + MSD[tau, 2]

I then used trackpy to compute the MSD using tp.motion.msd.

My results:

  1. By changing the max_lagtime parameter on trackpy (which represents the maximum time lag considered for the MSD in number of frames), I was able to get a linear relationship between the MSD and time lag. trackpy also computed the exact diffusion constant that I used to generate the trajectories.

  2. My manual calculation of the MSD (detailed in the code block above) does not give me a linear relationship between MSD and time lag and so I cannot obtain a diffusion constant value from it.

My question:
Since the number of datapoints are exactly the same in both methods, I am not able to see why my manual method should not give me a linear relationship between the MSD and time lag. Does this mean that the trackpy algorithm is doing something unreliable with the data? Or is there something fundamentally wrong with my manual calculation?

PS: I have gone through the trackpy documentation and from what I understand, it is using an FFT to compute the MSD in my case (there are no skipped frames). This should be a faster method, but not necessarily a more accurate one if I understand it correctly.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744840350a4596519.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信