def trackmsd(track, dt0, dtau): """ trackmsd(track, dt0, dtau) finds the track msd, as function of tau, averaged over t0, for one track (worldline) """ trackdots = data[trackids==track] if dt0 == dtau == 1: if verbose: print "Using correlation" xy = np.column_stack([trackdots['x'], trackdots['y']]) return corr.msd(xy, ret_taus=True) trackbegin, trackend = trackdots['f'][[0,-1]] tracklen = trackend - trackbegin + 1 if verbose: print "tracklen =",tracklen print "\t from %d to %d"%(trackbegin, trackend) if isinstance(dtau, float): taus = helpy.farange(dt0, tracklen, dtau) elif isinstance(dtau, int): taus = xrange(dtau, tracklen, dtau) tmsd = [] for tau in taus: # for tau in T, by factor dtau #print "tau =", tau avg = t0avg(trackdots, tracklen, tau) #print "avg =", avg if avg > 0 and not np.isnan(avg): tmsd.append([tau,avg[0]]) if verbose: print "\t...actually", len(tmsd) return tmsd
def trackmsd(track, dt0, dtau): """ finds the mean squared displacement as a function of tau, averaged over t0, for one track (particle) parameters ---------- track : a single integer giving the track id to be calculated dt0 : spacing stepsize for values of t0, gives the number of starting points averaged over in `t0avg` dtau : spacing stepsize for values of tau, gives the spacing of the points in time at which the msd is evaluated For dt0, dtau: Small values will take longer to calculate without adding to the statistics. Large values calculate faster but give worse statistics. For the special case dt0 = dtau = 1, a correlation is used for a signicant speedup returns ------- a list of tuples (tau, msd(tau)) the value of tau and the mean squared displacement for a single track at that value of tau """ trackdots = data[trackids==track] if dt0 == dtau == 1: if verbose: print "Using correlation" xy = np.column_stack([trackdots['x'], trackdots['y']]) return corr.msd(xy, ret_taus=True) trackbegin, trackend = trackdots['f'][[0,-1]] tracklen = trackend - trackbegin + 1 if verbose: print "tracklen =",tracklen print "\t from %d to %d"%(trackbegin, trackend) if isinstance(dtau, float): taus = helpy.farange(dt0, tracklen, dtau) elif isinstance(dtau, int): taus = xrange(dtau, tracklen, dtau) tmsd = [] for tau in taus: # for tau in T, by factor dtau #print "tau =", tau avg = t0avg(trackdots, tracklen, tau) #print "avg =", avg if avg > 0 and not np.isnan(avg): tmsd.append([tau,avg[0]]) if verbose: print "\t...actually", len(tmsd) return tmsd
def trackmsd(trackset, dt0, dtau): """ finds the mean squared displacement as a function of tau, averaged over t0, for one track (particle) parameters ---------- trackset : a subset of the data for a given track dt0 : spacing stepsize for values of t0, gives the number of starting points averaged over in `t0avg` dtau : spacing stepsize for values of tau, gives the spacing of the points in time at which the msd is evaluated For dt0, dtau: Small values will take longer to calculate without adding to the statistics. Large values calculate faster but give worse statistics. For the special case dt0 = dtau = 1, a correlation is used for a signicant speedup returns ------- a list of tuples (tau, msd(tau)) the value of tau and the mean squared displacement for a single track at that value of tau """ if dt0 == dtau == 1: xy = helpy.consecutive_fields_view(trackset, 'xy') return corr.msd(xy, ret_taus=True) trackbegin, trackend = trackset['f'][[0,-1]] tracklen = trackend - trackbegin + 1 if verbose: print "length {} from {} to {}".format(tracklen, trackbegin, trackend) if isinstance(dtau, float): taus = helpy.farange(dt0, tracklen, dtau) elif isinstance(dtau, int): taus = xrange(dtau, tracklen, dtau) tmsd = [] for tau in taus: avg = t0avg(trackset, tracklen, tau) if avg > 0 and not np.isnan(avg): tmsd.append([tau,avg[0]]) if verbose: print "\t...actually", len(tmsd) return tmsd