<commit_before>import nifty
import vigra
import numpy

chunked_rag = nifty.graph.rag.chunkedLabelsGridRagSliced
normal_rag  = nifty.graph.rag.explicitLabelsGridRag3D

def test_rag_build(labels_file, labels_key):
    rag_c = chunked_rag(labels_file, labels_key)
    edges_c = rag_c.numberOfEdges
    nodes_c = rag_c.numberOfNodes
    del rag_c

    labels = vigra.readHDF5(labels_file, labels_key)

    rag_n = normal_rag(labels)
    edges_n = rag_n.numberOfEdges
    nodes_n = rag_n.numberOfNodes

    rag_v = vigra.graphs.regionAdjacencyGraph(vigra.graphs.gridGraph(labels.shape), labels)
    nodes_v = rag_v.nodeNum
    edges_v = rag_v.edgeNum

    assert nodes_c == nodes_n, str(nodes_c) + " , " + str(nodes_n)
    assert nodes_v == nodes_n, str(nodes_v) + " , " + str(nodes_n)

    print "Vigra edges:", edges_v
    assert edges_c == edges_n, str(edges_c) + " , " + str(edges_n)
    assert edges_v == edges_n, str(edges_v) + " , " + str(edges_n)


    print "Check"





if __name__ == '__main__':
    labels_file = "/home/consti/Work/projects/phd_prototyping/vigra_chunked/test_labels_chunked.h5"
    labels_key  = "data"

    test_rag_build(labels_file, labels_key)<commit_msg>start travis<commit_after>import nifty
import vigra
import numpy

chunked_rag = nifty.graph.rag.chunkedLabelsGridRagSliced
normal_rag  = nifty.graph.rag.explicitLabelsGridRag3D

def test_rag_build(labels_file, labels_key):

    with vigra.Timer("Chunked Nifty Rag"):
        rag_c = chunked_rag(labels_file, labels_key, numberOfThreads = 1)
    edges_c = rag_c.numberOfEdges
    print edges_c
    nodes_c = rag_c.numberOfNodes
    del rag_c


    labels = vigra.readHDF5(labels_file, labels_key).astype('uint32')

    with vigra.Timer("Nifty Rag"):
        rag_n = normal_rag(labels, numberOfThreads = -1 )
    edges_n = rag_n.numberOfEdges
    nodes_n = rag_n.numberOfNodes

    with vigra.Timer("Vigra Rag"):
        rag_v = vigra.graphs.regionAdjacencyGraph(vigra.graphs.gridGraph(labels.shape), labels)
    nodes_v = rag_v.nodeNum
    edges_v = rag_v.edgeNum

    assert nodes_c == nodes_n, str(nodes_c) + " , " + str(nodes_n)
    #assert nodes_v == nodes_n, str(nodes_v) + " , " + str(nodes_n)

    assert edges_c == edges_n, str(edges_c) + " , " + str(edges_n)
    assert edges_v == edges_n, str(edges_v) + " , " + str(edges_n)

    print "Checks out"




if __name__ == '__main__':

    files = ["/home/consti/Work/projects/phd_prototyping/vigra_chunked/test_labels_chunked.h5",
            "/home/consti/Work/data_neuro/test_block/sliced_data/test-seg.h5",
            "/home/consti/Work/data_neuro/large_tests/sampleA/sampleA_ws.h5"]

    for f in files:

        print f
        test_rag_build(f, "data")
{'fraction_non_alphanumeric': 0.11197626992955136, 'fraction_numerical': 0.004449388209121246, 'mean_word_length': 3.700348432055749, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2868634', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1034, 'n_words': 165}