コード例 #1
0
def test_wizard_move():

    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)

    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    target = clusters_unique[np.argmax(quality)]

    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()

    cluster0 = w.current_candidate()
    cluster1 = w.next_candidate()
    cluster2 = w.next_candidate()

    # Simulate a move.
    cluster_groups.ix[cluster2] = 1

    # Update the wizard.
    w.set_data(cluster_groups=cluster_groups)
    w.update_candidates(target)

    assert w.current_target() == target
    assert w.current_candidate() not in (cluster0, cluster1, cluster2)

    for _ in xrange(nclusters):
        c = w.next_candidate()
        assert c != cluster2
コード例 #2
0
ファイル: test_wizard.py プロジェクト: Jackieee/klustaviewa
def test_wizard_move():
    
    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)
    
    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    target = clusters_unique[np.argmax(quality)]
    
    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()
    
    cluster0 = w.current_candidate()
    cluster1 = w.next_candidate()
    cluster2 = w.next_candidate()
    
    # Simulate a move.
    cluster_groups.ix[cluster2] = 1
    
    # Update the wizard.
    w.set_data(cluster_groups=cluster_groups)
    w.update_candidates(target)
    
    assert w.current_target() == target
    assert w.current_candidate() not in (cluster0, cluster1, cluster2)
    
    for _ in xrange(nclusters):
        c = w.next_candidate()
        assert c != cluster2
コード例 #3
0
ファイル: test_hdf5tools.py プロジェクト: beniamino38/kwiklib
def setup():
    # Special setup fixture to create a data set with 2 shanks.
    # No need for teardown as the 'mockdata' folder will be cleared at the
    # end of the tests anyway.
    
    
    # Create mock directory if needed.
    dir = TEST_FOLDER
    if not os.path.exists(dir):
        os.mkdir(dir)
        
    # Create mock data.
    waveforms = create_waveforms(nspikes, nsamples, nchannels)
    features = create_features(nspikes, nchannels, fetdim, duration, freq)
    clusters = create_clusters(nspikes, nclusters)
    cluster_colors = create_cluster_colors(nclusters)
    masks = create_masks(nspikes, nchannels, fetdim)
    xml = create_xml(nchannels, nsamples, fetdim)
    probe = create_probe(nchannels)
    
    # Create mock files.
    save_binary(os.path.join(dir, 'test.spk.2'), waveforms)
    save_text(os.path.join(dir, 'test.fet.2'), features,
        header=nchannels * fetdim + 1)
    save_text(os.path.join(dir, 'test.aclu.2'), clusters, header=nclusters)
    save_text(os.path.join(dir, 'test.clu.2'), clusters, header=nclusters)
    save_text(os.path.join(dir, 'test.fmask.2'), masks, header=nclusters,
        fmt='%.6f')
    save_text(os.path.join(dir, 'test.xml'), xml)
    save_text(os.path.join(dir, 'test.probe'), probe)
コード例 #4
0
def test_wizard_merge():

    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)

    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    target = clusters_unique[np.argmax(quality)]

    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()

    cluster = w.current_candidate()

    # Simulate a merge: target and cluster ==> cluster_new.
    cluster_new = clusters_unique.max() + 1
    clusters[clusters == target] = cluster_new
    clusters[clusters == cluster] = cluster_new
    log.debug("Merged {0:d} and {1:d} to {2:d}".format(target, cluster,
                                                       cluster_new))
    similarity_matrix = create_similarity_matrix(nclusters - 1)
    indices = [
        x for x in xrange(cluster_offset, cluster_offset + nclusters + 1)
        if x != cluster and x != target
    ]
    cluster_groups = pd.Series(np.array(np.ones(nclusters - 1) * 3,
                                        dtype=np.int32),
                               index=np.array(indices))

    # Update the wizard.
    quality = np.diag(similarity_matrix)
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates(cluster_new)

    assert w.current_target() == cluster_new

    c = w.current_candidate()
    assert c is not None
    assert w.previous_candidate() == w.current_candidate()
    assert w.next_candidate() == c

    for _ in xrange(nclusters):
        c = w.next_candidate()
        assert c not in (target, cluster)
コード例 #5
0
ファイル: test_wizard.py プロジェクト: Jackieee/klustaviewa
def test_wizard_merge():
    
    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)
    
    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    target = clusters_unique[np.argmax(quality)]
    
    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()
    
    cluster = w.current_candidate()
    
    # Simulate a merge: target and cluster ==> cluster_new.
    cluster_new = clusters_unique.max() + 1
    clusters[clusters == target] = cluster_new
    clusters[clusters == cluster] = cluster_new
    log.debug("Merged {0:d} and {1:d} to {2:d}".format(
        target, cluster, cluster_new))
    similarity_matrix = create_similarity_matrix(nclusters - 1)
    indices = [x for x in xrange(cluster_offset, cluster_offset + nclusters + 1)
                    if x != cluster and x != target]
    cluster_groups = pd.Series(np.array(np.ones(nclusters - 1) * 3, dtype=np.int32),
        index=np.array(indices))
    
    # Update the wizard.
    quality = np.diag(similarity_matrix)
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates(cluster_new)
    
    assert w.current_target() == cluster_new
    
    c = w.current_candidate()
    assert c is not None
    assert w.previous_candidate() == w.current_candidate()
    assert w.next_candidate() == c
    
    for _ in xrange(nclusters):
        c = w.next_candidate()
        assert c not in (target, cluster)
コード例 #6
0
def test_wizard():

    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)

    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    best_cluster = clusters_unique[np.argmax(quality)]

    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()

    # Check the first target cluster.
    assert w.current_target() == best_cluster

    # Test impossible previous.
    assert w.previous_candidate() == w.current_candidate()

    # Check next/previous.
    c0 = w.next_candidate()
    c1 = w.next_candidate()
    assert w.previous_candidate() == c0
    assert w.next_candidate() == c1

    # Check skip target.
    t0 = w.current_target()
    w.skip_target()
    w.update_candidates()
    t1 = w.current_target()
    assert t0 != t1
コード例 #7
0
ファイル: test_wizard.py プロジェクト: Jackieee/klustaviewa
def test_wizard():
    
    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)
    
    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    best_cluster = clusters_unique[np.argmax(quality)]
    
    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()
    
    # Check the first target cluster.
    assert w.current_target() == best_cluster
    
    # Test impossible previous.
    assert w.previous_candidate() == w.current_candidate()
    
    # Check next/previous.
    c0 = w.next_candidate()
    c1 = w.next_candidate()
    assert w.previous_candidate() == c0
    assert w.next_candidate() == c1
    
    # Check skip target.
    t0 = w.current_target()
    w.skip_target()
    w.update_candidates()
    t1 = w.current_target()
    assert t0 != t1