python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
73 stars 42 forks source link

pvcam camera.get_exposure_time does not return real exposure time in bulb mode #275

Open VroniPfann opened 1 year ago

VroniPfann commented 1 year ago

I realized that when using the Kinetix in bulb mode camera.get_cycle_time and camera.get_exposure_time do not return the real values, which kind of makes sense I guess since they are not set in the software. I noticed this because I thought to use those values to calculate my timings for hardware triggering on the RedPitaya. Does it make sense to return something else, like for example length of the hardware trigger in this case? Not sure if this needs to be fixed on the python-microscope level or my experiment script level. Please see the code that I am running below. Thanks!

LIGHT_TO_EXPOSURE = [
    # light-name, exposure-in-msec
    ("laser3", 500),
    ("laser6", 200),
    ("laser7", 300),
]

camera = PVCamera()
camera.set_trigger(microscope.TriggerType.HIGH,
                   microscope.TriggerMode.BULB)
camera_buffer = Queue()
camera.set_client(camera_buffer)
camera.enable()

actions = []

running_time = 0.0
for light_name, emitting_time in LIGHT_TO_EXPOSURE:
    mask = CAMERA_EXECUTOR_LINE | LIGHT_TO_EXECUTOR_LINE[light_name]
    action = (running_time, (mask, [0, 0]))
    actions.append(action)
    # Turn off the laser
    running_time += emitting_time
    action = (running_time, (0, [0, 0]))
    actions.append(action)
    # Wait until camera stops exposing
    running_time += (camera.get_cycle_time() - camera.get_exposure_time()) * 1000  #-> **returns not real value here**
    ## Prepare for next acquisition 
    actions.append((running_time, (0, [0, 0])))  # wait before start next repetition

executor.PrepareActions(actions, N_TIMEPOINTS)
iandobbie commented 1 year ago

I think we need o think carefully before overloading the existing functions. Not sure of the best solution but maybe we need a readout_time to find just the readout time and allow the proper timing calculations in this mode.