Camera sync alternative; experiment data pickle loading

103 views
Skip to first unread message

João Pedro Junqueira

unread,
Sep 20, 2022, 4:34:36 AM9/20/22
to pyControl
Hello,

I'd like to ask about the following:

1 - Although we currently have a working synchronization routine of sending sync pulses with the sync pyControl object, we needed a second camera and due to stock shortages we are trying to demo a model from another manufacturer that has a GPIO but can only use it to trigger a frame capture on trigger mode. Considering that, if we are not to give up on using this one, I thought of the following alternatives:
 
a ) Using a pyControl digital output to trigger the frame capture on our desired frame rate, making so that the frame timestamps are already recorded by default. I was wondering if this could pose any issue with the high frequency of this signal, specially should we capture on high frame rates.

b )  Recording frame timestamps on the system clock, which is possible from the camera API. But then would I be able to also get system timestamps of the synchronization pulses? Also, would recording system timestamps be less precise than recording from the camera clock?

2 -  I've noticed from my data analysis jupyter notebook that, although I have lines for saving experiment data, when it is then loaded the script just loads all files as if they are new ones. I also couldn't find a .pickle file in my data folder. Also checked that an IOerror exception is returned when the data_import script tries loading a pickle.

Thank you!

Thomas Akam

unread,
Sep 20, 2022, 6:44:30 AM9/20/22
to pyControl
Hi,

You could generate pulses to trigger each camera frame using a pyControl timer and the all_states function, as illustrated in the attached task file camera_trigger.py.   This will put a bit of load on the pycontrol framework but should be OK as long as the frame rate is not super high, e.g. 100Hz seems to work OK.  I've created an issue on the github here  to implement a better solution for this.

There is no method implemented currently for recording the time of pyControl events on the computers system clock, I guess it would be possible to modify the code that runs on the computer to to this (data_logger.py would be the place to do it), but I'm not sure how accurate it would be given the possibly variable latency in communication between the pyboard and computer.

I've noticed from my data analysis jupyter notebook that, although I have lines for saving experiment data, when it is then loaded the script just loads all files as if they are new ones. I also couldn't find a .pickle file in my data folder. Also checked that an IOerror exception is returned when the data_import script tries loading a pickle.

Using the standard data_import module, the following code works for saving an experiment to pickle and subsequently loading it when I run it from a standard python interpretter.

import data_import as di

exp_path = 'path\\to\\data\\folder'

experiment = di.Experiment(exp_path)

experiment.save() # Save data to sessions.pkl

experiment = di.Experiment(exp_path) # Reload experiment from sessions.pkl

Can you try this in a standard python interpretter to see if it works there, and if so then try it in a jupyter notebook.

T


camera_trigger.py

João Pedro Junqueira

unread,
Sep 26, 2022, 11:07:11 PM9/26/22
to pyControl
Dear Thomas,

Thank you as always for the support.

Running the lines in the terminal made me realize I forgot to add the parenthesis on the class method. It's now working as expected.

I think I'll run my lower frame-rate camera with the pulses from pyControl and watch the github issues.

Lastly, somewhat unrelated do pyControl, but I think generally useful, do you think it would be possible to run video acquisition and encoding through a GPU with only python libraries (i.e. without bonsai nodes)?

Best,
Joao.

pyControl

unread,
Oct 4, 2022, 5:50:56 AM10/4/22
to pyControl
Hi Joao,

Glad to hear you got the import code working.

Regarding doing video acqusition and encoding on the GPU with only python libraries, I have not tried it but it would be nice if it could be made to work as it would be simpler than the combined Python+Bonsai+FFMPEG pipeline we use currently (github).  The Spinnaker SDK for the FLIR (formerly Point Grey) cameras we use does have a Python API called PySpin, and there is an open source python package called simple-pyspin that looks like it provides a simpler API.  You would need to work out a way to get python to dispay the live video feeds, and either do the compression directly or stream the video to FFMPEG for compression.  I guess this would be possible but don't know how you would best go about it as I have never worked with video in Python.

best,

Thomas
Reply all
Reply to author
Forward
0 new messages