Commit 4cb44145 authored by lucas_miranda's avatar lucas_miranda
Browse files

Drastically sped up get_distances method in coordinates class

parent 881f8ed7
This diff is collapsed.
This diff is collapsed.
......@@ -49,15 +49,23 @@ def tab2polar(tabdict):
return result
# Paired distance between bodyparts
def bpart_distance(frame, labels, absdist_arena, pixdist_arena):
"""Designed to be applied to a dataframe with frames as rows and body parts as columns. Returns a dataframe
with frames as rows and distances as columns"""
dist = pd.Series(spatial.distance.pdist(frame.unstack()))
dist = (dist * absdist_arena) / pixdist_arena
dist.index = list(combinations(labels, 2))
return dist
def compute_dist(pair_df, arena_abs, arena_rel):
a, b = pair_df[:, :2], pair_df[:, 2:]
ab = a - b
dist = np.sqrt(inner1d(ab, ab))
return pd.DataFrame(dist * arena_abs / arena_rel)
def bpart_distance(dataframe, arena_abs, arena_rel):
indexes = combinations(dataframe.columns.levels[0], 2)
dists = []
for idx in indexes:
dist = compute_dist(np.array(dataframe.loc[:, list(idx)]), arena_abs, arena_rel)
dist.columns = [idx]
dists.append(dist)
return pd.concat(dists, axis=1)
def angle(a, b, c):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment