[trackingdata] implementation of bendedness

This commit is contained in:
Jan Grewe 2025-02-13 09:55:22 +01:00
parent bf7c37eb46
commit 6d288aace1

View File

@ -175,12 +175,11 @@ class TrackingData(QObject):
bodyaxis = [0, 1, 2, 5]
bodycoords = self.coordinates()[:, bodyaxis, :]
head_tail_vector = bodycoords[:, -1, :] - bodycoords[:, 0, :]
head_tail_length = np.linalg.norm(head_tail_vector, axis=1, keepdims=True)
normalized_head_tail_vector = head_tail_vector / head_tail_length
projections = np.einsum('ijk,ij->ik', bodycoords - bodycoords[:, 0, np.newaxis, :], normalized_head_tail_vector)
distances = np.linalg.norm(bodycoords - (bodycoords[:, 0, np.newaxis, :] + projections[:, :, np.newaxis] * normalized_head_tail_vector[:, np.newaxis, :]), axis=2)
deviation = np.mean(distances, axis=1)
head_tail_vector = head_tail_vector[:, np.newaxis ,:] # cross-product only defined in space, not in 2D
head_tail_length = np.linalg.norm(head_tail_vector, axis=1, keepdims=True) # pythagoras, length of head- tail connection
point_axis_vectors = bodycoords - head_tail_vector
deviations = np.cross(head_tail_vector, point_axis_vectors)/head_tail_length
deviation = np.mean(deviations, axis=1)
return deviation
def __getitem__(self, key):
@ -237,7 +236,8 @@ def main():
lengths = data.animalLength()
frames = data["frame"]
tracks = data["track"]
bendedness = data.bendedness()
# bendedness = data.bendedness()
embed()
tracks = data["track"]