9 ct = datetime.datetime.now()
10 savedir = start_path +
'{:>04d}{:>02d}{:>02d}/'.format(ct.year, ct.month, ct.day)
16 os.makedirs(new_path, exist_ok=
True)
17 except FileExistsError:
18 print(
"Directory already exists.")
23 ms = int(1000 * (t - t_seconds))
24 stamp =
'{:d}{:d}'.format(t_seconds, ms)
29 while client[device +
'.fsm.state'] !=
'READY':
38 x = (-1.0)**(np.arange(width) - width//2)
39 y = (-1.0)**(np.arange(height) - height//2)
42 probe[15:19, 6:10] = np.outer(x, y)
43 probe[15:19, 6:10] = np.outer(y, x)
44 if direction ==
'right':
55 x = (-1.0)**(np.arange(width) - width//2)
56 y = (-1.0)**(np.arange(height) - height//2)
59 probe[8:12, 15:19] = np.outer(y, x)
60 probe[8:12, 15:19] = np.outer(x, y)
61 probe = np.sign(probe)
68 ncpc_act_grid = hp.make_pupil_grid(34, 34/30.0 * np.array([1.0, np.sqrt(2)]))
74def wait_for_state(client, indi_property, value, wait_time=1, tolerance=None):
76 while not (client[indi_property] == value):
80 while not abs(client[indi_property] - value) < tolerance:
84def calibrate_indi_device(client, device_name, device_property, delta_pertubation, camera, measurement_function, num_stack=50, do_wait=False):
85 client.get_properties(
'{:s}'.format(device_name))
87 property_current =
'{:s}.{:s}.current'.format(device_name, device_property)
88 property_target =
'{:s}.{:s}.target'.format(device_name, device_property)
89 current_position = client[property_current]
90 print(
"Probe to {:f} +- {:f}".format(current_position, delta_pertubation))
93 client[property_target] = current_position + s * delta_pertubation
95 wait_for_state(client, property_current, current_position + s * delta_pertubation, tolerance=0.1 * delta_pertubation)
101 im = camera.grab_stack(num_stack)
103 measurement = measurement_function(im)
104 slope += s * measurement / (2 * delta_pertubation)
106 client[property_target] = current_position
108 wait_for_state(client, property_current, current_position, tolerance=0.1 * delta_pertubation)
115 def __init__(self, reference_image, domain_pixels=480, domain_size=40, filter_size=None, reference_point=np.array([0,0])):
117 self.
_xgrid = hp.make_pupil_grid(domain_pixels, domain_size).shifted(reference_point)
123 if filter_size
is not None:
132 tilt = np.exp(1j * local_reference_point @ self.
_fft.output_grid.points.T)
137 ny, nx = xcorr_2d.shape
138 if ix < 1
or ix > nx - 2
or iy < 1
or iy > ny - 2:
141 patch = xcorr_2d[iy-1:iy+2, ix-1:ix+2]
142 dx, dy = np.meshgrid(np.arange(-1, 2), np.arange(-1, 2))
153 coeff, *_ = np.linalg.lstsq(A, z, rcond=
None)
154 a, b, c, d, e, _ = coeff
157 if abs(denom) < 1e-12:
160 x0 = (c*e - 2*b*d)/denom
161 y0 = (c*d - 2*a*e)/denom
163 if abs(x0) > 1.0
or abs(y0) > 1.0:
166 return np.array([x0, y0])
169 xcorr_arr = np.asarray(xcorr)
170 grid_shape = tuple(self.
_xgrid.shape)
171 xcorr_2d = xcorr_arr.reshape(grid_shape)
173 idx_max = np.argmax(xcorr_2d)
174 iy, ix = np.unravel_index(idx_max, grid_shape)
178 return self.
_xgrid.points[idx_max]
181 x_center = self.
_xgrid.x.reshape(grid_shape)[iy, ix]
182 y_center = self.
_xgrid.y.reshape(grid_shape)[iy, ix]
185 x_center + dx * self.
_xgrid.delta[0],
186 y_center + dy * self.
_xgrid.delta[1]
189 def measure(self, image, local_reference_point=np.array([0,0]), subpixel=
True):
195 indx_max = np.argmax(np.asarray(xcorr))
196 peak = self.
_xgrid.points[indx_max]
198 return peak + local_reference_point
_subpixel_peak_position(self, xcorr)
cross_correlate(self, image, local_reference_point=np.array([0, 0]))
__init__(self, reference_image, domain_pixels=480, domain_size=40, filter_size=None, reference_point=np.array([0, 0]))
_subpixel_offset_from_quadratic(self, xcorr_2d, ix, iy)
measure(self, image, local_reference_point=np.array([0, 0]), subpixel=True)
calibrate_indi_device(client, device_name, device_property, delta_pertubation, camera, measurement_function, num_stack=50, do_wait=False)
wait_for_state(client, indi_property, value, wait_time=1, tolerance=None)
make_horizontal_probe(grid, direction='left')
wait_for_ready(client, device, timeout=0.1)
make_ncpc_alignment_poke_pattern()
make_vertical_probe(grid, direction='down')
make_savedir_for_today(start_path='./Data/')
Make the save directory.