-
Notifications
You must be signed in to change notification settings - Fork 0
/
zig_zag_scan.py
69 lines (50 loc) · 1.91 KB
/
zig_zag_scan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""---\nThis session shows how to implement a simple zig-zag scan using
two motors for horizontal (x_motor) and vertical movement (z_motor) as well as
a detector. The result is an image composed of all scanned tiles.
Usage:
result = await zig_zag_scan()
"""
import concert
concert.require('0.31')
import numpy as np
import scipy.misc
import matplotlib.pyplot as plt
from concert.quantities import q
from concert.session.utils import ddoc, dstate, pdoc
from concert.devices.cameras.dummy import Camera
from concert.devices.motors.dummy import LinearMotor
from concert.ext.viewers import PyplotImageViewer
# Create a camera with noisy background
camera = await Camera(background=scipy.misc.ascent())
# Assume motors' zero coordinate is left and up respectively
x_motor = await LinearMotor()
z_motor = await LinearMotor()
viewer = await PyplotImageViewer()
async def zig_zag_scan(num_images_horizontally=2, num_images_vertically=2,
pixel_size=5*q.micrometer):
await x_motor.set_position(0 * q.micrometer)
await z_motor.set_position(0 * q.micrometer)
width = pixel_size * (await camera.get_roi_width())
height = pixel_size * (await camera.get_roi_height())
delta = +width
final_image = None
for i in range(num_images_vertically):
image_row = None
for j in range(num_images_horizontally):
await x_motor.move(delta)
frame = np.copy(await camera.grab())
if image_row is None:
image_row = frame
else:
image_row = np.hstack((image_row, frame))
z_f = z_motor.move(height)
# Move in the other direction
delta *= -1
# Add row to our final image
if final_image is None:
final_image = image_row
else:
final_image = np.vstack((final_image, image_row))
await z_f
await viewer.show(final_image)
return final_image