Matrix Write from Nidaq input

325 views
Skip to first unread message

KPerks

unread,
Jun 24, 2021, 9:16:21 AM6/24/21
to Bonsai Users
Hi all,
I am trying to figure out how to save my data to a file and am having trouble.
I am using the DAQmx package to acquire analog input. It visualizes nicely with the native Visualizer option on the right click menu ('.MatVisualizer').
I added a MatrixWriter node to save to binary. I am able to open the binary file in Python but the result is not as expected. 
Attached is the workflow, the visualizer in Bonsai, and the plot of the binary data in Python. 

What am I doing wrong?

Thank you so much for help.

brunocruz

unread,
Jun 25, 2021, 6:08:09 AM6/25/21
to Bonsai Users
Hi,

I think you might have forgotten to add the workflow. Also it would be useful to get a sense of the results you are getting in python.
In general, when reading these binary files you need to make sure you get the format correct (col vs row major), the bitdepth (U8, S8, U16, etc...) and the number of col/rows you are expecting.

Cheers,
Bruno

KPerks

unread,
Jun 25, 2021, 10:01:30 AM6/25/21
to Bonsai Users
Thank you, Bruno.
I had some screenshots that did not get attached. Sorry for that. 

Here are better ones anyway; trying both row major and column major as the write property. Hopefully they post this time. 
Shown are the workflow with the matrixwriter property list visible, the analog input visualizer (showing just 60cycle noise in this case), and the plot of the resulting file in python with the line of code used to read it. 
I found a document that explained an example of reading the result of the Bonsai matrixWriter in Python that said to specify int16 (can't refind the resource now). So I was using that
I only have one analog input from the Nidaq currently so I am guessing it should be one channel (unless the DAQmx streams the data as well as timestamps? Is there a resource for what the format of the datastream from AnalogInput is?


Is 'Data' output where the Voltage values should be from the nidaq analog input?
Here I tried pulling out the 'Data' output of the AnalogInput and TypeMapping it as OpenCV.Net.Mat. Here I get a "no method overload found for given arguments" build error.
Capture.PNG
Capture_ColumnMajor.PNG
Capture_RowMajor.PNG
nidaq_workflow.bonsai

Gonçalo Lopes

unread,
Jun 27, 2021, 12:24:25 PM6/27/21
to KPerks, Bonsai Users
There are some good examples of how to open the bin files in the forums which might be useful and should generalize to different number of channels and data formats:

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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/263e167e-6ee5-4b24-b65f-f7b2f35280bbn%40googlegroups.com.

KPerks

unread,
Jun 28, 2021, 4:25:41 PM6/28/21
to Bonsai Users
Thank you. My matrix dimensions were correctly specified in Python. The thing that I was missing was understanding how to get the right data type. I assumed there was a standard data output type used by Bonsai to save .bin data using MatrixWriter. There was an audio recording workflow that I found that I was using as my example for how to read into Python and it specified that the data type should be np.int16. So I had been using that to read into Python. At the end of that thread you just linked me to I read that you can find the data type by right clicking the node in Bonsai and choosing the text visualizer. When I did that the data type was F64! I changed that in Python and now get data that looks as expected, which is currently just 60Hz noise haha (attached).

Cheers. 
Hope this helps others as well.


Capture.PNG
Reply all
Reply to author
Forward
0 new messages