Skip to content

Commit 76d89f2

Browse files
committed
Add docstrings for intrusion and avoidance functions
Module docstring with paper reference, and per-function docstrings with the mathematical definitions (Eqs. 1 and 2 from Cordes et al. 2024), parameter descriptions, and return types. Follows the existing rst/math style used in other PedPy modules.
1 parent a74b582 commit 76d89f2

1 file changed

Lines changed: 43 additions & 15 deletions

File tree

pedpy/methods/dimensionless_number_calculator.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
"""We need a proper name here ..."""
1+
"""Dimensionless numbers for pedestrian crowd classification.
2+
3+
Implements the Intrusion number and Avoidance number defined in
4+
Cordes et al., PNAS Nexus 2024 (https://doi.org/10.1093/pnasnexus/pgae120).
5+
"""
26

37

48
from enum import Enum
@@ -37,18 +41,30 @@ def compute_intrusion(
3741
l_min: float = 0.2,
3842
method: IntrusionMethod = IntrusionMethod.SUM,
3943
) -> pandas.DataFrame:
40-
"""_summary_.
44+
r"""Compute the intrusion number for each pedestrian per frame.
45+
46+
The intrusion variable :math:`\mathcal{I}n_i` quantifies how much
47+
other agents encroach on pedestrian *i*'s personal space
48+
(Cordes et al. 2024, Eq. 1):
49+
50+
.. math::
51+
52+
\mathcal{I}n_i = \sum_{j \in \mathcal{N}_i}
53+
\left(\frac{r_\text{soc} - \ell_\text{min}}
54+
{r_{ij} - \ell_\text{min}}\right)^{k_I},
4155
42-
TODO add documentation here
56+
with :math:`k_I = 2`. The neighbor set :math:`\mathcal{N}_i` contains
57+
all agents *j* with :math:`r_{ij} \leq 3\,r_\text{soc}`.
4358
4459
Args:
45-
traj_data (TrajectoryData): _description_
46-
r_soc (float): _description_
47-
l_min (float): _description_
48-
method (IntrusionMethod, optional): _description_. Defaults to IntrusionMethod.SUM.
60+
traj_data (TrajectoryData): trajectory data to analyze
61+
r_soc (float): social radius in m (default 0.8)
62+
l_min (float): pedestrian diameter in m (default 0.2)
63+
method (IntrusionMethod): aggregation over neighbors,
64+
``SUM`` (default, as in the paper) or ``MAX``
4965
5066
Returns:
51-
pandas.DataFrame: _description_
67+
DataFrame with columns 'id', 'frame', and 'intrusion'
5268
"""
5369
intrusion = _compute_individual_distances(traj_data=traj_data)
5470
intrusion = intrusion[intrusion.distance <= 3 * r_soc]
@@ -73,18 +89,30 @@ def compute_avoidance(
7389
radius: float = 0.2,
7490
tau_0: float,
7591
) -> pandas.DataFrame:
76-
"""_summary_.
92+
r"""Compute the avoidance number for each pedestrian per frame.
93+
94+
The avoidance variable :math:`\mathcal{A}v_i` quantifies the
95+
imminence of collisions that pedestrian *i* faces, based on
96+
the time-to-collision (TTC) with neighbors
97+
(Cordes et al. 2024, Eq. 2):
98+
99+
.. math::
100+
101+
\mathcal{A}v_i = \sum_{j \in \mathcal{N}'_i}
102+
\left(\frac{\tau_0}{\tau_{ij}}\right)^{k_A},
77103
78-
TODO add documentation here
104+
with :math:`k_A = 1`. The neighbor set :math:`\mathcal{N}'_i` is
105+
restricted to the agent with the shortest TTC :math:`\tau_{ij}`,
106+
implemented by taking the ``max`` over :math:`\tau_0 / \tau_{ij}`.
79107
80108
Args:
81-
traj_data (TrajectoryData): _description_
82-
frame_step (int): _description_
83-
radius (float): _description_
84-
tau_0 (float): _description_
109+
traj_data (TrajectoryData): trajectory data to analyze
110+
frame_step (int): number of frames used for velocity computation
111+
radius (float): combined disc radius for TTC in m (default 0.2)
112+
tau_0 (float): reference timescale in s (paper uses 3.0)
85113
86114
Returns:
87-
pandas.DataFrame: _description_
115+
DataFrame with columns 'id', 'frame', and 'avoidance'
88116
"""
89117
velocity = compute_individual_speed(
90118
traj_data=traj_data,

0 commit comments

Comments
 (0)