Ejemplo n.º 1
0
def test_klusters_save():
    """WARNING: this test should occur at the end of the module since it
    changes the mock data sets."""
    # Open the mock data.
    dir = TEST_FOLDER
    xmlfile = os.path.join(dir, 'test.xml')
    l = KlustersLoader(filename=xmlfile)
    
    clusters = l.get_clusters()
    cluster_colors = l.get_cluster_colors()
    cluster_groups = l.get_cluster_groups()
    group_colors = l.get_group_colors()
    group_names = l.get_group_names()
    
    # Set clusters.
    indices = get_indices(clusters)
    l.set_cluster(indices[::2], 2)
    l.set_cluster(indices[1::2], 3)
    
    # Set cluster info.
    cluster_indices = l.get_clusters_unique()
    l.set_cluster_colors(cluster_indices[::2], 10)
    l.set_cluster_colors(cluster_indices[1::2], 20)
    l.set_cluster_groups(cluster_indices[::2], 1)
    l.set_cluster_groups(cluster_indices[1::2], 0)
    
    # Save.
    l.remove_empty_clusters()
    l.save()
    
    clusters = read_clusters(l.filename_aclu)
    cluster_info = read_cluster_info(l.filename_acluinfo)
    
    assert np.all(clusters[::2] == 2)
    assert np.all(clusters[1::2] == 3)
    
    assert np.array_equal(cluster_info.index, cluster_indices)
    assert np.all(cluster_info.values[::2, 0] == 10)
    assert np.all(cluster_info.values[1::2, 0] == 20)
    assert np.all(cluster_info.values[::2, 1] == 1)
    assert np.all(cluster_info.values[1::2, 1] == 0)

    l.close()
    
    
    
Ejemplo n.º 2
0
def test_cluster_info():
    dir = TEST_FOLDER
    clufile = os.path.join(dir, 'test.aclu.1')
    cluinfofile = os.path.join(dir, 'test.acluinfo.1')

    clusters = read_clusters(clufile)
    
    indices = np.unique(clusters)
    colors = np.random.randint(low=0, high=10, size=len(indices))
    groups = np.random.randint(low=0, high=2, size=len(indices))
    cluster_info = pd.DataFrame({'color': pd.Series(colors, index=indices),
        'group': pd.Series(groups, index=indices)})
    
    save_cluster_info(cluinfofile, cluster_info)
    cluster_info2 = read_cluster_info(cluinfofile)
    
    assert np.array_equal(cluster_info.values, cluster_info2.values)
Ejemplo n.º 3
0
def test_klusters_save():
    """WARNING: this test should occur at the end of the module since it
    changes the mock data sets."""
    # Open the mock data.
    dir = TEST_FOLDER
    xmlfile = os.path.join(dir, 'test.xml')
    l = KlustersLoader(filename=xmlfile)

    clusters = l.get_clusters()
    cluster_colors = l.get_cluster_colors()
    cluster_groups = l.get_cluster_groups()
    group_colors = l.get_group_colors()
    group_names = l.get_group_names()

    # Set clusters.
    indices = get_indices(clusters)
    l.set_cluster(indices[::2], 2)
    l.set_cluster(indices[1::2], 3)

    # Set cluster info.
    cluster_indices = l.get_clusters_unique()
    l.set_cluster_colors(cluster_indices[::2], 10)
    l.set_cluster_colors(cluster_indices[1::2], 20)
    l.set_cluster_groups(cluster_indices[::2], 1)
    l.set_cluster_groups(cluster_indices[1::2], 0)

    # Save.
    l.remove_empty_clusters()
    l.save()

    clusters = read_clusters(l.filename_aclu)
    cluster_info = read_cluster_info(l.filename_acluinfo)

    assert np.all(clusters[::2] == 2)
    assert np.all(clusters[1::2] == 3)

    assert np.array_equal(cluster_info.index, cluster_indices)
    assert np.all(cluster_info.values[::2, 0] == 10)
    assert np.all(cluster_info.values[1::2, 0] == 20)
    assert np.all(cluster_info.values[::2, 1] == 1)
    assert np.all(cluster_info.values[1::2, 1] == 0)

    l.close()
Ejemplo n.º 4
0
def test_cluster_info():
    dir = TEST_FOLDER
    clufile = os.path.join(dir, 'test.aclu.1')
    cluinfofile = os.path.join(dir, 'test.acluinfo.1')

    clusters = read_clusters(clufile)

    indices = np.unique(clusters)
    colors = np.random.randint(low=0, high=10, size=len(indices))
    groups = np.random.randint(low=0, high=2, size=len(indices))
    cluster_info = pd.DataFrame({
        'color': pd.Series(colors, index=indices),
        'group': pd.Series(groups, index=indices)
    })

    save_cluster_info(cluinfofile, cluster_info)
    cluster_info2 = read_cluster_info(cluinfofile)

    assert np.array_equal(cluster_info.values, cluster_info2.values)