compute_path_emax#
- movement.kinematics.compute_path_emax(data, in_spatial_units=True, nan_warn_threshold=0.2)[source]#
Compute the maximum expected displacement (\(E_{\max}\)).
\(E_{\max}\) is a straightness measure that captures the directional persistence of a path. Intuitively, it is the maximum expected displacement of an animal navigating without an external directional reference (e.g. a compass or a landmark), given the observed distribution of its turning angles and step lengths [1]. Larger values indicate straighter, more persistent paths; values close to zero indicate sinuous paths.
Two variants are available. The dimensionless variant \(E_{\max}^{(a)}\) depends only on the turning angles:
\[E_{\max}^{(a)} = \frac{\bar{c}}{1 - \bar{c}}, \qquad \bar{c} = \overline{\cos\theta}\]where \(\theta\) are the turning angles and \(\bar{c}\) is their mean cosine. The variant \(E_{\max}^{(b)}\) scales this by the mean step length \(\bar{p}\) to express the result in the same spatial units as the input:
\[E_{\max}^{(b)} = \bar{p} \, E_{\max}^{(a)}\]- Parameters:
data (
DataArray) – The input data containing position information, withtimeandspace(in Cartesian coordinates) as required dimensions.in_spatial_units (
bool) – IfTrue(the default), return the dimensioned variant \(E_{\max}^{(b)}\), expressed in the same spatial units asdata. IfFalse, return the dimensionless variant \(E_{\max}^{(a)}\).nan_warn_threshold (
float) – If any point track in the data has at least (\(\ge\)) this proportion of values missing, a warning will be emitted. Defaults to 0.2 (20%).
- Returns:
The maximum expected displacement, with dimensions matching those of the input data, except
timeandspaceare removed. Whenin_spatial_unitsisTruethe values are in the same spatial units asdata; otherwise they are dimensionless.- Return type:
See also
compute_turning_angleThe underlying function used to compute the turning angles.
compute_path_sinuosityA related turning-angle-based measure of path tortuosity.
compute_path_straightnessA related, path-length-based measure of straightness.
Notes
Mean cosine of the turning angles. \(\bar{c} = \overline{\cos\theta}\) is the
timeaverage (ignoringNaNvalues) of the cosine of the turning angles \(\theta\) returned bycompute_turning_angle(). The first two time steps have no defined turning angle and so do not contribute.Range. \(E_{\max}^{(a)} \in [-0.5, \infty)\). While highly sinuous paths actually have values approaching 0, negative values specifically arise for trajectories with a systematic backward-turning bias where the mean cosine \(\bar{c}\) is itself negative.
Straight paths. As a path approaches a perfectly straight line, \(\bar{c} \to 1\), so \(1 - \bar{c} \to 0\) and \(E_{\max} \to +\infty\). An infinite result is therefore the correct, expected output for a straight path.
Missing values. Turning angles and step lengths that are
NaN(e.g. from missing positions or stationary steps) are ignored when averaging. If every turning angle isNaN(e.g. a stationary track), the result isNaN.
References
Examples
>>> from movement.kinematics import compute_path_emax
Compute E_max from the centroid trajectory of a poses dataset
ds:>>> centroid = ds.position.mean(dim="keypoint") >>> emax = compute_path_emax(centroid)
Return the dimensionless variant instead:
>>> emax_a = compute_path_emax(centroid, in_spatial_units=False)
Compute over a specific time window:
>>> emax = compute_path_emax(centroid.sel(time=slice(0, 100)))