compute_angular_time_derivative#
- movement.kinematics.compute_angular_time_derivative(data, order, window=None)[source]#
Compute the time-derivative of a 2D orientation.
The orientation is given as 2D vectors. Its rate of change is estimated from the signed angles between nearby orientation vectors, which avoids the spurious jumps that occur when angles wrap around at \(\pm\pi\) (see Notes).
- Parameters:
data (
DataArray) – The input orientation vectors, containingtimeandspaceas dimensions.spacemust have exactly the coordinates["x", "y"]. The vectors need not be of unit length.order (
int) – The order of the time-derivative. Use 1 for angular velocity and 2 for angular acceleration. Must be a positive integer.window (
int|None) – IfNone(default), the derivative 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 polynomial is fitted (see Notes). Must be an odd integer greater thanorder, and requires a uniformly sampledtimecoordinate.
- Returns:
The time-derivative of the orientation, in radians per unit of time (raised to the power of
order). It has the dimensions of the input, withoutspace.- Return type:
See also
compute_angular_velocityWrapper for
order=1.compute_angular_accelerationWrapper for
order=2.
Notes
Wrap-around. Differentiating angles directly produces spurious spikes wherever they wrap around at \(\pm\pi\). Instead, this function uses the
signed anglesbetween nearby orientations vectors. Withoutwindow,order=1is a central-difference estimate built from the angles between consecutive observations. As withnumpy.gradient(), it stays centred on each observation even when time steps are irregular. Higher orders differentiate that result further withcompute_time_derivative(). Withwindow, the angles are measured from the window’s centre orientation (see Windowed estimate). This assumes rotations of less than \(\pi\) between consecutive observations (or across half awindow). Undefined orientations (NaNs or zero-length vectors) are treated as NaN.Sign. Positive values are rotations from the positive x-axis towards the positive y-axis. In image coordinates (y pointing down) with a top-down camera, this is clockwise on screen.
Windowed estimate. With
window, the angles of the orientations in the window, relative to the centre one, are differentiated with Savitzky-Golay coefficients (scipy.signal.savgol_coeffs()). Fororder=1, this is the slope of a least-squares line over the window centred on each time point. It uses every observation in the window. The first and lastwindow // 2values are NaN, as are all outputs whose window contains a NaN. For a window ending on each time point, shift the result bywindow // 2time steps.Preprocessing. Smooth, interpolate, or resample the orientation vectors, not their angles, since angle averages are wrong near \(\pm\pi\). Windowed estimates require uniform sampling, so make sure to resample irregularly sampled data onto a uniform
timegrid first, e.g. withxarray.DataArray.interp()on the vectors.