最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论