Importing ephys and video data for synchronisation

128 views
Skip to first unread message

João Pedro Junqueira

unread,
Mar 25, 2022, 9:27:41 PM3/25/22
to pyControl
Hello, everyone.

I'd be happy to get some ideas for the following objective:

I successfully instantiated syncing for an ephys system but, for the next step of aligning and plotting synchronized data, I'm not sure how to progress.

 I've read the documentation but it seems that, outside from pyPhotometry systems, there's not yet a ready solution for importing arrays of sync pulses from ephys data or video data.

For open ephys, could these tools help? What about for video data?

Thank you vert much,
Joao.

João Pedro Junqueira

unread,
Mar 25, 2022, 10:46:45 PM3/25/22
to pyControl
I actually meant that I'd like to know how to get sync pulse time arrays from ephys recording files,
 such that they may be imported for use with the rsync aligner class.

João Pedro Junqueira

unread,
Mar 28, 2022, 3:04:05 AM3/28/22
to pyControl
As a second question related to synchronization:

Besides the sync pulse, which we'll use for offline histogram analysis etc, we'd also like to visualize
inputs from devices online in the open ephys GUI.

For that purpose, are there other options besides having one separate digital output cable from the breakout board
connected to the IO board of open ephys for each event? In our case, that would mean having one for licking events,
one for running start, etc. 

Thanks!

thoma...@neuro.fchampalimaud.org

unread,
Mar 28, 2022, 10:44:55 AM3/28/22
to pyControl
Hi Joao,

The attached zip file contains example data and code showing how you can setup an Rsync_aligner object to convert between Open Ephys sample numbers and pyControl timestamps.  The file script.py is the only code that is specific to this example, the other code files (data_import.py and rsync.py) are the standard ones from the pyControl/tools folder.  The comments in script.py should hopefully provide enough information for you to adapt it to work with your own data, but let me know if anything is not clear.

For video data it will depend on how you are recording the sync pulses using the camera system.  You need to the camera frame numbers corresponding to the rising edges of the sync pulses as a numpy array.  Once you have that you can setup the synchronization as detailed in the docs here.

Besides the sync pulse, which we'll use for offline histogram analysis etc, we'd also like to visualize inputs from devices online in the open ephys GUI. For that purpose, are there other options besides having one separate digital output cable from the breakout board connected to the IO board of open ephys for each event?

Currently there is no pyControl functionality that supports this.  I think Open Ephys has functionality to read serial input, and it would be straightforward to modify the pyControl framework code to send a message over one of the pyboard's UART serial outputs every time an event occurs indicating what the event was.  There would be some latency due to the pyboard sending the signal and Open Ephys processing it, probably not more than a couple of ms at the pyControl end.   I don't know what the latency of the Open Ephys serial implementation is.  If you interested in trying to get this working I can give you pointers about where to modify the pyControl framework code.

best,

Thomas
open_ephys_sync_example.zip

João Pedro Junqueira

unread,
Mar 29, 2022, 3:46:36 AM3/29/22
to pyControl
Hello!

I didn't know I could load it just by using np.load. Thank you very much for the script!

I just found out of a programming API for the camera I use, so I'll use it to generate arrays like the ones from ephys.

For the events broadcasting: I'm interested in trying that but, alternatively, since this is just for visualization during experiment,
I thought we might send over digital outputs for just two of the more relevant events through the behavior ports by using the
allstates function and this adapter, which should allows to use DIO pins A for each port:

HTB1mr5uSFXXXXa6XFXXq6xXFXXXS.jpg

Would that be viable?

Thank you very much for the support!

thoma...@neuro.fchampalimaud.org

unread,
Mar 29, 2022, 6:37:56 AM3/29/22
to pyControl

Hi Joao,

Rather than using that adapter you could probably use the 4 BNC connectors on the breakout board. You can configure one of these as the Rsync output and the other 3 as generic digital outputs using:

from devices import *

board = Breakout_1_2()

sync_output = Rsync(pin=board.BNC_1, mean_IPI=1000)
output_1 = Digital_output(board.BNC_2)
output_2 =  Digital_output(board.DAC_1)  
output_3 = Digital_output(board.DAC_2)

One thing to be aware of is that the microcontroller pins connected to the BNC_2, DAC_1 and DAC_2 connectors on the breakout board are also connected to behavior port pins, with BNC_2 also being Port-6-DIO_B, and DAC_1 and DAC_2 being the DIO_C lines on port 3 and 4 respectively (see the schematic here). Therefore depending on what you have plugged into those ports you may not be able to use all the BNC connectors.

The adapters in the photo do look like they should allow you to connect a BNC cable to the DIO_A line on a behavior port. Alternatively you could use the pyControl port adapter board or a generic RJ45 to screw terminal board to connect to lines on the behavior port.

T

João Pedro Junqueira

unread,
Mar 30, 2022, 3:39:09 AM3/30/22
to pyControl
Since my BNC/DAC ports are occupied with the output from a lickometer, water unit, camera sync
and ephys sync, I might have to use the port adapter board or the screw terminal for sending extra
inputs to ephys.

Thank you as always for the pointers!

Joao.

thoma...@neuro.fchampalimaud.org

unread,
Mar 31, 2022, 7:45:46 AM3/31/22
to pyControl
Hi Joao,

I suggest using a single Rsync output to synchronise both the camera and ephys system, splitting the signal from the BNC connector using a T junction (e.g. this).  This both reduces the number of BNC outputs used for sync, and more importantly ensures that all systems receive the same sync pulse train, which allows you to e.g. convert ephys sample numbers directly to video frame numbers without having to first convert to pyControl times.

T

João Pedro Junqueira

unread,
Apr 1, 2022, 8:32:43 PM4/1/22
to pyControl
Hello,

That's a good call! I'll get those T junctions ASAP. I guess those could also work for duplicating digital inputs/outputs
to/from the other devices to also send them to the Ephys Digital IO board, instead using up breakout board ports.

Thank you,
Joao.
Reply all
Reply to author
Forward
0 new messages