Beispiel #1
0
def compare_many(A, pos_A, B, pos_B, frames, savepath=""):
    pos_A_copy = pos_A.copy()
    pos_B_copy = pos_B.copy()
    
    #Make the directory to save the frames
    directory = os.getcwd() + savepath
    if(savepath != ""):
        if( not os.path.isdir(directory) ):
            os.makedirs(directory)
    
    geom_A = get_bounds_and_radius(pos_A)
    r_A = geom_A[0]
    
    geom_B = get_bounds_and_radius(pos_B)
    r_B = geom_B[0]
            
    for i in range(0, frames):
        
        pth=""
        if(savepath != ""):
            pth = "." + savepath + str("/frame-" + str(i+1))
            
        calc_values_height_reorient(A, pos_A_copy, math.pi/2 + 2*math.pi/frames)
        calc_values_height_reorient(B, pos_B_copy, math.pi/2 + 2*math.pi/frames)
        
        mA = merge_tree(A)
        mB = merge_tree(B)
        
        print("A reduced: " + str(reduced(mA)))
        print("B reduced: " + str(reduced(mB)))
        
        compare_square(mA, pos_A_copy, r_A, mB, pos_B_copy, r_B, pth)
def get_data_point(G1,
                   pos1,
                   G2,
                   pos2,
                   angle,
                   index,
                   data,
                   rotate_both=True,
                   accuracy=0.0001):

    p1 = pos1.copy()
    p2 = pos2.copy()
    G1c = G1.copy()
    G2c = G2.copy()

    if (rotate_both):
        calc_values_height_reorient(G1c, p1, angle)
    else:
        calc_values_height_reorient(G1c, p1)

    M1 = merge_tree(G1c, shift=True)

    calc_values_height_reorient(G2c, p2, angle)
    M2 = merge_tree(G2c, shift=True)

    dist = Compare.branching_distance(M1, M2, accuracy)
    data.append((index, dist))
    return (index, dist)
Beispiel #3
0
def input_output_square(G, pos, r, savepath=""):
    fig = plt.subplots(1,3,figsize=(15,5))
    
    #Figure out the bounds
    geom = get_bounds_and_radius(pos)
    b = geom[1]
    xAvg = (b[0][1]+b[0][0])/2
    yAvg = (b[1][1]+b[1][0])/2
    
    
    #Show the input
    ax = plt.subplot(131, frameon=False)
    ax.set_xlim(xAvg - r/2, xAvg + r/2)
    ax.set_ylim(yAvg - r/2, yAvg + r/2)
    draw(G, pos, "Input Graph", ax)
    
    #Add the COOL arrow
    ax = plt.subplot(132, frameon=False)
    add_arrow(ax)
    
    #Show the output
    calc_values_height(G, pos, math.pi / 2)
    M = merge_tree(G)
    ax = plt.subplot(133, frameon=False)
    ax.set_xlim(xAvg - r/2, xAvg + r/2)
    ax.set_ylim(yAvg - r/2, yAvg + r/2)
    draw(M, pos, "Resulting Merge Tree", ax)
    
    #Save the image if specified
    if(savepath != ""):
        plt.savefig(savepath)
    
    plt.show()
    plt.close()
Beispiel #4
0
def cool_GIF(G1, pos1, G2, pos2, frames=720, rotate_both=True, gif_name="cool_gif", fps=30, delete_frames=True):
    data = distance_data(G1, pos1, G2, pos2, frames=frames, rotate_both=rotate_both)
    pth = "./images/frames"
    
    r1 = get_bounds_and_radius(pos1)[0]
    r2 = get_bounds_and_radius(pos2)[0]
    
    #Make sure the gif is 8 seconds long
    fps = frames/8
    
    for i in range(0, frames):
        if frames <=5:
            print("Working on frame", i, "...")
        elif frames <= 100:
            if i % 5 == 0:
                print("Working on frame", i, "...")
        else:
            if i % 25 == 0:
                print("Working on frame", i, "...")
        p1 = pos1.copy()
        p2 = pos2.copy()
        G1c = G1.copy()
        G2c = G2.copy()
    
        calc_values_height_reorient(G1c, p1, math.pi*(1/2 + 2*i/(frames)))
        M1 = merge_tree(G1c, shift=True)
        
        calc_values_height_reorient(G2c, p2, math.pi*(1/2 + 2*i/(frames)))
        M2 = merge_tree(G2c, shift=True)
        
        cool(M1, p1, M2, p2, G2c, data, i, r1, r2, savepath=pth, rotate_both=True, G1=G1c)
        
    file_list = glob.glob('./images/frames/*.png') # Get all the pngs in the current directory
    list.sort(file_list, key=lambda x: int(x.split('_')[1].split('.png')[0])) # Sort the images by #, this may need to be tweaked for your use case
    clip = mpy.ImageSequenceClip(file_list, fps=fps)
    clip.write_gif('{}.gif'.format(gif_name), fps=fps)
    
    #Delete the frames
    if(delete_frames):
        
        filelist = [ f for f in os.listdir("./images/frames")]
        for f in filelist:
            os.remove(os.path.join("./images/frames", f))
Beispiel #5
0
def input_output(G, pos, savepath=""):
    fig = plt.subplots(1,3,figsize=(15,5))
    
    #Show the input
    ax = plt.subplot(131, frameon=False)
    draw(G, pos, "Input Graph", ax)
    
    #Add the COOL arrow
    ax = plt.subplot(132, frameon=False)
    add_arrow(ax)
    
    #Show the output
    calc_values_height(G, pos, math.pi / 2)
    M = merge_tree(G)
    ax = plt.subplot(133, frameon=False)
    draw(M, pos, "Resulting Merge Tree", ax)
    
    #Save the image if specified
    if(savepath != ""):
        plt.savefig(savepath)
    
    plt.show()
    plt.close()