trigger by deceleration in the mouse open field task and trigger with a 50% probability or send out TTL with a 50% probability

580 views
Skip to first unread message

Zirong Gu

unread,
May 10, 2018, 10:10:21 PM5/10/18
to Bonsai Users
Dear Bonsai users, 

I set up this code to do closed loop optogenetic manipulation based on the video/speed tracing in a mouse open field task. 
I managed to send out a TTL via an Arduino board to the optogenetic system whenever the speed of the mouse (from video tracking) is greater than a predefined speed. 
I am wondering if 
1) it is possible to trigger an optogenetic stimulation by deceleration? for example, it is possible to monitored acceleration/deceleration of mice using bins of 300 ms.
We want to trigger the optogenetic manipulation when mice accelerate or decelerate?
2) second, it is possible to  send out TTL with a 50% probability so that only half of the trials receive the optogenetic manipulation and the second half will be the same subject/session control. 

Thanks in advance for the help!
Zirong Gu


Speed triggr 20.bonsai

Gonçalo Lopes

unread,
May 13, 2018, 11:43:45 AM5/13/18
to Zirong Gu, Bonsai Users
Hi Zirong and welcome to the forums,

It looks like in your case you would be able to look at acceleration/deceleration using exactly the same strategy you used to compute velocity.
The only difference is that you need to change your Velocity node to use the Subtract operator, instead of your custom built EuclideanDistance script.

Basically, the Velocity node would now look like this:




This computes the first derivative (difference) vector for the centroid. If you now use it twice (i.e. one after the other), you will be computing acceleration.
You can then adapt your EuclideanDistance script to compute the length of that vector to obtain the magnitude of the acceleration vector.

Please note that if you are interested in variation of speed (magnitude of velocity vector), it may be easier to differentiate that number instead (i.e. the output of your original Velocity node). You can use the Subtract pattern above, or simply the Difference node with the Order parameter set to 1 for that.

I hope this helps. Let me know if anything is not clear.

--
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/b67dd137-5cf6-4f32-a4ee-af3df0b31464%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zirong Gu

unread,
May 14, 2018, 1:18:28 AM5/14/18
to Gonçalo Lopes, Bonsai Users
 Hi Gonçalo, 

Thanks for your suggestion and help. 
I have five more questions regarding the attached codes. 

1) Your suggestion is "
This computes the first derivative (difference) vector for the centroid. If you now use it twice (i.e. one after the other), you will be computing acceleration.
You can then adapt your EuclideanDistance script to compute the length of that vector to obtain the magnitude of the acceleration vector.
I am not sure if my revised code is what you suggested. Could you please take a look and let me know? 

2) I guess for acceleration, I can set the value for the Greaterthan to a positive value, say 40
for deceleration,  I can set the value for the Greaterthan to a positive value, say -40

3) I do not understand this comment " Please note that if you are interested in variation of speed (magnitude of velocity vector), it may be easier to differentiate that number instead (i.e. the output of your original Velocity node). You can use the Subtract pattern above, or simply the Difference node with the Order parameter set to 1 for that.

4) I  have one line of code to send out a TTL timestamp whenever the Flycapture take a frame, but there is an error when I delete " Greaterthan". I set the value of the  Greaterthan to 0 here. 
It seems this trick works, but do you know a better way of doing this. 

5) would it be possible to trigger with a 50% probability so that half of the trials will be within-subject control. 

Thanks,
Zirong 
trigger by the magnitude of the acceleration vector_Gonçalo version.bonsai
trigger by the magnitude of the acceleration vector_Gonçalo version_digital output arduino error.bonsai

Paolo Botta

unread,
May 17, 2018, 6:15:21 PM5/17/18
to Zirong Gu, Gonçalo Lopes, Bonsai Users
Hi Gonçalo,

I have also been trying to incorporate few nodes in order to have 50% of probability to trigger an arduino.

Specifically in the code that I am attaching, I would like that the animal entering to an ROI will receive optogenetic stimulations with 50% of probability (i.e., for 50 trials). This can also be valid for Zirogn question (triggering based on a speed or acceleration threshold).

1) After the node DistinctUntilChanged, I have added a group-node and a Condition node but I still get 100% probability of triggering. Do you have a solution or a simpler way to have a 50% probability? IOt also 

2) Additionally, I would like to have the exact time stamp of when the stimulation (and the non-triggered one). Will the simple TimeStamp node give me both? In this case, how can I discriminate between the two times (stimulus and missed-stimulus condition)?

Thanks for any feedback on this.

Best,
Paolo


Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman institute
Columbia University
Tel. +1 (347) 525-3666 | Skype paolobotta | LinkedIn

ROIentrance_50%stim.bonsai
ROIentrance_50%stim.bonsai.layout

Gonçalo Lopes

unread,
May 23, 2018, 7:51:45 PM5/23/18
to Paolo Botta, Zirong Gu, Bonsai Users
Hi Paolo,

Can you please start a new question about triggering effects with randomized probabilities, and another one about timestamping events?
It will be very hard for new users to discover this kind of information if it is all combined together into a very complex question.

Thanks!

Gonçalo Lopes

unread,
May 23, 2018, 7:58:05 PM5/23/18
to Zirong Gu, Bonsai Users
Hi Zirong,

Your new code looks correct, but regarding 3) the question is whether you care about "velocity" (where the animal is going) or "speed" (the 'amount' of movement). If you care about "speed", this is the length of the velocity vector, which is always a positive number, or zero if the animal is stopped. You then need to differentiate the output of that, rather than the difference between velocity vectors.

Does this make sense? Hope it helps.

Regarding probabilistic effects, I would recommend opening another question, as this is a more general topic.

Paolo Botta

unread,
May 25, 2018, 9:16:09 AM5/25/18
to Gonçalo Lopes, Zirong Gu, Bonsai Users
Sure I will.

Thanks!
Paolo

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman institute
Columbia University
Tel. +1 (347) 525-3666 | Skype paolobotta | LinkedIn

On Wed, May 23, 2018 at 7:51 PM, Gonçalo Lopes <goncal...@gmail.com> wrote:
Hi Paolo,

Can you please start a new question about triggering effects with randomized probabilities, and another one about timestamping events?
It will be very hard for new users to discover this kind of information if it is all combined together into a very complex question.

Thanks!
Reply all
Reply to author
Forward
0 new messages