-
Notifications
You must be signed in to change notification settings - Fork 141
Description
I have a question:
I was trying to compute drift for my imaging setup with some beads in order to measure the mechanical instability. After trying the compute_drift function, I noticed that the rolling average is applied before the cumulative sum (which seems right). But then I switched the order of operations and got a result which I do not really understand:
The scatter plot represents the computed drift without any rolling window average. I get the blue curve when I apply an average myself to the scattered points. The subsequent curves are what I get when I pass a finite smoothing parameter to the compute_drift. I don't understand what causes the offset (which mostly comes from the y-coordinate). Would appreciate the help.
Code for reference:
from trackpy.motion import compute_drift, subtract_drift
drift = compute_drift(df, 0, ['x_unrefined', 'y_unrefined'])
drift_rollingp5 = compute_drift(df, 10, ['x_unrefined', 'y_unrefined'])
drift_rolling = compute_drift(df, 20, ['x_unrefined', 'y_unrefined'])
drift_rolling2 = compute_drift(df, 40, ['x_unrefined', 'y_unrefined'])and,
fig, ax = plt.subplots(figsize=(10,10))
ax.scatter(drift.x_unrefined, drift.y_unrefined, c=drift.index, label="Ensemble drift")
ax.plot(drift.x_unrefined.rolling(20).mean(), drift.y_unrefined.rolling(20).mean(), c="blue", label=r"Rolling average after cumulative sum $1Hz$")
ax.plot(drift_rolling.x_unrefined, drift_rolling.y_unrefined, c="red", label=r"Rolling average (20) :: $1Hz$")
ax.plot(drift_rolling2.x_unrefined, drift_rolling2.y_unrefined, c="orange", label=r"Rolling average (40) :: $2Hz$")
ax.plot(drift_rollingp5.x_unrefined, drift_rollingp5.y_unrefined, c="maroon", label=r"Rolling average (10) :: $0.5Hz$")
plt.legend()