Skip to content

Commit

Permalink
remove first jump frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanharvey1 committed Feb 3, 2025
1 parent 0f3e7f1 commit fe8686c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions neuro_py/behavior/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def filter_tracker_jumps(
Returns
-------
pd.DataFrame
Notes
-----
Will force dtypes of x and y to float64
"""

# Calculate the Euclidean distance between consecutive points
Expand All @@ -37,10 +41,17 @@ def filter_tracker_jumps(
# Calculate the speed between consecutive points (distance / time)
beh_df["speed"] = beh_df["distance"] / beh_df["dt"]

# Mark x and y as NaN where the speed exceeds the maximum allowed speed
beh_df.loc[beh_df["speed"] > max_speed, ["x", "y"]] = np.nan
# Identify the start of each jump
# A jump starts when the speed exceeds the threshold, and the previous speed did not
jump_starts = (beh_df["speed"] > max_speed) & (
beh_df["speed"].shift(1) <= max_speed
)

# Mark x and y as NaN only for the first frame of each jump
beh_df.loc[jump_starts, ["x", "y"]] = np.nan

beh_df = beh_df.drop(columns=["dx", "dy", "distance", "dt", "speed"])

return beh_df


Expand Down

0 comments on commit fe8686c

Please sign in to comment.