neuroinformatics-unit / movement

Python tools for analysing body movements across space and time
http://movement.neuroinformatics.dev
BSD 3-Clause "New" or "Revised" License
77 stars 7 forks source link

Rethink definition of displacement vector #136

Open sfmig opened 3 months ago

sfmig commented 3 months ago

Right now the displacement vector at t is defined as the vector from t-1 to t. For the first frame, it is defined as the zero vector.

Although this naturally derives from the diff operator, it does feel a bit awkward for example when you want to visually check the displacement vector. Right now, you would typically use a quiver plot, in which at each position t of the trajectory you plot the negative of the displacement vector at t. In this way, the resulting vector at t points to the previous position at t-1, and you can visually check the data behaves as you expect.

Plotting the _negative_displacement vector seems slightly cumbersome and adds to the mental load of things to remember about the data. It may show that a more useful definition of the displacement vector would be "the vector at t that goes from the position at t to the position at t+1". This would make for an easy visual check with quiver plot, and seems like an easier mental model to have of the data. For the last frame, we would define it as the zero vector.

lochhh commented 3 months ago

There's no need to plot the negative displacement. pivot would get us what we want:

# plot displacement vectors: at t, vector from t-1 to t
ax.quiver(
    pose_tracks.sel(individuals=mouse_name, space="x"),
    pose_tracks.sel(individuals=mouse_name, space="y"),
    displacement.sel(individuals=mouse_name, space="x"),
    displacement.sel(individuals=mouse_name, space="y"),
    angles="xy",
    scale=1,
    scale_units="xy",
    headwidth=7,
    headlength=9,
    headaxislength=9,
    pivot="tip",
)
sfmig commented 3 months ago

yes, I was aware of this option too 😁 My point is that it is a bit more intuitive to think displacement as t to t+1