Skip to content

Commit 9e87735

Browse files
authored
Issue #213: Project invalid trajectories inside walkable area (#506)
* added preprocessing and trajectory_projector * edited user guide, added test file * Fixed Float_Precision Problem and added tests * new distance calculation function * errors for false parameters, better structure, method for catching incorrect adjustments * Added Errors for Exceptions * Finished documentation * changed list structure for geo_data into dataframes * Fixed Docstring Notation * Updated min_ - / max_distance to user_guide * Symlinks describtion for Windows User in developeter guide * Fixed import statements * added a visualization for the min-/max-distance parameters * Improved the plot for showing preprocessing parameters * adapted init so tests run through
1 parent 29f9126 commit 9e87735

File tree

8 files changed

+63316
-381
lines changed

8 files changed

+63316
-381
lines changed

docs/source/developer_guide.rst

Lines changed: 390 additions & 381 deletions
Large diffs are not rendered by default.
627 KB
Loading

notebooks/user_guide.ipynb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"execution_count": null,
66
"metadata": {
77
"jupyter": {
8+
"is_executing": true,
89
"outputs_hidden": false
910
},
1011
"tags": [
@@ -891,6 +892,67 @@
891892
"get_invalid_trajectory(traj_data=traj, walkable_area=walkable_area_faulty)"
892893
]
893894
},
895+
{
896+
"cell_type": "markdown",
897+
"metadata": {},
898+
"source": [
899+
"## Preprocessing\n",
900+
"\n",
901+
"\n",
902+
"### Trajectory Projector\n",
903+
"\n",
904+
"When working with head trajectories, participants may occasionally lean over obstacles. As a result, their trajectories can leave the walkable area for some frames, and this data cannot be processed by PedPy.\n",
905+
"\n",
906+
"To address this, there is a function that moves trajectory points that lay inside a wall or too close to it. The distance that should remain between the point and the wall afterwards is calculated by linear interpolation. The new distance lies within the interval between min_distance and max_distance:\n",
907+
"\n",
908+
"$$\n",
909+
"d' = (d-b)*{(e-s) \\over (e-b)}+s\n",
910+
"$$\n",
911+
"\n",
912+
"- d' is the new distance to the wall\n",
913+
"- d is the original distance to the wall\n",
914+
"- b corresponds to back_distance\n",
915+
"- s corresponds to min_distance\n",
916+
"- e corresponds to max_distance\n",
917+
"\n",
918+
"```{eval-rst}\n",
919+
".. figure:: images/parameters_preprocessing.png\n",
920+
" :width: 400px\n",
921+
" :align: center\n",
922+
"```\n",
923+
"\n",
924+
"If a point lies inside the geometry or too close to it, it will be pushed outward. The distance interval for these points starts at back_distance, which must be negative because it represents the maximum depth inside the wall, and ends at max_distance. Points located deeper inside an obstacle are assigned a smaller new distance than points located near the boundary of the interval.\n",
925+
"\n",
926+
"For example, a point, which lays deep inside an obstacle will receive a new distance close to min_distance, which represents the minimum possible value for new_distance. A point that is already outside the obstacle but needs to be adjusted for smoother results will also receive a new distance, but this value will be only slightly larger than its original distance.\n",
927+
"\n",
928+
"It is essential that max_distance is larger than min_distance, and that back_distance is negative. Depending on the geometry and the parameter values, it can also be beneficial to buffer the geometry beforehand to create thicker walls. If the walls are too thin, the function may accidentally move a point to the wrong side.\n",
929+
"\n",
930+
"The function returns a pedpy.TrajectoryData, either the corrected version of the trajectory or the\n",
931+
" original trajectory, if the original trajectory was valid.\n",
932+
"\n"
933+
]
934+
},
935+
{
936+
"cell_type": "code",
937+
"execution_count": null,
938+
"metadata": {
939+
"jupyter": {
940+
"is_executing": true
941+
}
942+
},
943+
"outputs": [],
944+
"source": [
945+
"from pedpy import correct_invalid_trajectories\n",
946+
"\n",
947+
"valid_trajectory = correct_invalid_trajectories(\n",
948+
" trajectory_data=traj,\n",
949+
" walkable_area=walkable_area,\n",
950+
" min_distance_obst=0.01,\n",
951+
" max_distance_obst=0.05,\n",
952+
" back_distance_obst=-0.5,\n",
953+
")"
954+
]
955+
},
894956
{
895957
"cell_type": "markdown",
896958
"metadata": {},

pedpy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
plot_voronoi_cells,
150150
plot_walkable_area,
151151
)
152+
from .preprocessing.trajectory_projector import correct_invalid_trajectories
152153

153154
__all__ = [ # noqa: RUF022 disable sorting of __all__ for better maintenance
154155
"AxisAlignedMeasurementArea",
@@ -210,6 +211,7 @@
210211
"compute_individual_acceleration",
211212
"compute_mean_acceleration_per_frame",
212213
"compute_voronoi_acceleration",
214+
"correct_invalid_trajectories",
213215
"PEDPY_BLUE",
214216
"PEDPY_GREEN",
215217
"PEDPY_GREY",

0 commit comments

Comments
 (0)