dbeab7509cfec1314b6529d57fbd090ce744695c,trackpy/motion.py,,compute_drift,#Any#Any#Any#,237

Before Change


        pos_columns = ["x", "y"]
    // the groupby...diff works only if the trajectory Dataframe is sorted along frame
    // I do here a copy because a "inplace=True" would sort the original "traj" which is perhaps unwanted/unexpected
    traj = pandas_sort(traj, "frame")
    // Probe by particle, take the difference between frames.
    delta = traj.groupby("particle", sort=False).apply(lambda x :
                                    x.set_index("frame", drop=False).diff())
    // Keep only deltas between frames that are consecutive.
    delta = delta[delta["frame"] == 1]
    // Restore the original frame column (replacing delta frame).
    del delta["frame"]
    delta.reset_index("particle", drop=True, inplace=True)
    delta.reset_index("frame", drop=False, inplace=True)
    dx = delta.groupby("frame").mean()
    if smoothing > 0:
        dx = pd.rolling_mean(dx, smoothing, min_periods=0)
    x = dx.cumsum(0)[pos_columns]
    return x


def subtract_drift(traj, drift=None, inplace=False):
    Return a copy of particle trajectories with the overall drift subtracted

After Change


    
    if pos_columns is None:
        pos_columns = ["x", "y"]
    f_sort = traj.sort_values(["particle", "frame"])

    // Compute the difference list of positions, particle, and frame columns.
    f_diff = f_sort[list(pos_columns) + ["particle", "frame"]].diff()

    // Rename the frame column and insert the original frame column back in.
    f_diff.rename(columns={"frame": "frame_diff"}, inplace=True)
    f_diff["frame"] = f_sort["frame"]

    // Compute the per frame averages. Keep only deltas of the same particle,
    // and between frames that are consecutive, and of the same particle.
    mask = (f_diff["particle"] == 0) & (f_diff["frame_diff"] == 1)
    dx = f_diff.loc[mask, pos_columns + ["frame"]].groupby("frame").mean()
    if smoothing > 0:
        dx = pd.rolling_mean(dx, smoothing, min_periods=0)
    return dx.cumsum()


def subtract_drift(traj, drift=None, inplace=False):
    Return a copy of particle trajectories with the overall drift subtracted
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 5

Instances


Project Name: soft-matter/trackpy
Commit Name: dbeab7509cfec1314b6529d57fbd090ce744695c
Time: 2017-07-27
Author: caspervdw@gmail.com
File Name: trackpy/motion.py
Class Name:
Method Name: compute_drift


Project Name: sympy/sympy
Commit Name: a732984b582e2869665c6448d35cad2c4178ad94
Time: 2021-02-09
Author: harshityadav2k@gmail.com
File Name: sympy/concrete/products.py
Class Name: Product
Method Name: _eval_derivative


Project Name: AIRLab-POLIMI/mushroom
Commit Name: 8de90b2a3760fad7d007399b4a94087900ae82c8
Time: 2017-10-20
Author: boris.ilpossente@hotmail.it
File Name: mushroom/policy/normal_policy.py
Class Name: NormalPolicy
Method Name: diff_log