""" automated sample finder for the Y axis (TESTING) the script first runs a coarse scan to find the lower and upper edges of the sample. after that it runs a fine scan on either edge. set the scienta to a clear peak in fixed mode. """ import math # estimated center of the sample START_POS = 0.0 # coarse scan range = estimated size of the sample + margins COARSE_RANGE = 10.0 # scienta dwell time (fixed mode) DWELL_TIME = 0.1 # --- do not edit below --- RELATIVE = False LATENCY = 0.0 ZIGZAG = False ENDSCAN = False SENSORS = (Counts, SampleCurrent, RefCurrent, MachineCurrent) MOTORS = (ManipulatorY) RANGE = (START_POS + COARSE_RANGE / 2., START_POS - COARSE_RANGE / 2.) Scienta.setExposure(DWELL_TIME) #scienta_time = DWELL_TIME + 0.1 # time per scienta acquisition in seconds trig_scienta() time1 = time.time() trig_scienta() time.sleep(0.01) time2 = time.time() scienta_time = (time2 - time1) + 1. print "step time: ", scienta_time STEP = 0.25 SPEED = MOTORS[0].getSpeed() fly_time = abs(RANGE[1] - RANGE[0]) / SPEED STEPS = int(fly_time / scienta_time) + 1 print "coarse scan" print "speed: ", SPEED print "scan time: ", fly_time set_exec_pars(keep=True) adjust_sensors() set_adc_averaging() result = cscan(MOTORS, SENSORS, RANGE[0], RANGE[1], STEPS, time=fly_time, before_read=before_readout, after_read = after_readout, check_positions = False) readable = result.getReadable(0) positions = result.getPositions(0) min_counts = min(readable) max_counts = max(readable) thresh = (max_counts - min_counts) / 2. + min_counts print "threshhold: ", thresh sample_positions = [pos for idx, pos in enumerate(positions) if readable[idx] >= thresh] lo_edge = min(sample_positions) hi_edge = max(sample_positions) print "lower edge, upper edge: ", lo_edge, ", ", hi_edge RANGE = (lo_edge - 0.4, lo_edge + 0.4) STEP = 0.025 SPEED = STEP / scienta_time fly_time = abs(RANGE[1] - RANGE[0]) / SPEED STEPS = int(fly_time / scienta_time) + 1 print "lower edge scan" print "speed: ", SPEED print "scan time: ", fly_time cscan(MOTORS, SENSORS, RANGE[0], RANGE[1], STEPS, time=fly_time, before_read=before_readout, after_read = after_readout, check_positions = False) RANGE = (hi_edge - 0.4, hi_edge + 0.4) STEP = 0.025 SPEED = STEP / scienta_time fly_time = abs(RANGE[1] - RANGE[0]) / SPEED STEPS = int(fly_time / scienta_time) + 1 print "upper edge scan" print "speed: ", SPEED print "scan time: ", fly_time cscan(MOTORS, SENSORS, RANGE[0], RANGE[1], STEPS, time=fly_time, before_read=before_readout, after_read = after_readout, check_positions = False) MOTORS.move((lo_edge + hi_edge) / 2)