Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
        '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")
Ejemplo n.º 8
0
def pyneval(DEBUG=True):
    # init path parameter
    abs_dir = os.path.abspath("")
    sys.path.append(abs_dir)
    sys.path.append(os.path.join(abs_dir, "src"))
    sys.path.append(os.path.join(abs_dir, "test"))

    # read parameter
    args = read_parameters()

    # set config
    # gold/test files
    if args.test is None:
        test_swc_files = []
    else:
        test_swc_files = [os.path.join(abs_dir, path) for path in args.test]
    gold_swc_file = os.path.join(abs_dir, args.gold)

    # reverse
    reverse = args.reverse
    if reverse is None:
        reverse = False

    # metric
    metric = args.metric
    if metric not in metric_list:
        raise Exception("[Error: ] Unknown metric method {}".format(
            metric
        ))

    # output path
    output_dest = args.output
    if output_dest is not None:
        output_dest = os.path.join(abs_dir, output_dest)

    # config
    config = args.config
    if config is None:
        if platform.system() == "Windows":
            if metric == "diadem_metric" or metric == "DM":
                config = os.path.join(abs_dir, "config\\diadem_metric.json")
            if metric in ["overall_length", "matched_length", "OL", "ML"]:
                config = os.path.join(abs_dir, "config\\length_metric.json")
            if metric in ["overlap_clean", "OD"]:
                config = os.path.join(abs_dir, "config\\overlap_clean.json")
        elif platform.system() == "Linux":
            if metric == "diadem_metric" or metric == "DM":
                config = os.path.join(abs_dir, "config/diadem_metric.json")
            if metric in ["overall_length", "matched_length", "OL", "ML"]:
                config = os.path.join(abs_dir, "config/length_metric.json")
            if metric in ["overlap_clean", "OD"]:
                config = os.path.join(abs_dir, "config/overlap_clean.json")
    if DEBUG:
        print("Config = {}".format(config))

    # read test trees, gold trees and configs
    test_swc_trees = []
    for test_swc_file in test_swc_files:
        test_swc_trees += read_swc_trees(test_swc_file)
    gold_swc_trees = read_swc_trees(gold_swc_file)
    config = read_json(config)

    # info: how many trees read
    print("There are {} test image(s) and {} gold image(s)".format(len(test_swc_trees), len(gold_swc_trees)))
    if len(gold_swc_trees) == 0:
        raise Exception("[Error:  ] No gold image detected")
    if len(gold_swc_trees) > 1:
        print("[Warning:  ] More than one gold image detected, only the first one will be used")

    # entries to different metrics
    gold_swc_treeroot = gold_swc_trees[0]
    for test_swc_treeroot in test_swc_trees:
        if metric == "diadem_metric" or metric == "DM":
            diadem_metric(swc_test_tree=test_swc_treeroot,
                          swc_gold_tree=gold_swc_treeroot,
                          config=read_json("D:\gitProject\mine\PyNeval\config\diadem_metric.json"))
            if reverse:
                diadem_metric(gold_swc_treeroot, test_swc_treeroot)
        if metric == "overall_length" or metric == "OL":
            config["method"] = 1
            length_metric(gold_swc_treeroot, test_swc_treeroot,
                          abs_dir, config)
            if reverse:
                length_metric(test_swc_treeroot, gold_swc_treeroot,
                              abs_dir, config)
        if metric == "matched_length" or metric == "ML":
            config["method"] = 2
            length_metric(gold_swc_treeroot, test_swc_treeroot,
                          abs_dir, config)
            if reverse:
                config["detail"] = config["detail"][:-4] + "_reverse.swc"
                length_metric(test_swc_treeroot, gold_swc_treeroot,
                              abs_dir, config)
    if metric == "overlap_clean" or metric == "OC":
        # debug
        print("entry")
        print(config["radius_threshold"])
        print(config["length_threshold"])
        print(output_dest)
        overlap_clean(gold_swc_treeroot, output_dest, config)
Ejemplo n.º 9
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"))
Ejemplo n.º 10
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))