Initial state for keydown node

263 views
Skip to first unread message

jarto...@gmail.com

unread,
Mar 7, 2018, 5:54:24 AM3/7/18
to Bonsai Users
Hi,

my problem is, that I want to connect a continuous flow of data and the KeyDown node with CombineLatest, but KeyDown doesn't return anything until a button is pressed for the first time, so CombineLatest can't return anything either. Is there any way to go around this, so even if you don't press anything, KeyDown still returns empty data when the program is started so CombineLatest can start running? I'm attaching my current workflow.

-Felix
keydown_example.bonsai

Niccolò Bonacchi

unread,
Mar 7, 2018, 10:01:38 AM3/7/18
to jarto...@gmail.com, Bonsai Users
Hi Felix,

I'm not clear on exactly what are you trying to achieve. Do you want the key press to stop the data flow? 'label' the data with key presses? Maybe you need to initialize the workflow with a constant var like Bool that fires only once onLoad.

--
N

--
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/f50a852e-5135-494e-b7a4-88ec87905850%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jarto...@gmail.com

unread,
Mar 7, 2018, 10:22:48 AM3/7/18
to Bonsai Users
Dear Niccolò,

it is really hard for me to explain what this does exactly, but in my full workflow there is a continuous flow of data from a FileCapture node coming in and I combine it with the data from the KeyDown node. This is achieved by a CombineLatest node. So basically every frame of the video is labeled with a button press. The problem is, that CombineLatest can't send any data until KeyDown produces an element. But for the program, it would be essential that it sends the data from the video as soon as the program starts combined with the data from KeyDown (they can't be separate), so KeyDown must produce an empty element as soon as the program starts without pressing any buttons, so that CombineLatest can send the data at the start of the workflow. I don't know if that makes it more understandable.

-Felix


2018. március 7., szerda 16:01:38 UTC+1 időpontban Niccolò Bonacchi a következőt írta:
Hi Felix,

I'm not clear on exactly what are you trying to achieve. Do you want the key press to stop the data flow? 'label' the data with key presses? Maybe you need to initialize the workflow with a constant var like Bool that fires only once onLoad.

--
N

On Wed, Mar 7, 2018 at 10:54 AM, <jarto...@gmail.com> wrote:
Hi,

my problem is, that I want to connect a continuous flow of data and the KeyDown node with CombineLatest, but KeyDown doesn't return anything until a button is pressed for the first time, so CombineLatest can't return anything either. Is there any way to go around this, so even if you don't press anything, KeyDown still returns empty data when the program is started so CombineLatest can start running? I'm attaching my current workflow.

-Felix

--
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,
Mar 7, 2018, 9:14:50 PM3/7/18
to jarto...@gmail.com, Bonsai Users
Hi Felix,

If you are trying to label frames in the video, it might be more useful to use Sample instead of CombineLatest, so that you tag the latest frame that passed through. If you would like to know the frame number, you can use Index to count the number of frames.

Hope this helps.

Btw, we have been developing some solutions for video annotation in Bonsai that we may package for release soon: https://github.com/everymind/CuttleShuttle-Analysis
It requires compiling some custom operators, but instructions are in the README. This will allow you to create arbitrary annotations and even replay anotated files, edit annotations, step frame-by-frame, etc.

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

jarto...@gmail.com

unread,
Mar 9, 2018, 5:49:31 AM3/9/18
to Bonsai Users
Dear Goncalo,

I'm sorry, I'm not really good at explaining myself and I wanted to avoid writing a book about this part of the workflow. I tried cutting out this specific part of my current workflow to a separate workflow, I'll try to explain what it does as best as I can. I'm attaching it with this post.

The workflow loads in a batch of videos and a node transforms the filename into a string, that is essentially the code for the animal in the video (FNameChange). This provides a continous flow of this filename. The DistinctUntilChanged node connected to it triggers the TriggeredWindow node when a new video with a new filename comes in. There is also a KeyDown node, the PythonTransform node gives back specific strings on specific button presses, which serve as labels. The button presses and the continous flow of the filename string feed into a SelectMany node. Inside it, it basically counts the frames according to the labels they're given and than calculates a percentage for each label. At the end, these percentages are saved in a text file, the text file's name is decided by the continous flow of the filename. So this flow acts as the name specifier but also it "carries the frames" into SelectMany

Now the problem. The CombineLatest node can't start without a button press. That means, that the filename can't feed into SelectMany, so at the start of the workflow, the textfile doesn't get it's filename and it doesn't create a text file for the first video in the batch. Because of this, I would need an empty data from the KeyDown node at the very start of the workflow, so CombineLatest can start feeding the filename into SelectMany.

I tried using sample, but it only returns one value.

-Felix
keydown_example_2.bonsai

Gonçalo Lopes

unread,
Mar 10, 2018, 6:56:32 AM3/10/18
to jarto...@gmail.com, Bonsai Users
Hi Felix,

If you want to annotate frames for each video file, it might be best to actually place all that logic inside the Batching node. This way you know that the annotation workflow runs once for each file in the batch. Basically, your data stream is already split at the level of Batching, so it seems counter-productive to merge it and then split it again (does that make sense)?

In practice, the way I would solve this is by moving all the nodes that are after Concat inside Batching, and proceed from there. You should find that it makes everything easier, since now you will have one annotation workflow running for each file in the batch.

If you still need an empty event to drive your CombineLatest, you can consider inserting an empty string at the beginning of your key press, like so:



This will insert an empty string at the beginning of that sequence.

Hope this helps.


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