def do_scan(S, K, max_ai_clock_rate, ai_task, ao_task, do_task, N, M, pixel_time, scan_speed, pixel_size_x, alpha, roi, cache=None): key = (S, K, N, M, pixel_time, scan_speed, alpha, roi) flyback_ratio = K / N flystart_ratio = S / K sample_clock = SampleClock(pixel_time=pixel_time * 1e-6, pixel_size=pixel_size_x * 1e-6) T, clock_rate, min_clock_rate = sample_clock.get_optimal_scanning_parameters( verbose=False) mirror = MirrorDriver(image_size=(N, M), T=T, flyback_ratio=flyback_ratio, flystart_ratio=flystart_ratio, alpha=alpha, roi=roi, clock_rate=clock_rate, verbose=False) output_input_clock_ratio = min(int(clock_rate / max_ai_clock_rate) + 1, T) while mirror.T % output_input_clock_ratio: output_input_clock_ratio += 1 ai_clock_rate = clock_rate // output_input_clock_ratio result = None if cache is not None: result = cache.data.get(key) if result is None: vx_target = mirror.vx_t_array() vy_target = mirror.vy_t_array() i_target = mirror.i_t_array() j_target = mirror.j_t_array() ai_task.configure_timing_sample_clock( rate=ai_clock_rate, active_edge='rising', sample_mode='finite', samples_per_channel=vx_target.size) ao_task.configure_timing_sample_clock( rate=clock_rate, active_edge='rising', sample_mode='finite', samples_per_channel=vx_target.size) # first iteration vx_input = vx_target vy_input = vy_target vx_pos, vy_pos, vx_err, vy_err = run_mirrors(ao_task, ai_task, do_task, vx_input, vy_input, output_input_clock_ratio) i_pos = mirror.i_v(vx_pos, vy_pos) j_pos = mirror.j_v(vx_pos, vy_pos) toffset, ioffset, joffset, ioffset_std, joffset_std, ioffset_max, joffset_max = mirror.estimate_offsets( i_target, j_target, i_pos, j_pos) # second iteration mirror.set_params(t_offset=toffset + mirror.t_offset) vx_input = mirror.vx_t_array() vy_input = mirror.vy_t_array() vx_pos, vy_pos, vx_err, vy_err = run_mirrors(ao_task, ai_task, do_task, vx_input, vy_input, output_input_clock_ratio) i_pos = mirror.i_v(vx_pos, vy_pos) j_pos = mirror.j_v(vx_pos, vy_pos) toffset, ioffset, joffset, ioffset_std, joffset_std, ioffset_max, joffset_max = mirror.estimate_offsets( i_target, j_target, i_pos, j_pos) # third iteration mirror.set_params( i_offset=ioffset + mirror.i_offset, j_offset=joffset + mirror.j_offset, ) vx_input = mirror.vx_t_array() vy_input = mirror.vy_t_array() vx_pos, vy_pos, vx_err, vy_err = run_mirrors(ao_task, ai_task, do_task, vx_input, vy_input, output_input_clock_ratio) i_pos = mirror.i_v(vx_pos, vy_pos) j_pos = mirror.j_v(vx_pos, vy_pos) i_input = mirror.i_v(vx_input, vy_input) j_input = mirror.j_v(vx_input, vy_input) result = vx_target, vy_target, i_target, j_target, vx_input, vy_input, i_input, j_input, vx_pos, vy_pos, i_pos, j_pos, vx_err, vy_err if cache is not None: cache.data[key] = result cache.dump() else: print 'Using cache for key=', key vx_target, vy_target, i_target, j_target, vx_input, vy_input, i_input, j_input, vx_pos, vy_pos, i_pos, j_pos, vx_err, vy_err = result toffset, ioffset, joffset, ioffset_std, joffset_std, ioffset_max, joffset_max = mirror.estimate_offsets( i_target, j_target, i_pos, j_pos) print 'XXX:', pixel_time, scan_speed, N, M, K, T, '->', toffset, ioffset, joffset, ioffset_std, joffset_std from ioc.microscope.regress import regress regress_scale = min(1, 20 / N) i_pos, i_pos_grad = regress(i_pos, (regress_scale, ), method='average') j_pos, j_pos_grad = regress(j_pos, (regress_scale, ), method='average') vx_pos, vx_pos_grad = regress(vx_pos, (regress_scale, ), method='average') vy_pos, vy_pos_grad = regress(vy_pos, (regress_scale, ), method='average') plt = mk_figure(vx_target, vy_target, i_target, j_target, vx_input, vy_input, i_input, j_input, vx_pos, vy_pos, i_pos, j_pos, vx_err, vy_err, mirror, sample_clock, output_input_clock_ratio) plt.xlabel('ioffset=%s(%.3f,%.3f), joffset=%s(%.3f,%.3f), toffset=%s' % (ioffset, ioffset_std, ioffset_max, joffset, joffset_std, joffset_max, toffset)) plt.draw() plt.show() return ioffset_max
def do_scan(S, K, max_ai_clock_rate, ai_task, ao_task, do_task, N, M, pixel_time, scan_speed, pixel_size_x, alpha, roi, cache = None): key = (S, K, N, M, pixel_time, scan_speed, alpha, roi) flyback_ratio = K/N flystart_ratio = S/K sample_clock = SampleClock(pixel_time = pixel_time * 1e-6, pixel_size = pixel_size_x * 1e-6) T, clock_rate, min_clock_rate = sample_clock.get_optimal_scanning_parameters(verbose=False) mirror = MirrorDriver(image_size = (N,M), T=T, flyback_ratio = flyback_ratio, flystart_ratio = flystart_ratio, alpha = alpha, roi = roi, clock_rate = clock_rate, verbose=False) output_input_clock_ratio = min(int(clock_rate / max_ai_clock_rate)+1, T) while mirror.T % output_input_clock_ratio: output_input_clock_ratio += 1 ai_clock_rate = clock_rate // output_input_clock_ratio result = None if cache is not None: result = cache.data.get(key) if result is None: vx_target = mirror.vx_t_array() vy_target = mirror.vy_t_array() i_target = mirror.i_t_array() j_target = mirror.j_t_array() ai_task.configure_timing_sample_clock(rate = ai_clock_rate, active_edge = 'rising', sample_mode = 'finite', samples_per_channel = vx_target.size ) ao_task.configure_timing_sample_clock(rate = clock_rate, active_edge = 'rising', sample_mode = 'finite', samples_per_channel = vx_target.size ) # first iteration vx_input = vx_target vy_input = vy_target vx_pos, vy_pos, vx_err, vy_err = run_mirrors(ao_task, ai_task, do_task, vx_input, vy_input, output_input_clock_ratio) i_pos = mirror.i_v(vx_pos, vy_pos) j_pos = mirror.j_v(vx_pos, vy_pos) toffset, ioffset, joffset, ioffset_std, joffset_std, ioffset_max, joffset_max = mirror.estimate_offsets(i_target, j_target, i_pos, j_pos) # second iteration mirror.set_params(t_offset=toffset + mirror.t_offset) vx_input = mirror.vx_t_array() vy_input = mirror.vy_t_array() vx_pos, vy_pos, vx_err, vy_err = run_mirrors(ao_task, ai_task, do_task, vx_input, vy_input, output_input_clock_ratio) i_pos = mirror.i_v(vx_pos, vy_pos) j_pos = mirror.j_v(vx_pos, vy_pos) toffset, ioffset, joffset, ioffset_std, joffset_std, ioffset_max, joffset_max = mirror.estimate_offsets(i_target, j_target, i_pos, j_pos) # third iteration mirror.set_params(i_offset=ioffset + mirror.i_offset, j_offset=joffset + mirror.j_offset, ) vx_input = mirror.vx_t_array() vy_input = mirror.vy_t_array() vx_pos, vy_pos, vx_err, vy_err = run_mirrors(ao_task, ai_task, do_task, vx_input, vy_input, output_input_clock_ratio) i_pos = mirror.i_v(vx_pos, vy_pos) j_pos = mirror.j_v(vx_pos, vy_pos) i_input = mirror.i_v(vx_input, vy_input) j_input = mirror.j_v(vx_input, vy_input) result = vx_target, vy_target, i_target, j_target, vx_input, vy_input, i_input, j_input, vx_pos, vy_pos, i_pos, j_pos, vx_err, vy_err if cache is not None: cache.data[key] = result cache.dump() else: print 'Using cache for key=', key vx_target, vy_target, i_target, j_target, vx_input, vy_input, i_input, j_input, vx_pos, vy_pos, i_pos, j_pos, vx_err, vy_err = result toffset, ioffset, joffset, ioffset_std, joffset_std, ioffset_max, joffset_max = mirror.estimate_offsets(i_target, j_target, i_pos, j_pos) print 'XXX:', pixel_time, scan_speed, N,M,K,T,'->',toffset, ioffset, joffset, ioffset_std, joffset_std from ioc.microscope.regress import regress regress_scale = min(1, 20/N) i_pos, i_pos_grad = regress(i_pos, (regress_scale,), method='average') j_pos, j_pos_grad = regress(j_pos, (regress_scale,), method='average') vx_pos, vx_pos_grad = regress(vx_pos, (regress_scale,), method='average') vy_pos, vy_pos_grad = regress(vy_pos, (regress_scale,), method='average') plt = mk_figure(vx_target, vy_target, i_target, j_target, vx_input, vy_input, i_input, j_input, vx_pos, vy_pos, i_pos, j_pos, vx_err, vy_err, mirror, sample_clock, output_input_clock_ratio ) plt.xlabel('ioffset=%s(%.3f,%.3f), joffset=%s(%.3f,%.3f), toffset=%s' % (ioffset, ioffset_std, ioffset_max, joffset, joffset_std, joffset_max, toffset)) plt.draw() plt.show() return ioffset_max
flyback_data = pos_dict[scan_speed] legends.append('%.3f m/s' % (scan_speed)) flyback, data = zip(*flyback_data) plt.semilogy(flyback, data, 'x') plt.title('Scan speed - flyback ratio curves: %s' % (title)) plt.xlabel('flyback ratio') plt.ylabel('position resolution, um') plt.legend(legends) plt.show() return pixel_size = options.pixel_size_um * 1e-6 # m if options.image_width is None: image_width = MirrorDriver.compute_image_width(options.roi_x0, options.roi_x1, pixel_size) else: image_width = options.image_width pixel_size = MirrorDriver.compute_pixel_size_x(options.roi_x0, options.roi_x1, image_width) # m scan_speed = options.scan_speed # m/sec if options.pixel_time_usec is None: pixel_time = pixel_size / scan_speed # sec else: pixel_time = options.pixel_time_usec * 1e-6 # sec
for scan_speed in scan_speed_list: flyback_data = pos_dict[scan_speed] legends.append ('%.3f m/s' % (scan_speed)) flyback, data = zip (*flyback_data) plt.semilogy(flyback,data, 'x') plt.title('Scan speed - flyback ratio curves: %s' % (title)) plt.xlabel('flyback ratio') plt.ylabel('position resolution, um') plt.legend(legends) plt.show() return pixel_size = options.pixel_size_um * 1e-6 # m if options.image_width is None: image_width = MirrorDriver.compute_image_width(options.roi_x0, options.roi_x1, pixel_size) else: image_width = options.image_width pixel_size = MirrorDriver.compute_pixel_size_x(options.roi_x0, options.roi_x1, image_width) # m scan_speed = options.scan_speed # m/sec if options.pixel_time_usec is None: pixel_time = pixel_size / scan_speed # sec else: pixel_time = options.pixel_time_usec*1e-6 # sec scan_speed = pixel_size / pixel_time if options.flyback is None: