Distance traveled

948 views
Skip to first unread message

a...@webmail.unt.edu.ar

unread,
Apr 21, 2017, 4:37:13 PM4/21/17
to Bonsai Users
Good afternoon. 
I'm using Bosai to track a rat in the Morris water maze, but I have a trouble. 
I don´t know how can I make that Bonsai shows me the distance traveled by the rat. 
I´m using the next workflow. 
file capture> crop > Convert Color> Hsv Threshold> Find Contours> Binary region analysis> Largest Binary region> Source Centroid> Source Y
Which function allows me to know the distance?
Can anybody help me?
Thank you

a...@webmail.unt.edu.ar

unread,
Apr 21, 2017, 4:44:38 PM4/21/17
to Bonsai Users


El viernes, 21 de abril de 2017, 17:37:13 (UTC-3), a...@webmail.unt.edu.ar escribió:
Good afternoon. 
I'm using Bosai to track a rat in the 
Morris water maze, but I have a trouble. 
I don´t know how can I make that Bonsai tells me the distance traveled by the rat, in numbers.

Gonçalo Lopes

unread,
Apr 21, 2017, 9:19:00 PM4/21/17
to a...@webmail.unt.edu.ar, Bonsai Users
Hi abi and welcome to the forums.

I am attaching two versions to do this with a simple tracking workflow which you may be able to adapt to your case.

This depends on how exactly you are defining "distance" in this case. Do you mean the length of the displacement vector from an initial position (subtract the current position from the first position)?



Or do you mean the cumulative sum of all the displacements for every frame (subtract the current position from the previous position and add up all the lengths)?


In both examples, the ExpressionTransform node is simply used to compute the length of the vector.​

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/519882f9-42bd-44a0-bfbf-6f07fd78927a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

displacementlength.bonsai
distancetravelled.bonsai

a...@webmail.unt.edu.ar

unread,
Apr 24, 2017, 12:12:53 PM4/24/17
to Bonsai Users, a...@webmail.unt.edu.ar
Hi, thanks for your help. 
I mean the cumulative sum of all the displacements for every frame. Sorry if I wasn't clear about that. 
I think I´m closer to get what i want. But I'm still having some troubles. 
When I use the workflow that you sent, I can view a dynamic analysis about the recording, but not a "Final report" about the facts detected. Is this possible?
In the Node "Acumulate" i can see nothing..
I don't know if this is this is caused by the record, or just a wrong configuration of Bonsai.
Again, thanks for your help.



El viernes, 21 de abril de 2017, 22:19:00 (UTC-3), goncaloclopes escribió:
Hi abi and welcome to the forums.

I am attaching two versions to do this with a simple tracking workflow which you may be able to adapt to your case.

This depends on how exactly you are defining "distance" in this case. Do you mean the length of the displacement vector from an initial position (subtract the current position from the first position)?



Or do you mean the cumulative sum of all the displacements for every frame (subtract the current position from the previous position and add up all the lengths)?


In both examples, the ExpressionTransform node is simply used to compute the length of the vector.​

Hope this helps.
On 21 April 2017 at 21:44, <a...@webmail.unt.edu.ar> wrote:


El viernes, 21 de abril de 2017, 17:37:13 (UTC-3), a...@webmail.unt.edu.ar escribió:
Good afternoon. 
I'm using Bosai to track a rat in the 
Morris water maze, but I have a trouble. 
I don´t know how can I make that Bonsai tells me the distance traveled by the rat, in numbers.
I´m using the next workflow. 
file capture> crop > Convert Color> Hsv Threshold> Find Contours> Binary region analysis> Largest Binary region> Source Centroid> Source Y
Which function allows me to know the distance?
Can anybody help me?
Thank you

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.

Gonçalo Lopes

unread,
Apr 25, 2017, 9:01:46 AM4/25/17
to a...@webmail.unt.edu.ar, Bonsai Users
Hi Abi,

This was most likely due to frames where the animal was not in view. In this case, the centroid reports invalid values (i.e. NaN) for the centroid X and Y so when you compute the cumulative sum, the result will always be NaN.

I am attaching a modified version where I extend the script to check for such invalid values and return 0 in that case (i.e. the assumption is that there was no distance travelled in that case).


To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
distancetravelled.bonsai

a...@webmail.unt.edu.ar

unread,
Apr 26, 2017, 12:11:06 AM4/26/17
to Bonsai Users, a...@webmail.unt.edu.ar
Hi, Good morning.
I've tried your new algorithm and ir works perfectly.
I Have one last question. 
In the graph of "Accumulative" I can see values assigned to the length, but I don't know the unit of length that is used for it.

Are these milimmeters? centimeters? Inch? foot?
Thank you very much.

Gonçalo Lopes

unread,
Apr 26, 2017, 5:18:25 AM4/26/17
to a...@webmail.unt.edu.ar, Bonsai Users
The units are pixels, the same as the tracked centroid coordinates.

If you want to convert them into a physical unit (such as mm), you could use the Rescale node just before the Accumulate node (i.e. before you integrate) and pass in the dimensions associated with the min and max pixel displacement (i.e. 0 is the minimum displacement and the physical diagonal would be the max displacement).

However, I would recommend that this conversion be performed in the analysis phase, rather than acquisition, unless you have a really rigid and fixed setup that never changes.

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.

Zirong Gu

unread,
Jun 11, 2019, 11:24:08 AM6/11/19
to Bonsai Users
Dear Bonsai Users,

We tried to make sure that the distance csv file outputted by Bonsai and the distances calculated using the centroid csv file were the same, but when we ran analysis on them, we found that the centroid csv file yields distances that are 10x smaller than the distances found using the distance csv file. If anyone has any suggestions on what we can do or what could be going wrong, it would be much appreciated! I have attached the raw csv files for both the distance and the centroid data.

Thanks so much,
Zirong


Distancetravelled2019-05-29T16_10_37.csv
Centroid2019-05-29T16_10_37.csv

Zirong Gu

unread,
Jun 12, 2019, 11:54:30 AM6/12/19
to Bonsai Users
Hi all, 

We are doing optogenetic experiments and using centroid data from Bonsai to calculate distance traveled during true and false trials.

I used the distance formula on the centroid data from Bonsai and calculated the mean distance for each of my experiments, which I then plotted in the bar graph on the right in the second slide of the powerpoint. As you can see from the plotted centroid trajectories on the first slide, these average distances do not appear to match up with the centroid trajectories. When I instead use the distance formula on only the first and last points for each trial of each experiment and then plot the mean distances for each experiment, it yields the bar graph on the left side of the second slide. Clearly, this bar graph seems to better represent the overall movement of the mouse. This discrepancy only seems to arise when the mouse does not move much in a trial and just stays in one corner. 

Yet, I also wonder if the bar graph on the right could actually be true, despite the mouse not appearing to move much in the true experiments 1 and 3. I looked at two random adjacent points from a trial where the mouse barely moved, and the distance formula on the two points confirmed what the MATLAB script had calculated for those two points. 

Has anyone else ever experienced this or know if what is happening is real or artificial? If so, any suggestions on what to do would be highly appreciated.  Please find PPT and .mat files in the attachement. 
   
    Best,
    Zirong  
 
BonsaiHelpForum.pptx
BonsaiHelpForum_Zirong.mat

Gonçalo Lopes

unread,
Jun 15, 2019, 8:33:37 AM6/15/19
to Zirong Gu, Bonsai Users
Hi Zirong,

I'm not sure I understand the question. Do you mean total distance travelled is 10x different, or individual centroid coordinates are 10x different? Can you attach the Bonsai workflows you are using so we can have a better idea of how the data is being logged?

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.

Zirong Gu

unread,
Jun 18, 2019, 12:37:02 AM6/18/19
to Gonçalo Lopes, Bonsai Users
Hi Gonçalo, 

Thanks so much for your reply!  We found that the total distance traveled calculated online (using the attached Bonsai code) is 10x more than that of distance traveled calculated based on centroid coordinates csv file. We found the plotting of centroid coordinates match the dimension of the open field. But online calculation is based on the centroid coordinates and we use the same distance formula for both online and offline calculation. 

Could you please also comment on our second question - about the potential artifact of distance traveled when the mouse is staying in a corner and not moving much forward? 

Thank you so much for your help! 
Distance travelled.bonsai
Distance travelled.layout

Zirong Gu

unread,
Jun 28, 2019, 12:46:41 PM6/28/19
to Bonsai Users
Hi Gonçalo, 

I forget to attach the files. 

Thanks,
Zirong 


On Saturday, June 15, 2019 at 8:33:37 AM UTC-4, goncaloclopes wrote:
Hi Zirong,

I'm not sure I understand the question. Do you mean total distance travelled is 10x different, or individual centroid coordinates are 10x different? Can you attach the Bonsai workflows you are using so we can have a better idea of how the data is being logged?

On Wed, 12 Jun 2019 at 16:54, Zirong Gu <ziro...@gmail.com> wrote:
Hi all, 

We are doing optogenetic experiments and using centroid data from Bonsai to calculate distance traveled during true and false trials.

I used the distance formula on the centroid data from Bonsai and calculated the mean distance for each of my experiments, which I then plotted in the bar graph on the right in the second slide of the powerpoint. As you can see from the plotted centroid trajectories on the first slide, these average distances do not appear to match up with the centroid trajectories. When I instead use the distance formula on only the first and last points for each trial of each experiment and then plot the mean distances for each experiment, it yields the bar graph on the left side of the second slide. Clearly, this bar graph seems to better represent the overall movement of the mouse. This discrepancy only seems to arise when the mouse does not move much in a trial and just stays in one corner. 

Yet, I also wonder if the bar graph on the right could actually be true, despite the mouse not appearing to move much in the true experiments 1 and 3. I looked at two random adjacent points from a trial where the mouse barely moved, and the distance formula on the two points confirmed what the MATLAB script had calculated for those two points. 

Has anyone else ever experienced this or know if what is happening is real or artificial? If so, any suggestions on what to do would be highly appreciated.  Please find PPT and .mat files in the attachement. 
   
    Best,
    Zirong  
 

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai...@googlegroups.com.
BonsaiHelpForum.pptx
BonsaiHelpForum_Zirong.mat

Gonçalo Lopes

unread,
Jun 30, 2019, 3:55:01 PM6/30/19
to Zirong Gu, Bonsai Users
Hi Zirong,

Unfortunately I don't have MATLAB so I cannot open the .mat file. I tried looking at the raw data files you sent earlier, but it looks like they were generated by a different Bonsai workflow. The file "Distancetravelled..." seems to have 5 columns. Do you have the workflow that originally generated these files? The workflow you sent before doesn't seem to generate any data files.



To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.

Zirong Gu

unread,
Jul 1, 2019, 11:45:10 PM7/1/19
to Bonsai Users
Hi Gonçalo, 

Thanks for looking into this. 

The first four columns are time, hour-minute-second-ms, the last one is the distance. 
It is generated from the Bonsai workflow that I have attached. Attach is the csv file that is generated from the Bonsai file. 

Regarding the artifact of the centroid issue, I think the artifact could come from the threshold configuration. 
I plan to play with the configuration and see if this can be fixed. 

Please let me know if you have any more questions. 

Thanks,
Zirong 
Distancetravelled2019-05-29T16_10_37.csv

Gonçalo Lopes

unread,
Aug 9, 2019, 5:45:08 AM8/9/19
to Zirong Gu, Bonsai Users
Hi Zirong,

Can you please attach the workflow that was used to originally record this data?
The first workflow you attached has a Rescale operator that could not possibly give correct results, as it has zeros for all the ranges.

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages