compute_directional_change#
- movement.kinematics.compute_directional_change(data, in_degrees=False, min_step_length=0.0)[source]#
Compute the directional change (DC) per time step.
The directional change at step \(i\) is the absolute turning angle divided by the temporal interval spanning the two steps that define it [1]:
\[\mathrm{DC}_i = \frac{|\theta_i|}{\Delta t_i}\]where \(\theta_i\) is the signed turning angle at step \(i\) and \(\Delta t_i = t_i - t_{i-2}\).
- Parameters:
data (
DataArray) – The input data containing position information, withtimeandspace(in Cartesian coordinates) as required dimensions.in_degrees (
bool) – IfTrue, the turning angles (and hence the directional change) are expressed in degrees rather than radians. Defaults toFalse.min_step_length (
float) – The minimum step length used when computing turning angles. Steps shorter than or equal to this value produceNaNturning angles, which propagate toNaNdirectional change values. The default0.0only masks steps with exactly zero length; near-zero steps from positional jitter may still produce spurious turning angles. Seecompute_turning_angle()for details.
- Returns:
Directional change values with the same dimensions as the input, except
spaceis removed. Values are in radians pertimeunit (e.g. radians/second iftimeis in seconds), or degrees pertimeunit ifin_degreesisTrue.- Return type:
Notes
Boundary behaviour: The first two time steps of the output are always
NaN, because a turning angle requires three consecutive positions (seecompute_turning_angle()).References
See also
compute_turning_angleThe underlying function used to compute turning angles.
Examples
>>> from movement.kinematics import compute_directional_change
Compute directional change from the centroid trajectory of a poses dataset
ds:>>> centroid = ds.position.mean(dim="keypoint") >>> dc = compute_directional_change(centroid)
Compute over a specific time window:
>>> dc = compute_directional_change(centroid.sel(time=slice(0, 100)))
Filter out pose-estimation jitter by setting
min_step_length:>>> dc = compute_directional_change(centroid, min_step_length=3)