|
| 1 | +# Simple python script to use Pyth0n-Microscope |
| 2 | +# https://github.com/python-microscope/microscope |
| 3 | +# to produce a time laspe image series. |
| 4 | + |
| 5 | +# Example code for a time-series experiment with hardware |
| 6 | +# triggers. In the hardware, this experiment requires the camera |
| 7 | +# digital output line to be connected to the laser digital input |
| 8 | +# line, so that the camera emits a high TTL |
| 9 | +# signal while its sensor is being exposed. In the code, the laser |
| 10 | +# is configured as to emit light only while receiving a high TTL |
| 11 | +# input signal. The example triggers the camera a specific number |
| 12 | +# times with a time interval between exposures. The acquired |
| 13 | +# images are put in the buffer asynchronously. The images are taken |
| 14 | +# from the queue at the end of the experiment and saved to a file. |
| 15 | + |
| 16 | +import time |
| 17 | +from queue import Queue |
| 18 | +from microscope import TriggerMode, TriggerType |
| 19 | +from microscope.cameras.pvcam import PVCamera |
| 20 | +from microscope.lights.toptica import TopticaiBeam |
| 21 | +from tifffile import TiffWriter |
| 22 | + |
| 23 | +#set parameters |
| 24 | +n_repeats = 10 |
| 25 | +interval_seconds = 15 |
| 26 | +exposure_seconds = .5 |
| 27 | +power_level = .5 |
| 28 | + |
| 29 | +#create devices |
| 30 | +camera = PVCamera() |
| 31 | +laser = TopticaiBeam(port="COM1") |
| 32 | + |
| 33 | +#initialise buffer as a queue |
| 34 | +image_buffer = Queue() |
| 35 | + |
| 36 | +#configure camera, pass the buffer queue and enable. |
| 37 | +camera.set_client(image_buffer) |
| 38 | +camera.exposure_time = exposure_seconds |
| 39 | +camera.set_trigger(TriggerType.SOFTWARE, TriggerMode.ONCE) |
| 40 | +camera.enable() |
| 41 | + |
| 42 | +#configure laser |
| 43 | +laser.power = power_level |
| 44 | +laser.set_trigger(TriggerType.HIGH, TriggerMode.BULB) |
| 45 | +laser.enable() |
| 46 | + |
| 47 | +#main loop to collect images. |
| 48 | +for i in range(n_repeats): |
| 49 | + camera.trigger() |
| 50 | + time.sleep(interval_seconds) |
| 51 | + |
| 52 | +#shutdown hardware devices |
| 53 | +laser.shutdown() |
| 54 | +camera.shutdown() |
| 55 | + |
| 56 | +#write out image data to a file. |
| 57 | +writer = TiffWriter("data.tif") |
| 58 | +for i in range(n_repeats): |
| 59 | + writer.save(image_buffer.get()) |
| 60 | +writer.close() |
0 commit comments