[trackingdata] implement a bendedness function
This commit is contained in:
parent
6d288aace1
commit
f62c7c43e0
@ -171,16 +171,30 @@ class TrackingData(QObject):
|
||||
return orientations
|
||||
|
||||
def bendedness(self, bodyaxis=None):
|
||||
"""
|
||||
Calculate the bendedness of the body axis.
|
||||
Parameters
|
||||
----------
|
||||
bodyaxis : list of int, optional
|
||||
Indices of the body axis coordinates to consider. If None, defaults to [0, 1, 2, 5].
|
||||
Returns
|
||||
-------
|
||||
numpy.ndarray
|
||||
Array of mean absolute deviations of the body axis points from the head-tail vector.
|
||||
"""
|
||||
|
||||
if bodyaxis is None:
|
||||
bodyaxis = [0, 1, 2, 5]
|
||||
bodycoords = self.coordinates()[:, bodyaxis, :]
|
||||
bodycoords = np.concat((bodycoords, np.zeros((bodycoords.shape[0], len(bodyaxis), 1))), axis=2)
|
||||
head_tail_vector = bodycoords[:, -1, :] - bodycoords[:, 0, :]
|
||||
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
|
||||
point_axis_vector = bodycoords[:,:,:] - bodycoords[:, 0, :][:,np.newaxis,:]
|
||||
htv = head_tail_vector[:,np.newaxis, :]
|
||||
# Pythagoras, length of head- tail connection
|
||||
head_tail_length = np.linalg.norm(head_tail_vector, axis=1, keepdims=True)
|
||||
deviations = np.cross(htv, point_axis_vector)[:,:,-1] / head_tail_length
|
||||
deviations = np.mean(np.abs(deviations), axis=1)
|
||||
return deviations
|
||||
|
||||
def __getitem__(self, key):
|
||||
return self._data[key]
|
||||
@ -236,8 +250,8 @@ def main():
|
||||
lengths = data.animalLength()
|
||||
frames = data["frame"]
|
||||
tracks = data["track"]
|
||||
|
||||
# bendedness = data.bendedness()
|
||||
bendedness = data.bendedness()
|
||||
|
||||
|
||||
embed()
|
||||
tracks = data["track"]
|
||||
|
Loading…
Reference in New Issue
Block a user