Beispiel #1
0
def verify_data(func, desc, DAQ, instrs, adv, steps, j=0):
    dataset = DAQ.dataset
    good = True
    for serial, instr, in instrs.items():
        root = instr.data_type
        path = file.get_dirName(root, dataset)
        ending = file.get_file_ending(root)
        for i in range(steps):
            filename = file.get_fileName(serial, dataset, i)
            if not os.path.isfile(path + filename + ending):
                print('File {:s} is missing'.format(path + filename + ending))
                good = False
    if not good and j < 10:
        j += 1
        print(
            'Dataset {:s} is missing shots, retaking for the {:d} time'.format(
                str(dataset), j))
        TC = DAQ.instr[DAQ.TC_serial]
        DAQ.send_command(TC, 'reset', steps)
        time.sleep(0.1)
        DAQ.send_command(TC, 'start')
        func(desc, DAQ, instrs, adv, j)
    elif not good and i >= 10:
        print('Maximum retakes exceeded, saving last dataset')
        if adv:
            DAQ.adv_dataset(desc)
    else:
        print('Dataset {:s} is checked and has all {:d} shots'.format(
            str(dataset), steps))
        if adv:
            DAQ.adv_dataset(desc)
Beispiel #2
0
def main(start, stop, incr, desc):
    """ Run the sweep, does not include <stop> in the positions. """
    start = float(start)
    stop = float(stop)
    incr = float(incr)
    positions = np.arange(start, stop, incr)
    N = len(positions)
    DAQ = daq.Daq(broadcast=False, print_normal=True)
    ID = check_log()
    add_to_log(ID)
    global META_PATH
    META_PATH = file.get_dirName('META', '') + str(ID) + '.txt'
    create_meta(desc)

    # Connect all devices we want to use
    devices = connect_instruments(DAQ)
    if devices is None:
        DAQ.close_daq()
        return
    NF, FF, stage_cam, xps, sdg, TC = devices
    DAQ.create_dir_struct()
    # Handle the XPS directly rather than through the DAQ
    print('Connecting XPS motor controller')
    xps_dev = xps.device_cls(xps.address)
    time.sleep(5)
    print('Finished waiting 5s for instruments to connect')
    # Config any instrument settings that we want to make sure are correct
    config_instruments(DAQ, NF, FF, stage_cam)

    # Take the initial dataset
    pos = move_stage(positions[0], xps_dev)
    instrs = {
        NF.serial: NF,
        FF.serial: FF,
    }
    append_meta('Initial laser parameters:\t{:s}'.format(str(DAQ.dataset)))
    take_laser('Initial laser parameters', DAQ, instrs)

    # Move the stage and take a dataset at each position
    instrs = {
        stage_cam.serial: stage_cam,
        #FF.serial: FF,
    }
    for i in range(N):
        pos = move_stage(positions[i], xps_dev)
        step_desc = 'Step:\t{:d}\t{:0.3f}'.format(i + 1, pos)
        append_meta('Step:\t{:0.3f}\t{:s}'.format(pos, str(DAQ.dataset)))
        take_step(step_desc, DAQ, instrs)
        adjust_gain()

    # Take the final dataset
    instrs = {
        NF.serial: NF,
        FF.serial: FF,
    }
    append_meta('Final laser parameters:\t{:s}'.format(str(DAQ.dataset)))
    take_laser('Final laser parameters', DAQ, instrs, adv=False)
    DAQ.close_daq()
Beispiel #3
0
def check_log():
    """ Create a log for each day that assigns a unique ID to each sweep. """
    dirName = file.get_dirName('META', '')
    # If the sweep log file doesn't exist for today, make it
    if not os.path.isfile(dirName + 'sweep_log.txt'):
        with open(dirName + 'sweep_log.txt', 'w') as f:
            f.writelines("# Sweeps taken\n")
        f.close()
        return 1
    # If it does exist, figure out which sweep this is
    else:
        with open(dirName + 'sweep_log.txt', 'r') as f:
            data = f.readlines()
        f.close()
        sweepPrev = data[-1]
        return int(sweepPrev) + 1
Beispiel #4
0
def add_to_log(ID):
    dirName = file.get_dirName('META', '')
    with open(dirName + 'sweep_log.txt', 'a') as f:
        f.write(str(ID) + '\n')
    f.close()