-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute Head Direction Vector #276
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #276 +/- ##
=======================================
Coverage 99.77% 99.77%
=======================================
Files 14 14
Lines 884 904 +20
=======================================
+ Hits 882 902 +20
Misses 2 2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @b-peri! This is well implemented and well tested with the known values.
Some thoughts (apart from the things I point out in individual comments):
- would be nice to expand the tests a bit by checking for what happens if there is a NaN value. For example, you can make one of the ears NaN for a particular timepoint and test whether the head vector for that exact timepoint (and no other) is NaN.
- As we discussed today, you may move the new funciton to the kinematics module (anticipating our planned removal of the
analysis
level. - Once you compelete the above, it would be good to use this function within the polar vectors example. For that you'd need to modify the code to use your function for computing the head vector (instead of midpoint + snout) and update the plots accordingly. I think it's worth doing that in this PR, as that example will serve as the perfect documentation for the new feature. Btw, becasue the example scripts are broken down into cells (via
# %%
), you can run them independently via ipython, which is helpful for debugging and editing that script. Let me know if you need help with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the delay @b-peri !
From the longer discussion in zulip, I detail here what I think would be the simplest implementation.
I also added some comments about the tests, let me know if you have any questions. The basic idea is to split them based on their goals (e.g. split them if they test the error-catching, the behaviour with nans, or the 'ideal' behaviour) and parametrise them when possible.
Let me know if you'd like to discuss anything offline or if you have questions!
movement/analysis/kinematics.py
Outdated
@@ -161,6 +163,94 @@ def _compute_approximate_time_derivative( | |||
return result | |||
|
|||
|
|||
def compute_head_direction_vector( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def compute_head_direction_vector( | |
def compute_2D_head_direction_vector( |
or something of the like to make it clear that we are focusing on the top-down / bottom-up view case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be more general than head direction?
It would work to compute any forward direction perpendicular to a line connecting two symmetrical points about the sagittal plane, right? For example, we could compute a forward vector that is always perpendicular to the line connecting both hips.
Maybe it's worth renaming?
Hey @b-peri , just a note to also remove any uppercase letters in function names. |
…_direction_vector()`
for more information, see https://pre-commit.ci
Hi @lochhh, thanks for the heads-up, that's my bad! The function names are fixed now! |
Quality Gate passedIssues Measures |
Description
This PR introduces the
navigation
module and addscompute_head_direction_vector()
- a function for calculating an animal's 2D head direction vector - tomovement
. As described in #238, this function takes two keypoints (corresponding to the left and right of the head) and computes the vector perpendicular to the line connecting them, pointing in the animal's rostral direction.Since
compute_head_direction_vector()
expects the input dataset to have specific dimensions (and specific keypoints), I've taken some notes from thekinematics
module here and added some validation to the beginning of the function. I expect that some of this will be factored out into a separate function as we continue to add to thenavigation
module, but I've kept everything under the main function itself for the time being.What is this PR
References
Checklist: