MScan 2.1 brings new scripting capabilities to easily develop and run close-loop experiments based on functional imaging with multiphoton microscopy. Particular attention was devoted to optimizing the response time of scripting functions.
The StartDigitalTrain and StartAnalogTrain functions introduced in the previous post are fast enough to be used in non-resonant scanning experiments, but with resonant scanning we recommend using the new scripting methods SetDigitalTrain, SetAnalogTrain, FireDigitalTrain and FireAnalogTrain.
SetDigitalTrain and SetAnalogTrain are quite similar to their counterparts StartDigitalTrain and StartAnalogTrain with the exception that they do not output the train. SetDigitalTrain and SetAnalogTrain can be used for instance in the On Scanning Starts event to set up and arm either a digital or an analog train. Train delivery can be done with minimal latency using FireDigitalTrain or FireAnalogTrain, for instance when processing ROIs in the On New Frames event handler. If an analogy with electronics can be made, the pairs of scripting functions SetDigitalTrain/FireDigitalTrain and SetAnalogTrain/FireAnalogTrain are similar to non-retriggerable, one-shot train stimulators. Resetting the stimulators is automatically performed when the imaging run terminates, regardless of whether the train was delivered or not.
We performed initial benchmarks to measure and optimize the latency of script-triggered delivery of digital trains in resonant scanning mode, which is arguably the most demanding situation to run scripts driven by frame acquisition. The latencies result from delays to:
(1) get the imaging data from the acquisition board to memory,
(2) process frame data (mostly reordering pixels into an image, adding offsets etc…),
(3) signal threads that frame data is available,
(4) activate the scripting interpreter,
(5) execute the user-written code in the On New Frames handler
(6) and deliver the digital train;
The tests were conducted in resonant scanning mode using a protocol involving simultaneous acquisition and real-time display of two imaging channels and two analog channels with each analog channel sampled at 20 kHz. The first analog channel recorded the motion of the “slow” Y mirror to give accurate timing of frame acquisition while the second analog channel was connected to the digital output of the analog board. MScan was set to process every frame individually rather than in batches as soon as frames arrived.
The script executed SetDigitalTrain in the On Scanning Starts event handler to set up a train consisting of ten pulses of 10 ms duration each. The On New Frames executed the user-written code:
If CurrentFrameIndex = 20 Then FireDigitalTrain
to deliver the digital train immediately after the 20th imaging frame was scanned and processed.
With 512 x 512 frames sampled at 31 fps, the latency from the mirror position at the end of the 20th frame to the beginning of the pulse train ranged from 15 to 17 ms. In comparison, the frame interval was 32 ms. In other words, MScan can react asynchronously to run user-written scripts and deliver stimuli in less time than the sampling interval of two-photon imaging, even in resonant scanning mode. Similarly, we obtained a near real-time latency of only 8-10 ms with frames sampled at 94 fps (512 x 170 frames). We found that most of the latencies in both cases were due to waiting for the device driver of the acquisition board to complete Step 1 described above.
We are looking forward to hear from scientists running cutting-edge, script-based close-loop experiments with the MOM and MCS.