-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Dear Gilestro lab
Thank you for developing sleepr and making it publicly available for free. It’s great!
I had a question regarding your max_velocity_detector annotation function, which you use in sleep_annotation to determine the level of activity of a fly in time_window_length seconds.
The logic you implement consists of retrieving the distance computed live on the ethoscopes, and you then divide by the time passed since the previous frame. This time difference is expressed in the dt column, which you compute in the beginning of the function
Line 44 in 59949e3
| d[,dt := c(NA,diff(t))] |
With the distance and the time difference, you then can compute a velocity
Line 47 in 59949e3
| d[,velocity := dist/dt] |
In the next lines you simulate beam crosses and mask behavior if an interaction occurs, which is not relevant for my question.
The next relevant line is the following:
Line 74 in 59949e3
| d[, velocity_corrected := velocity * dt /a] |
Which according to the supplementary material in your PLOS One article https://journals.plos.org/plosbiology/article/file?id=10.1371/journal.pbio.2003026.s005&type=supplementary is designed to correct for the problem
that resulting velocity computation depended on the frame rate of the processed video
i.e. you correct the velocity taking into account the FPS.
However, by having a close look to the code, I would argue that what you effectively do is instead getting the distance again and then normalizing with a. The result of this operation is called velocity_corrected, but it is basically a distance normalized by a. You then select the maximum value in time_window_length and if the maximum is bigger than 1 i.e. the original distance dist is greater than a, the fly is annotated as moving for that block of time, and not moving otherwise.
Wouldn’t it be more correct to omit line 74 and just check if the velocity is greater than a? Or maybe divide again by dt (and not multiply). Under my reasoning, the fact that the velocity is multiplied with dt does not only not correct the velocity but also makes the time between frames irrelevant because it takes the magnitudes to the distance space, and not the velocity space.
This question is related to issue gilestrolab/ethoscope#97 in the ethoscope repository. We are trying to find what is the problem and misannotation could be one of the culprits.
Once again, thank you very much!
Best,
Antonio