[trackingdata] implement a bendedness function
This commit is contained in:
parent
6d288aace1
commit
f62c7c43e0
@ -171,16 +171,30 @@ class TrackingData(QObject):
|
|||||||
return orientations
|
return orientations
|
||||||
|
|
||||||
def bendedness(self, bodyaxis=None):
|
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:
|
if bodyaxis is None:
|
||||||
bodyaxis = [0, 1, 2, 5]
|
bodyaxis = [0, 1, 2, 5]
|
||||||
bodycoords = self.coordinates()[:, bodyaxis, :]
|
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 = bodycoords[:, -1, :] - bodycoords[:, 0, :]
|
||||||
head_tail_vector = head_tail_vector[:, np.newaxis ,:] # cross-product only defined in space, not in 2D
|
point_axis_vector = bodycoords[:,:,:] - bodycoords[:, 0, :][:,np.newaxis,:]
|
||||||
head_tail_length = np.linalg.norm(head_tail_vector, axis=1, keepdims=True) # pythagoras, length of head- tail connection
|
htv = head_tail_vector[:,np.newaxis, :]
|
||||||
point_axis_vectors = bodycoords - head_tail_vector
|
# Pythagoras, length of head- tail connection
|
||||||
deviations = np.cross(head_tail_vector, point_axis_vectors)/head_tail_length
|
head_tail_length = np.linalg.norm(head_tail_vector, axis=1, keepdims=True)
|
||||||
deviation = np.mean(deviations, axis=1)
|
deviations = np.cross(htv, point_axis_vector)[:,:,-1] / head_tail_length
|
||||||
return deviation
|
deviations = np.mean(np.abs(deviations), axis=1)
|
||||||
|
return deviations
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return self._data[key]
|
return self._data[key]
|
||||||
@ -236,8 +250,8 @@ def main():
|
|||||||
lengths = data.animalLength()
|
lengths = data.animalLength()
|
||||||
frames = data["frame"]
|
frames = data["frame"]
|
||||||
tracks = data["track"]
|
tracks = data["track"]
|
||||||
|
bendedness = data.bendedness()
|
||||||
# bendedness = data.bendedness()
|
|
||||||
|
|
||||||
embed()
|
embed()
|
||||||
tracks = data["track"]
|
tracks = data["track"]
|
||||||
|
Loading…
Reference in New Issue
Block a user