66from graphomotor .core import models
77
88
9- def _get_velocity_metrics (velocity : np .ndarray , type_ : str ) -> dict [str , float ]:
9+ def _get_velocity_statistics (velocity : np .ndarray , type_ : str ) -> dict [str , float ]:
1010 """Calculate velocity metrics for a given type of velocity.
1111
1212 Args:
@@ -19,6 +19,7 @@ def _get_velocity_metrics(velocity: np.ndarray, type_: str) -> dict[str, float]:
1919 """
2020 return {
2121 f"{ type_ } _sum" : np .sum (np .abs (velocity )),
22+ f"{ type_ } _median" : np .median (np .abs (velocity )),
2223 f"{ type_ } _variation" : stats .variation (velocity ),
2324 f"{ type_ } _skewness" : stats .skew (velocity ),
2425 f"{ type_ } _kurtosis" : stats .kurtosis (velocity ),
@@ -34,18 +35,17 @@ def calculate_velocity_metrics(spiral: models.Spiral) -> dict[str, float]:
3435 1. Linear velocity: The magnitude of change of Euclidean distance in pixels
3536 per second. This is calculated as the square root of the sum of squares of
3637 the differences in x and y coordinates divided by the difference in time.
37- 2. Radial velocity: The magnitude of change of distance from center in pixels
38- per second. Radius is calculated as the square root of the sum of squares of
39- the x and y coordinates. The radial velocity is the change in radius divided
40- by the change in time.
38+ 2. Radial velocity: The magnitude of change of distance from center (radius) in
39+ pixels per second. Radius is calculated as the square root of the sum of
40+ squares of x and y coordinates.
4141 3. Angular velocity: The magnitude of change of angle in radians per second.
4242 Angle is calculated using the arctangent of y coordinates divided by x
43- coordinates. It is assumed that the drawing starts in the first quadrant
44- The angle is unwrapped to ensure continuity. The angular
45- velocity is the change in angle divided by the change in time.
43+ coordinates, and then unwrapped to maintain continuity across the -π to π
44+ boundary.
4645
4746 For each velocity type, the following metrics are calculated:
48- - Sum: Sum of absolute velocity values
47+ - Sum: Total absolute velocity over the entire drawing
48+ - Median: Median of absolute velocity values
4949 - Variation: Coefficient of variation
5050 - Skewness: Asymmetry of the velocity distribution
5151 - Kurtosis: Tailedness of the velocity distribution
@@ -68,20 +68,12 @@ def calculate_velocity_metrics(spiral: models.Spiral) -> dict[str, float]:
6868 dr = np .diff (radius )
6969 dtheta = np .diff (theta )
7070
71- vx = dx / dt
72- vy = dy / dt
73- linear_velocity = np .sqrt (vx ** 2 + vy ** 2 )
74-
71+ linear_velocity = np .sqrt (dx ** 2 + dy ** 2 ) / dt
7572 radial_velocity = dr / dt
7673 angular_velocity = dtheta / dt
7774
78- linear_velocity_metrics = _get_velocity_metrics (linear_velocity , "linear_velocity" )
79- radial_velocity_metrics = _get_velocity_metrics (radial_velocity , "radial_velocity" )
80- angular_velocity_metrics = _get_velocity_metrics (
81- angular_velocity , "angular_velocity"
82- )
8375 return {
84- ** linear_velocity_metrics ,
85- ** radial_velocity_metrics ,
86- ** angular_velocity_metrics ,
76+ ** _get_velocity_statistics ( linear_velocity , "linear_velocity" ) ,
77+ ** _get_velocity_statistics ( radial_velocity , "radial_velocity" ) ,
78+ ** _get_velocity_statistics ( angular_velocity , "angular_velocity" ) ,
8779 }
0 commit comments