Skip to content

Handling near-zero steps in compute_turning_angle: alternatives to the current default #957

@niksirbi

Description

@niksirbi

In PR #833 we added a compute_turning_angle function (see API docs).

That function accepts an optional min_step_length=0.0 argument:

The minimum step length to consider for computing the turning angle. Any turning angle involving an incoming or outgoing step shorter than or equal to this value is set to NaN. The default 0.0 only masks steps with exactly zero length, which means steps with near-zero lengths may still produce spurious angles. See Note 2 below.

The aforementioned Note 2:

  1. Positional jitter and small steps: Tracking data often contains positional jitter, meaning a stationary animal may appear to make microscopic movements. With default parameters (min_step_length=0.0), these tiny, noisy movements will produce spurious, meaningless turning angles. It is highly recommended to set min_step_length to an appropriate threshold based on the tracking resolution and the animal's size in the scene. The value should be in the same units as the input position data (e.g. pixels, mm, etc.). Pre-smoothing the trajectory can also help reduce positional jitter.

I've kept the default as 0.0, even though it's not a good choice in most cases (as documented in the docstring). The problem is that any small positive value would be entirely arbitrary: we ultimately can't know what step length is small enough to render a computed heading meaningless, since that's domain-specific — it depends on video resolution, data units (pixels, mm, etc.), animal size in the scene, tracking quality, use of smoothing, and so on.

I merged #833 despite these reservations, since the implementation is sound, well-documented, and tested. This issue is a place to discuss alternatives to the current approach.

Some alternatives:

  • Make min_step_length a required argument. This forces users to make a conscious choice, but may deter newcomers and makes the function harder to use out of the box. There's also a design question: trajectory complexity metric functions are planned to call compute_turning_angle internally—should the requirement propagate up to those functions too?
  • Keep min_step_length optional, but change the default to 'auto', which would trigger heuristic-based threshold estimation—for example, something derived from the distribution of step lengths. The open question is whether a reliable heuristic exists that generalises well across use cases.

Note

Other ideas welcome. This is a discussion issue, not a call for PRs; at least not until we've converged on a workable approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    Status

    🤔 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions