New user of Bonsai

2,743 views
Skip to first unread message

Armando Remondes

unread,
Feb 3, 2015, 1:46:35 PM2/3/15
to bonsai...@googlegroups.com
I'm setting up my gig using Bonsai to record spikes, LFP (128 channels using Open Ephys box), and xyt position data (using Point Grey cam). I am completely new to the ways of Bonsai. Could anyone provide me with a Bonsai workflow I could start with? Thanks so much! Miguel

goncaloclopes

unread,
Feb 4, 2015, 5:20:41 AM2/4/15
to bonsai...@googlegroups.com
Hi Miguel and welcome to the forums!

Yes, I guess a more standardized example of simultaneous ephys and image processing is a bit overdue.

Attached you can find two workflows that demonstrate basic ephys and image acquisition and processing scenarios. I tend to prefer keeping them as separate Bonsai workflows logically and sometimes even physically. The reason to have them separate is that you may need to stop and start the ephys independently from the video (e.g. if some of the amplifier connectors jump out unexpectedly for example). Anyway, if you prefer them to be together in the same workflow, the solution is simple: just open a new Bonsai and drag both files inside; two nested workflows will be created that represent each of the parallel tasks.

Ok, so what's in these workflows? In order to run them successfully you need specific hardware and software arrangements. Starting with the video:

Video Workflow
* Hardware: PointGrey camera and FlyCapture software installed and configured. The workflow records both the acquired video stream and specific image metadata. In order for the metadata to be properly acquired, it needs to be activated in the FlyCapture control panel, under "Advanced Camera Settings". You should tick the boxes corresponding to the frame counter and GPIO pin state.
* Outputs: This workflow outputs 3 files:
  - video.avi: the compressed video output from the camera
  - video.csv: a text file containing the image metadata (one line per frame, each column represents a different metadata value - counter, gpio0-3)
  - tracking.csv: a text file containing tracking information about the largest segmented object from the video (one line per frame)

You can play around with the various parameters. The goal of the metadata is to provide possible synchronization points with ephys. The frame counter in general tells you if and where you've dropped frames for some reason (you'll see a jump in counter values). The GPIO pins can be used to pass synchronization pulses to the camera using the GPIO cable. The tracking provided here is very basic using just contrast segmentation and tracking the X,Y and angle position of the detected object. More sophisticated techniques include background subtraction, color segmentation and others which may be inserted before the FindContours node.

Ephys Workflow:
* Hardware: RHD2000 evaluation board or OpenEphys acquisition board. In order for this workflow to work, you also need the proper FPGA bitfile (see FAQ). The workflow records output data from multiple amplifiers, so you can connect headstages to the board for up to 256 channels simultaneous recording. It also records data from the board ADC and digital TTL inputs.
* Outputs: This workflow also outputs 3 files:
  - amplifier.bin: the raw unsigned 16-bit values acquired from the amplifiers in column-major format
  - adc.bin: same for the board ADCs
  - sync.bin: the raw unsigned 8-bit value representing the board TTL digital inputs

The workflow also provides two basic visualizations: LFP and Spikes. For each of them you need to select the channel (or channels) that you want to visualize. I've left it by default to visualize only 1 channel to ensure good operation. Visualizing simultaneously 256 channels at 30 kHz may prove challenging. Future versions of Bonsai will try to address this by using more optimized filtering and visualization routines, but for now it should be no problem to visualize something between 32-64 channels simultaneously. The ADC and TTL inputs from the board can be used to record extra sensors and signals synchronously with the neural data. This can again be used to solve synchronization between video and ephys, either by passing signals from the camera to the ephys system or from an external signal source (e.g. Arduino) to both of them.

As long as there is some kind of event that is simultaneously recorded reliably in both datasets, aligning the data later should be no problem.

Hope you find this helpful. There is of course much to improve on this basic workflow, but this should cover a large swath of the basics.
Cheers,
Gonçalo
ephys_video.bonsai
ephys_amplifiers.bonsai

Polina Litvak

unread,
Jul 20, 2016, 6:45:57 AM7/20/16
to Bonsai Users
I have a question regarding the format of the Ephys workflow output files - I'd like to be able to open them in matlab,  how should I write the data for that to work  ? Just using MatrixWriter and giving the file no extension doesn't work with either matlab or intan software.

Thanks!

goncaloclopes

unread,
Jul 20, 2016, 8:46:08 AM7/20/16
to Bonsai Users
Hi Polina,

MatrixWriter writes the data as raw binary, depending on where you place it in the workflow. Usually you would place the MatrixWriter immediately after you select out the AmplifierData. In this case, the file will be raw binary 16-bit.

I believe Korey had some example Matlab code for opening these files in a previous question:

Can you check if this helps?

Polina Litvak

unread,
Jul 21, 2016, 5:12:23 AM7/21/16
to Bonsai Users
Thanks!
Is there a way to save the data in Intan's format (.rhd), so it can be opened using their UI ?

goncaloclopes

unread,
Jul 21, 2016, 6:08:21 PM7/21/16
to Bonsai Users
Not right now unfortunately, but it could definitely be added to the ephys package. Basically the data format itself is actually the same, but the RHD file starts with a custom header described in:

I guess it would be possible to write a script in MATLAB or Python that takes the Bonsai raw data and adds the required bytes at the beginning to make it compatible. I have added an issue to the Bonsai.Neuro repository to track this for future releases:

Reply all
Reply to author
Forward
0 new messages