Beispiel #1
0
    def test_len_4(self):
        goldtree = SwcTree()
        testTree = SwcTree()

        goldtree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\gold\\conner.swc")
        testTree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\\test\\conner.swc")

        recall1, precision1, vertical_tree = length_metric(
            gold_swc_tree=goldtree,
            test_swc_tree=testTree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        recall2, precision2, vertical_tree = length_metric(
            gold_swc_tree=testTree,
            test_swc_tree=goldtree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))
        self.assertEqual(recall1, 1.0)
        self.assertEqual(recall2, 0.0)
        self.assertEqual(precision1, 0.9385873563259137)
        self.assertEqual(precision2, 0.0)
Beispiel #2
0
    def test_len_3(self):
        goldtree = SwcTree()
        testTree = SwcTree()

        goldtree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\gold\\34_23_10_gold.swc"
        )
        testTree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\\test\\34_23_10_test.swc"
        )

        recall1, precision1, vertical_tree = length_metric(
            gold_swc_tree=goldtree,
            test_swc_tree=testTree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        recall2, precision2, vertical_tree = length_metric(
            gold_swc_tree=testTree,
            test_swc_tree=goldtree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        self.assertEqual(recall1, 0.6092362772577844)
        self.assertEqual(recall2, 0.5585330586568052)
        self.assertEqual(precision1, 0.5318779478680355)
        self.assertEqual(precision2, 0.6397682076225172)
Beispiel #3
0
    def test_len_1(self):
        goldtree = SwcTree()
        testTree = SwcTree()

        goldtree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\gold\\2_18_gold.swc"
        )
        testTree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\\test\\2_18_test.swc"
        )

        recall1, precision1, vertical_tree = length_metric(
            gold_swc_tree=goldtree,
            test_swc_tree=testTree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        recall2, precision2, vertical_tree = length_metric(
            gold_swc_tree=testTree,
            test_swc_tree=goldtree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        self.assertEqual(recall1, 0.7030284661586385)
        self.assertEqual(recall2, 0.8685749970409651)
        self.assertEqual(precision1, 0.7174338664651955)
        self.assertEqual(precision2, 0.8511348243456205)
def test2():
    start = time.time()
    swc_tree = SwcTree()
    swc_tree.load("D:\gitProject\mine\PyNeval\\test\data_example\gold\ExampleGoldStandard.swc")
    bin_tree = convert_to_binarytree(swc_tree)
    test_print_bin_tree(bin_tree)
    print(time.time() - start)
Beispiel #5
0
    def test_len_2(self):
        goldtree = SwcTree()
        testTree = SwcTree()

        goldtree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\gold\\30_18_10_gold.swc"
        )
        testTree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\\test\\30_18_10_test.swc"
        )

        recall1, precision1, vertical_tree = length_metric(
            gold_swc_tree=goldtree,
            test_swc_tree=testTree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        recall2, precision2, vertical_tree = length_metric(
            gold_swc_tree=testTree,
            test_swc_tree=goldtree,
            abs_dir="D:\gitProject\mine\PyNeval",
            config=read_json(
                "D:\gitProject\mine\PyNeval\config\length_metric.json"))

        self.assertEqual(recall1, 0.6818040837428125)
        self.assertEqual(recall2, 0.6971179817818407)
        self.assertEqual(precision1, 0.6327624077188985)
        self.assertEqual(precision2, 0.7511474781551107)
Beispiel #6
0
def read_swc_trees(swc_file_paths):
    swc_tree_list = []
    if os.path.isfile(swc_file_paths):
        if not (swc_file_paths[-4:] == ".swc" or swc_file_paths[-4:] == ".SWC"):
            print(swc_file_paths + "is not a tif file")
            return None
        swc_tree = SwcTree()
        swc_tree.load(swc_file_paths)
        swc_tree_list.append(swc_tree)
    elif os.path.isdir(swc_file_paths):
        for file in os.listdir(swc_file_paths):
            swc_tree_list += read_swc_trees(swc_file_paths=os.path.join(swc_file_paths, file))
    return swc_tree_list
Beispiel #7
0
    def test_5(self):
        testTree = SwcTree()
        goldTree = SwcTree()
        goldTree.load("D:\gitProject\mine\PyNeval\\test\data_example\gold\diadem\diadem7.swc")
        testTree.load("D:\gitProject\mine\PyNeval\\test\data_example\\test\diadem\diadem7.swc")

        get_default_threshold(goldTree)

        score = diadem_metric(swc_test_tree=testTree,
                              swc_gold_tree=goldTree,
                              config=read_json("D:\gitProject\mine\PyNeval\config\diadem_metric.json"))
        print(score)
        self.assertEqual(score, 0.5)
Beispiel #8
0
    def test_3(self):
        testTree = SwcTree()
        goldTree = SwcTree()
        goldTree.load("D:\gitProject\mine\PyNeval\\test\data_example\gold\ExampleGoldStandard.swc")
        testTree.load("D:\gitProject\mine\PyNeval\\test\data_example\\test\ExampleTest.swc")

        # goldtree.load("D:\gitProject\mine\PyNeval\\test\data_example\\gold\\ExampleGoldStandard.swc")
        # testTree.load("D:\gitProject\mine\PyNeval\\test\data_example\\test\\ExampleTest.swc")
        get_default_threshold(goldTree)

        score = diadem_metric(swc_test_tree=testTree,
                              swc_gold_tree=goldTree,
                              config=read_json("D:\gitProject\mine\PyNeval\config\diadem_metric.json"))
        print(score)
        self.assertEqual(score, 0.9564541213063764)
    def test_rtree(self):
        swctree = SwcTree()
        swctree.load(
            "D:\gitProject\mine\PyNeval\\test\data_example\\test\\30_18_10_test.swc"
        )
        rtree = get_edge_rtree(swctree)
        id_edge_dict = get_idedge_dict(swctree)
        point = SwcNode(center=[22.5822, 172.856, 300.413])
        (line_tuple, dis) = get_nearby_edges(rtree, point, id_edge_dict,
                                             point.radius())[0]

        print(
            point.distance(
                Line(coords=[[15.3249, 130.821, 327.012],
                             [19.8495, 132.384, 323.395]])))
        print("dis = {}, line:{}, {}".format(dis, line_tuple[0]._pos,
                                             line_tuple[1]._pos))
Beispiel #10
0
            if gold_node.distance(get_kdtree_data(node)) > dis_threshold:
                gold_node_knn.remove(node)
        if DEBUG:
            print("knn of gold = {}".format(gold_node_knn))
        for son in gold_node.children:
            son_node_knn = test_kdtree.search_knn(son._pos, knn)
            if DEBUG:
                print("son of gold = {}".format(son_node_knn))
            match = check_match(gold_node_knn, son_node_knn, edge_set,
                                id_center_dict)
            if match is not None:
                match_edge[tuple([gold_node, son])] = match
    if DEBUG:
        print(len(match_edge))
    return match_edge


# for diadem metric
# def find
if __name__ == "__main__":
    goldtree = SwcTree()
    goldtree.load(
        "D:\gitProject\mine\PyNeval\\test\data_example\gold\\ExampleGoldStandard.swc"
    )
    get_default_threshold(goldtree)

    testTree = SwcTree()
    testTree.load(
        "D:\gitProject\mine\PyNeval\\test\data_example\\test\\ExampleTest.swc")

    get_match_edges_p(goldtree, testTree, 3, True)
Beispiel #11
0
    result = {
        'gold_swc': swc_to_list(gold_tree),
        'test_swc': swc_to_list(test_tree),
        'weight_sum': g_weight_sum,
        'score_sum': g_score_sum,
        'final_score': g_final_score
    }

    return result


if __name__ == "__main__":
    testTree = SwcTree()
    goldTree = SwcTree()
    goldTree.load(
        "D:\gitProject\mine\PyNeval\\test\data_example\gold\diadem\diadem11.swc"
    )
    testTree.load(
        "D:\gitProject\mine\PyNeval\\test\data_example\\test\diadem\diadem11.swc"
    )

    # goldTree.load("D:\gitProject\mine\PyNeval\\test\data_example\\gold\\ExampleGoldStandard.swc")
    # testTree.load("D:\gitProject\mine\PyNeval\\test\data_example\\test\\ExampleTest.swc")
    get_default_threshold(goldTree)

    diadem_metric(swc_test_tree=testTree,
                  swc_gold_tree=goldTree,
                  config=read_json(
                      "D:\gitProject\mine\PyNeval\config\diadem_metric.json"),
                  DEBUG=True)
    swc_save(goldTree, "D:\gitProject\mine\PyNeval\output\gold_tree_out.swc")
Beispiel #12
0
def test_get_bintree():
    goldtree = SwcTree()
    goldtree.load("D:\gitProject\mine\PyNeval\\test\data_example\\test\\ExampleTest.swc")
    bintree = convert_to_binarytree(goldtree)
    return bintree
                                    test_swc_tree,
                                    dis_threshold,
                                    DEBUG=True)

    match_length = 0.0
    for line_tuple in match_edges:
        match_length += line_tuple[0].parent_distance()

    gold_total_length = round(gold_swc_tree.length(), 8)
    match_length = round(match_length, 8)

    if DEBUG:
        print("match_length b = {}, gold_total_length = {}".format(
            match_length, gold_total_length))
    return match_length / gold_total_length


if __name__ == "__main__":
    goldtree = SwcTree()
    goldtree.load(
        "D:\gitProject\mine\PyNeval\\test\data_example\gold\\30_18_10_gold.swc"
    )

    testTree = SwcTree()
    testTree.load(
        "D:\gitProject\mine\PyNeval\\test\data_example\\test\\30_18_10_test.swc"
    )
    start = time.time()
    print(length_metric_2_2(gold_swc_tree=goldtree, test_swc_tree=testTree))

    print(time.time() - start)
Beispiel #14
0
    # gold_tree.radius_limit(10)
    # test_tree.radius_limit(10)

    result = {
        'recall': recall,
        'precision': precision,
        'gold_swc': swc_to_list(gold_tree),
        'test_swc': swc_to_list(test_tree),
        'vertical_swc': vertical_tree
    }
    return result


if __name__ == "__main__":
    goldtree = SwcTree()
    testTree = SwcTree()

    goldtree.load("D:\gitProject\mine\PyNeval\\test\data_example\\test\multy_useage\push.swc")
    testTree.load("D:\gitProject\mine\PyNeval\\test\data_example\gold\multy_useage\push.swc")

    recall1, precision1, vertical_tree = length_metric(gold_swc_tree=goldtree,
                                                       test_swc_tree=testTree,
                                                       abs_dir="D:\gitProject\mine\PyNeval",
                                                       config=read_json(
                                                           "D:\gitProject\mine\PyNeval\config\length_metric.json"))

    # recall2, precision2, vertical_tree = length_metric(gold_swc_tree=testTree,
    #                                                    test_swc_tree=goldtree,
    #                                                    abs_dir="D:\gitProject\mine\PyNeval",
    #                                                    config=read_json(
    #                                                        "D:\gitProject\mine\PyNeval\config\length_metric.json"))
Beispiel #15
0
    get_self_match_edges_e_fast(swc_tree=new_swc_tree,
                                rad_threshold=dis_threshold,
                                len_threshold=length_threshold,
                                list_size=swc_tree.node_count(),
                                mode="not_self",
                                DEBUG=False)
    color_origin_tree(new_swc_tree, swc_tree)
    delete_overlap_node(new_swc_tree)
    swc_save(new_swc_tree, out_path)


if __name__ == '__main__':
    file_path = "D:\gitProject\mine\PyNeval\\test\data_example\gold\swc_data_2"
    out_path = "D:\gitProject\mine\PyNeval\output\swc_data_2"

    files = os.listdir(file_path)
    for file in files:
        tree = SwcTree()
        tree.clear()
        tree.load(os.path.join(file_path, file))

        config = read_json(
            "D:\gitProject\mine\PyNeval\config\overlap_detect.json")
        overlap_clean(tree, os.path.join(out_path, "clean_" + file), config)

    # node = SwcNode(center=[101, 100.1, 100], radius=0.6)
    # son = SwcNode(center=[100, 100, 100], radius=0.5)
    # pa = SwcNode(center=[102, 100, 100], radius=0.5)
    # print(itp_ok(node=node, son=son, pa=pa))