compute_angular_velocity#

movement.kinematics.compute_angular_velocity(data, window=None, in_degrees=False)[source]#

Compute the angular velocity of a 2D orientation.

The orientation is given as 2D vectors, e.g. the output of compute_forward_vector().

Parameters:
  • data (DataArray) – The input orientation vectors, containing time and space as dimensions. space must have exactly the coordinates ["x", "y"]. The vectors need not be of unit length.

  • window (int | None) – If None (default), the angular velocity is computed with central differences (one-sided at the first and last observations). Otherwise, the size of the centred rolling window, representing the fixed number of observations to which a least-squares line is fitted; the angular velocity is its slope. Must be an odd integer greater than 1, and requires a uniformly sampled time coordinate.

  • in_degrees (bool) – If False (default), the output is in radians per unit of time. If True, it is in degrees per unit of time.

Returns:

The angular velocity, with the dimensions of the input, without space. The unit of time is that of the time coordinate (seconds or frames).

Return type:

DataArray

See also

compute_angular_time_derivative

The underlying function used.

compute_angular_acceleration

The second time-derivative of orientation.

Examples

>>> from movement.kinematics import (
...     compute_angular_velocity,
...     compute_forward_vector,
... )
>>> head_vector = compute_forward_vector(
...     ds.position, "left_ear", "right_ear"
... )

Central-difference angular head velocity:

>>> ahv = compute_angular_velocity(head_vector)

Least-squares estimate over the 7 observations centred on each time point, in degrees per unit of time:

>>> ahv = compute_angular_velocity(head_vector, window=7, in_degrees=True)

Shift the above estimate by half a window to get a trailing estimate, using only the 7 observations up to and including each time point, in radians per unit of time:

>>> ahv_trailing = compute_angular_velocity(head_vector, window=7).shift(
...     time=7 // 2
... )

Examples using compute_angular_velocity#

Compute angular velocity and acceleration

Compute angular velocity and acceleration