Resetting a counter #2343
-
|
Hi all — I'm trying to track a mouse in a simple arena (black mouse, white background), to detect when in it's a certain quadrant, and I want to add in some error robustness. The mouse has a tether, which causes only short-lived errors when the tether flops around, but as this is going to trigger optogenetic stimuli, I really want to avoid false positives. So, my current idea is to have a counter that counts frames when the mouse is in the quadrant, and set some threshold (say, 1 sec worth of frames) for allowing stimulation. Then if the mouse is ever detected out of the quadrant (truly or wrongly) the counter resets to 0 immediately. I can't figure out how to implement this resetting behavior in Bonsai. My first thought was to use an Accumulator node and externalize its "value" property, but it turns out the Accumulator nodes don't have any properties at all. I think I might be able to just use a Python script module, but I'm going to run this at 120 fps and I don't want to have latency issues. Let me know if this is possible? Thank you! (Note: this is in Bonsai 2.8) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Hi @jonahpearl there should be multiple ways of accomplishing it in bonsai without relying on external scripts, I am only showing one possible way here, not sure if its the best way or not. I simplified your workflow to something I could test with a computer mouse and also removed some unnecessary conversions. I think the key is that you want to group your centroid readout into windows, and then evaluate each window using a Within the That being said, if you also know the behaviour of your tether artifact, it might be possible to skip over frames with that artifact. That would involve collecting some empirical data on possible constraints on area or kinematics (for instance, the largest binary region might be much bigger than the area for a regular size mouse, or the travelling velocity of the centroid might not be physically possible for a mouse). You could also try an online pose estimation package like Bonsai.Sleap. I believe the tracking is more accurate and resilient to tether artifacts. That might allow you to be less conservative about false positives and eliminate the minimum time condition. Anyway let me know if the posted solution works for you, workflow attached! I kept the settings, so you can test it by moving your mouse over the top left corner. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, this is very helpful, I didn't know about the Window operators. Two asides: 1) is there a good place to learn more about all the different operators in Bonsai / see more sophisticated examples? The docs feel very limited, and it's hard to learn to think in a "Bonsai-onic" (to borrow from pythonic") mindset. |
Beta Was this translation helpful? Give feedback.


Hi @jonahpearl there should be multiple ways of accomplishing it in bonsai without relying on external scripts, I am only showing one possible way here, not sure if its the best way or not. I simplified your workflow to something I could test with a computer mouse and also removed some unnecessary conversions.
I think the key is that you want to group your centroid readout into windows, and then evaluate each window using a
SelectMany. You can useWindowTimeorWindowCountfor this purpose, and you can create overlapping or non overlapping windows depending on the latency you are looking for or if you are comfortable with just assessing each 1 second split independently (I don't think it …