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)
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 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)
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)
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)