Exemple #1
0
def focus_point(mmc, delta_z=10, total_z=150):
    # Get focus model
    focus_model = miq.get_classifier()
    
    # make z position array
    cur_pos = mmc.getPosition()
    start_pos = cur_pos + total_z/2
    end_pos = cur_pos - total_z/2
    num_steps = (start_pos-end_pos) / delta_z
    z = np.linspace(start_pos, end_pos, num_steps)

    cam = utils.start_cam()

    preds = []
    for curr_z in z:
        pos.set_pos(mmc, z=curr_z)
        frame = cam.get_frame(exp_time=1).reshape(cam.sensor_size[::-1])
        preds.append(focus_model.score(frame))
    # find the index of the min focus prediction
    best_focus_index = np.argmin(preds)
    # append to the PositionList 
    last_z = z[best_focus_index]

    utils.close_cam(cam)
    return last_z
Exemple #2
0
def focus_from_image_stack(xy_points, mmc, delta_z=5, total_z=150):
    ''' Brute force focus algorthim 
    
    args: 
        xy_points: a PositionList() of the locations to 
            focus at
        mmc: Micromanger instance
        delta_z: distacne between images (um)
        total_z: total imaging distance (all focused points on 
            chip should be in this range)
    
    returns:
        focused PositionList()
    '''
    start_time = time.time()

    # Get focus model
    focus_model = miq.get_classifier()

    pos_list = pos.PositionList()

    # make z position array
    cur_pos = mmc.getPosition()
    start_pos = cur_pos + total_z/2
    end_pos = cur_pos - total_z/2
    num_steps = (start_pos-end_pos) / delta_z
    z = np.linspace(start_pos, end_pos, num_steps)

    cam = utils.start_cam()

    for posit in xy_points:
        # Go to the x,y position 
        pos.set_pos(mmc, x=posit.x, y=posit.y)

        preds = []
        for curr_z in z:
            mmc.setPosition(curr_z)
            mmc.waitForSystem()
            frame = cam.get_frame(exp_time=1).reshape(cam.sensor_size[::-1])
            preds.append(focus_model.score(frame))
        # find the index of the min focus prediction
        best_focus_index = np.argmin(preds)
        # append to the PositionList 
        sp = pos.StagePosition(x=posit.x, y=posit.y,
                               z=z[best_focus_index])
        pos_list.append(sp)
    
    utils.close_cam(cam)
    total_time = time.time() - start_time
    # print ('Completed focus in', total_time, 'seconds')
    return pos_list
Exemple #3
0
def move_to_center(mmc, center):
    currx = mmc.getXPosition()
    curry = mmc.getYPosition()

    x = center[0]
    y = center[1]
    
    x_change = (x-1344)*0.45
    y_change = (y-1100)*0.45
    
    new_x = currx-x_change
    new_y = curry-y_change
    
    pos.set_pos(mmc, x=new_x, y=new_y)
Exemple #4
0
def find_corners(mmc):
    ''' Returns a PositonList of three alignment mark locations '''

    pl = pos.PositionList()
    positions = [(0,0), (CHIP_WIDTH,0), (0,CHIP_HEIGHT)]
    model = get_inference_model()
    for posit in positions:
        pos.set_pos(mmc, x=posit[0]+mmc.getXPosition(), 
                         y=posit[1]+mmc.getYPosition())
        center, orig_frame, frame, r = find_alignment_mark(model)
        move_to_center(mmc, center)
        s = pos.StagePosition(x=mmc.getXPosition(),
                              y=mmc.getYPosition())
        pl.append(s)
    return pl
Exemple #5
0
def focus_from_last_point(xy_points, mmc, delta_z=10, total_z=150):
    start_time = time.time()

    # Get focus model
    focus_model = miq.get_classifier()

    pos_list = pos.PositionList()

    # make z position array
    cur_pos = mmc.getPosition()
    start_pos = cur_pos + total_z/2
    end_pos = cur_pos - total_z/2
    num_steps = (start_pos-end_pos) / delta_z
    z = np.linspace(start_pos, end_pos, num_steps)

    cam = utils.start_cam()

    # Go to the first x,y position 
    pos.set_pos(mmc, x=xy_points[0].x, y=xy_points[0].y)

    preds = []
    for curr_z in z:
        pos.set_pos(mmc, z=curr_z)
        frame = cam.get_frame(exp_time=1).reshape(cam.sensor_size[::-1])
        preds.append(focus_model.score(frame))
    # find the index of the min focus prediction
    best_focus_index = np.argmin(preds)
    # append to the PositionList 
    last_z = z[best_focus_index]
    sp = pos.StagePosition(x=xy_points[0].x, y=xy_points[0].y,
                            z=last_z)
    pos_list.append(sp)

    z_range = range(-35, 35, 10)

    for i, posit in enumerate(xy_points):
        # We already did the first point
        if i == 0:
            best_focus_index = 0
            continue
        
        preds = []
        # Go to the next x,y position with the previous best focus 
        pos.set_pos(mmc, x=posit.x, y=posit.y, z=last_z)
        # frame = cam.get_frame(exp_time=1).reshape(cam.sensor_size[::-1])
        # first_score = focus_model.score(frame)
        
        if best_focus_index > 3.5:
            # Reverse the order of the list
            z_range = z_range[::-1]

        # Build list from last position
        # in order that makes sense 
        z_list = [(last_z+i) for i in z_range]

        for j, curr_z in enumerate(z_list):
            pos.set_pos(mmc, z=curr_z)
            frame = cam.get_frame(exp_time=1).reshape(cam.sensor_size[::-1])
            preds.append(focus_model.score(frame))

            if j > 0:
                if preds[j] > preds[j-1]:
                    # Focus got worse
                    break

        
        # find the index of the min focus prediction
        best_focus_index = np.argmin(preds)
        # append to the PositionList 
        last_z = z_list[best_focus_index]
        sp = pos.StagePosition(x=posit.x, y=posit.y,
                                z=last_z)
        pos_list.append(sp)
    
    utils.close_cam(cam)
    total_time = time.time() - start_time
    # print ('Completed focus in', total_time, 'seconds')
    return pos_list