[trackingdata] fix orientation estimation

This commit is contained in:
Jan Grewe 2025-02-19 17:45:21 +01:00
parent 256e9caa2f
commit 2bba098b77

View File

@ -166,10 +166,11 @@ class TrackingData(QObject):
lengths = np.sum(np.sqrt(np.sum(np.diff(bodycoords, axis=1)**2, axis=2)), axis=1)
return lengths
def orientation(self, head_node=1, tail_node=5):
def orientation(self, head_node=0, tail_node=5):
bodycoords = self.coordinates()[:, [head_node, tail_node], :]
vectors = bodycoords[:, 1, :] - bodycoords[:, 0, :]
orientations = np.arctan2(vectors[:, 1], vectors[:, 0])
orientations = np.arctan2(vectors[:, 0], vectors[:, 1]) * 180 / np.pi
orientations[orientations < 0] += 360
return orientations
def bendedness(self, bodyaxis=None):
@ -184,7 +185,7 @@ class TrackingData(QObject):
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, :]
@ -241,10 +242,20 @@ def main():
count += 1
return dists
datafile = PACKAGE_ROOT / "data/merged_small.pkl"
def plot_skeleton(positions):
skeleton_grid = [(0, 1), (1, 2), (1, 3), (1, 4), (2, 5)]
colors = ["tab:red"]
colors.extend(["tab:blue"]*5)
plt.scatter(positions[:, 0], positions[:, 1], c=colors)
for si, ei in skeleton_grid:
plt.plot([positions[si, 0], positions[ei, 0]],
[positions[si, 1], positions[ei, 1]], color="tab:green")
datafile = PACKAGE_ROOT / "data/merged2.pkl"
with open(datafile, "rb") as f:
df = pickle.load(f)
data = TrackingData()
data.setData(as_dict(df))
all_cogs = data.centerOfGravity()
@ -253,7 +264,7 @@ def main():
frames = data["frame"]
tracks = data["track"]
bendedness = data.bendedness()
positions = data.coordinates()[[160388, 160389]]
embed()
tracks = data["track"]