I am investigating the motion of a single micrometer sized particle in a low density plasma. With a so called long distance microscope I have recorded the motion of a particle (2726 images, fps=60 Hz).
The x,y data in mm are available here: http://pastebin.com/qdMsaUHD
With mathematica I got the following log-log plot for the mean squared displacement (MSD):
I am new to Python and have searched for examples on how to read in the 2D coordinates from a file, calculate and display the MSD (mean and standard deviation).
I have seen that there are some answers which show how to calculate the MSD but I am not able to adapt them to my data.
I would appreciate very much if somebody could show me the full Python source code (with all imports) which is necessary to solve my problem.
That will be for me a great opportunity and a very concrete problem to start also programming with Python. Thank you very much in advance for your help.
I tried the following from one of the answers (Computing the mean square displacement of a 2d random walk in Python), but the code produced errors.
import numpy as np
import matplotlib.pyplot as plt
data= [[49.136926889715, 48.4423791821561],
[48.8104534783146, 51.0491783022365],
[48.5231487166892, 53.3485202014],
[48.2320069851565, 55.2569539728078],
[47.8817794028032, 56.993296770262],
[47.381875792142, 58.179721166033],
...
[45.3409434914228, 49.0259838546922]]
def compute_MSD(path):
totalsize=len(path)
msd=[]
for i in range(totalsize-1):
j=i+1
msd.append(np.sum((path[0:-j]-path[j::])**2)/float(totalsize-j))
msd=np.array(msd)
return msd
result=compute_MSD(data)
plt.plot(result)
plt.show()