Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lucas Miranda
deepOF
Commits
4cb44145
Commit
4cb44145
authored
Apr 29, 2020
by
lucas_miranda
Browse files
Drastically sped up get_distances method in coordinates class
parent
881f8ed7
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
main.ipynb
View file @
4cb44145
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
source/utils.py
View file @
4cb44145
...
...
@@ -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
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment