Skip to content

Preprocessing: Added functions for outlier and anomaly detection.#535

Open
awestphal1 wants to merge 39 commits intoPedestrianDynamics:mainfrom
awestphal1:main
Open

Preprocessing: Added functions for outlier and anomaly detection.#535
awestphal1 wants to merge 39 commits intoPedestrianDynamics:mainfrom
awestphal1:main

Conversation

@awestphal1
Copy link
Copy Markdown
Collaborator

Closes #529

Sometimes, due to tracking problems, anomalies occur in the trajectory data, such as outliers or vertical displacements, where the tracker loses the person and continues tracking something else instead.

The function detects and handles such anomalies by correcting outliers and cropping the trajectory data of a single person ID if a displacement is found.

image

The blue line is the original trajectory, the red one the corrected one.

awestphal1 and others added 30 commits November 13, 2025 11:34
Copy link
Copy Markdown
Collaborator

@JuleAdrian JuleAdrian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments concerning the notebook.
I could not check all details of the maths, but we discussed about it and according to your examples, it seems to work.

"for i in range(len(changed_index_orig)):\n",
" original_trajectory = trajectory_data.data[trajectory_data.data[\"id\"] == changed_index_orig[i]]\n",
" trajectory_corrected = trajectory_data_corrected.data[trajectory_data_corrected.data[\"id\"] == changed_index_new[i]]\n",
" pedpy.plot_trajectories(\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments about the plots being made:

  • Can you choose PedPy colors?
  • The colors you chose have not enough contrast. At least on my screen, I cannot really distinguish between black and blue trajectories (see attached example). Please adjust the colors.
  • Please include a legend (which color represents what?)
  • Idea: Include titles to the plots stating which type of error wad detected.
Image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I tried to find a combination of two PedPy colors, that works with light- and with darkmode. I did not add a title, because depending on the parameters a trajectory could have outliers and a displacement later, so it is difficult to define a clear type.

" max_distance_wall=0.05,\n",
" back_distance_wall=-0.5,\n",
")\n",
"print(\"Valid after: \", pedpy.is_trajectory_valid(traj_data=valid_trajectory, walkable_area=walk_area))"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to include two plots, the not corrected and the corrected trajectories.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added two exemplary plots to give an idea of how the function modifies the trajectory. I will add a plotting function to the notebook, similar to the one used for outlier detection, when I include a list of modified person IDs in the return values.

"metadata": {},
"outputs": [],
"source": [
"traj_data_low_tolerance = pedpy.detect_anomalies_in_trajectories(\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the description above, it is not clear what the parameters do that you use in this example. Can you include parameters that you use in the description?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@schroedtert schroedtert added this to the v1.5.0 milestone May 3, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 98.61751% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.47%. Comparing base (ee8668f) to head (f64e8f2).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...edpy/preprocessing/trajectory_outlier_detection.py 98.61% 3 Missing ⚠️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect and correct outliers in trajectories

3 participants