From 19b7f6cf41d80f9bfd591bd7ce33a1c2af6ee75d Mon Sep 17 00:00:00 2001 From: zhanghan Date: Fri, 11 Jun 2021 12:05:19 +0800 Subject: [PATCH] change z scale in to scale including z,y scale. Show schema error --- config/branch_metric.json | 2 +- config/diadem_metric.json | 3 +-- config/length_metric.json | 2 +- config/link_metric.json | 2 +- config/schemas/branch_metric_schema.json | 10 +++++++--- config/schemas/diadem_metric_schema.json | 7 +++++-- config/schemas/length_metric_schema.json | 12 ++++++++---- config/schemas/link_metric_schema.json | 8 ++++++-- config/schemas/overlap_clean_schema.json | 8 -------- config/schemas/ssd_metric_schema.json | 12 ++++++++---- config/schemas/up_sample_schema.json | 3 --- config/schemas/volume_metric_schema.json | 4 ++-- config/ssd_metric.json | 6 +++--- pyneval/cli/pyneval.py | 1 - pyneval/metric/branch_leaf_metric.py | 6 +++--- pyneval/metric/diadem_metric.py | 6 +++--- pyneval/metric/length_metric.py | 6 +++--- pyneval/metric/link_metric.py | 6 +++--- pyneval/metric/ssd_metric.py | 6 +++--- pyneval/metric/utils/diadam_match_utils.py | 3 +-- pyneval/model/swc_node.py | 6 ++++-- setup.py | 6 ++++-- 22 files changed, 67 insertions(+), 58 deletions(-) delete mode 100644 config/schemas/overlap_clean_schema.json delete mode 100644 config/schemas/up_sample_schema.json diff --git a/config/branch_metric.json b/config/branch_metric.json index a05990d..2b107b8 100644 --- a/config/branch_metric.json +++ b/config/branch_metric.json @@ -1,7 +1,7 @@ { "threshold_dis": 2, "threshold_mode": 1, - "z_scale": 1, + "scale": [1, 1, 1], "true_positive": 3, "missed": 4, "excess": 5 diff --git a/config/diadem_metric.json b/config/diadem_metric.json index 341b979..6b779d9 100644 --- a/config/diadem_metric.json +++ b/config/diadem_metric.json @@ -7,8 +7,7 @@ "list_distant_matches": true, "list_continuations": true, "find_proper_root": true, - "z_scale": 1, - "TRAJECTORY_NONE": -1.0, + "scale": [1, 1, 1], "xy_threshold": 1.2, "z_threshold": 0.0, "default_xy_path_error_threshold": 0.05, diff --git a/config/length_metric.json b/config/length_metric.json index 1d5aa55..f4340f5 100644 --- a/config/length_metric.json +++ b/config/length_metric.json @@ -2,6 +2,6 @@ "rad_mode": 1, "rad_threshold": 1, "len_threshold": 0.2, - "z_scale": 1, + "scale": [1,1,1], "debug": false } diff --git a/config/link_metric.json b/config/link_metric.json index 332a5c2..62b7910 100644 --- a/config/link_metric.json +++ b/config/link_metric.json @@ -1,3 +1,3 @@ { - "z_scale": 1 + "scale": [1, 1, 1] } \ No newline at end of file diff --git a/config/schemas/branch_metric_schema.json b/config/schemas/branch_metric_schema.json index 4c9d264..e110e24 100644 --- a/config/schemas/branch_metric_schema.json +++ b/config/schemas/branch_metric_schema.json @@ -4,15 +4,19 @@ "required": [ "threshold_dis", "threshold_mode", - "z_scale", + "scale", "true_positive", "missed", "excess" ], "properties": { - "threshold_dis": {"type": "number", "exclusiveMinimum": 0}, + "threshold_dis": {"type": "number", "minimum": 0}, "threshold_mode": {"type": "number", "enum": [1, 2]}, - "z_scale": {"type": "number","minimum": 0}, + "scale": {"type":"array", + "additionalItems": {"type": "number", "minimum": 0}, + "minItems": 3, + "maxItems": 3 + }, "true_positive": {"type": "integer", "exclusiveMinimum": 0}, "missed": {"type": "integer", "exclusiveMinimum": 0}, "excess": {"type": "integer", "exclusiveMinimum": 0} diff --git a/config/schemas/diadem_metric_schema.json b/config/schemas/diadem_metric_schema.json index 22e57c1..72e0ffb 100644 --- a/config/schemas/diadem_metric_schema.json +++ b/config/schemas/diadem_metric_schema.json @@ -13,8 +13,11 @@ "list_distant_matches": {"type": "boolean", "default": "false"}, "list_continuations": {"type": "boolean", "default": "false"}, "find_proper_root": {"type": "boolean", "default": "true"}, - "z_scale": {"type": "number", "minimum": 0}, - "TRAJECTORY_NONE": {"type": "number"}, + "scale": {"type":"array", + "additionalItems": {"type": "number", "minimum": 0}, + "minItems": 3, + "maxItems": 3 + }, "xy_threshold": {"type": "number", "minimum": 0}, "z_threshold": {"type": "number", "minimum": 0}, "default_xy_path_error_threshold": {"type": "number", "minimum": 0}, diff --git a/config/schemas/length_metric_schema.json b/config/schemas/length_metric_schema.json index b28e7e6..0dd7f38 100644 --- a/config/schemas/length_metric_schema.json +++ b/config/schemas/length_metric_schema.json @@ -5,14 +5,18 @@ "rad_mode", "rad_threshold", "len_threshold", - "z_scale", + "scale", "debug" ], "properties": { "rad_mode": {"type": "number", "enum": [1,2]}, - "rad_threshold": {"type": "number", "exclusiveMinimum": 0}, - "len_threshold": {"type": "number", "exclusiveMinimum": 0}, - "z_scale": {"type": "number", "minimum": 0}, + "rad_threshold": {"type": "number", "minimum": 0}, + "len_threshold": {"type": "number", "minimum": 0}, + "scale": {"type":"array", + "additionalItems": {"type": "number", "minimum": 0}, + "minItems": 3, + "maxItems": 3 + }, "debug": {"type": "boolean"} } } \ No newline at end of file diff --git a/config/schemas/link_metric_schema.json b/config/schemas/link_metric_schema.json index 581ecfe..36075dd 100644 --- a/config/schemas/link_metric_schema.json +++ b/config/schemas/link_metric_schema.json @@ -2,9 +2,13 @@ "title": "link metric schema", "type": "object", "required": [ - "z_scale" + "scale" ], "properties": { - "z_scale": {"type": "number", "minimum": 0} + "scale": {"type":"array", + "additionalItems": {"type": "number", "minimum": 0}, + "minItems": 3, + "maxItems": 3 + } } } \ No newline at end of file diff --git a/config/schemas/overlap_clean_schema.json b/config/schemas/overlap_clean_schema.json deleted file mode 100644 index 2747ee7..0000000 --- a/config/schemas/overlap_clean_schema.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "radius_threshold": -1, - "length_threshold": 0.2, - "ang_threshold": 170, - "rad_mul": 1.5, - "center_dis": null, - "stage": 0 -} \ No newline at end of file diff --git a/config/schemas/ssd_metric_schema.json b/config/schemas/ssd_metric_schema.json index 55be463..a522609 100644 --- a/config/schemas/ssd_metric_schema.json +++ b/config/schemas/ssd_metric_schema.json @@ -5,14 +5,18 @@ "threshold_mode", "ssd_threshold", "up_sample_threshold", - "z_scale", + "scale", "debug" ], "properties": { "threshold_mode": {"type": "integer", "enum": [1,2]}, - "ssd_threshold": {"type": "number", "exclusiveMinimum": 0}, - "up_sample_threshold": {"type": "number", "exclusiveMinimum": 0}, - "z_scale": {"type":"number", "minimum": 0}, + "ssd_threshold": {"type": "number", "minimum": 0}, + "up_sample_threshold": {"type": "number", "minimum": 0}, + "scale": {"type":"array", + "additionalItems": {"type": "number", "minimum": 0}, + "minItems": 3, + "maxItems": 3 + }, "debug": {"type": "boolean"} } } \ No newline at end of file diff --git a/config/schemas/up_sample_schema.json b/config/schemas/up_sample_schema.json deleted file mode 100644 index 6f14ea0..0000000 --- a/config/schemas/up_sample_schema.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "thres_length": 1.0 -} \ No newline at end of file diff --git a/config/schemas/volume_metric_schema.json b/config/schemas/volume_metric_schema.json index 3be2747..72041f6 100644 --- a/config/schemas/volume_metric_schema.json +++ b/config/schemas/volume_metric_schema.json @@ -7,8 +7,8 @@ "debug" ], "properties": { - "length_threshold": {"type": "number", "exclusiveMinimum": 0}, - "intensity_threshold": {"type": "number", "exclusiveMinimum": 0}, + "length_threshold": {"type": "number", "minimum": 0}, + "intensity_threshold": {"type": "number", "minimum": 0}, "debug": {"type": "boolean"} } } \ No newline at end of file diff --git a/config/ssd_metric.json b/config/ssd_metric.json index 7a23452..aa85736 100644 --- a/config/ssd_metric.json +++ b/config/ssd_metric.json @@ -1,7 +1,7 @@ { "threshold_mode": 1, - "ssd_threshold": 1, - "up_sample_threshold": 1.0, - "z_scale": 1, + "ssd_threshold": 2, + "up_sample_threshold": 1, + "scale": [1,1,1], "debug": false } \ No newline at end of file diff --git a/pyneval/cli/pyneval.py b/pyneval/cli/pyneval.py index 9c6756d..621a91b 100644 --- a/pyneval/cli/pyneval.py +++ b/pyneval/cli/pyneval.py @@ -240,7 +240,6 @@ def excute_metric(metric, gold_swc_tree, test_swc_tree, config, detail_dir, outp out_path=os.path.join(detail_dir, file_name + "precision.swc"), extra=anno_utils.get_detail_type(metric)) - if output_dir: read_json.save_json(data=result, json_file_path=os.path.join(output_dir, file_name + ".json")) diff --git a/pyneval/metric/branch_leaf_metric.py b/pyneval/metric/branch_leaf_metric.py index 50010dc..986142a 100644 --- a/pyneval/metric/branch_leaf_metric.py +++ b/pyneval/metric/branch_leaf_metric.py @@ -148,10 +148,10 @@ def branch_leaf_metric(gold_swc_tree, test_swc_tree, config): # read configs threshold_dis = config["threshold_dis"] threshold_mode = config["threshold_mode"] - z_scale = config["z_scale"] + scale = config["scale"] - gold_swc_tree.z_rescale(z_scale) - test_swc_tree.z_rescale(z_scale) + gold_swc_tree.rescale(scale) + test_swc_tree.rescale(scale) # in threshold mode 2, threshold is a multiple of the average length of edges if threshold_mode == 2: # length of the entire gold swc forest diff --git a/pyneval/metric/diadem_metric.py b/pyneval/metric/diadem_metric.py index cf6ed1e..7912815 100644 --- a/pyneval/metric/diadem_metric.py +++ b/pyneval/metric/diadem_metric.py @@ -940,9 +940,9 @@ def diadem_metric(gold_swc_tree, test_swc_tree, config): diadem_init() config_init(config) diadam_match_utils.diadem_utils_init(config) - z_scale = config["z_scale"] - gold_swc_tree.z_rescale(z_scale) - test_swc_tree.z_rescale(z_scale) + scale = config["scale"] + gold_swc_tree.rescale(scale) + test_swc_tree.rescale(scale) test_kdtree, test_pos_node_dict = point_match_utils.create_kdtree(test_swc_tree.get_node_list()) t_matches = {} diff --git a/pyneval/metric/length_metric.py b/pyneval/metric/length_metric.py index 567232a..d1d4c92 100644 --- a/pyneval/metric/length_metric.py +++ b/pyneval/metric/length_metric.py @@ -88,11 +88,11 @@ def length_metric(gold_swc_tree, test_swc_tree, config): rad_mode = config["rad_mode"] rad_threshold = config["rad_threshold"] len_threshold = config["len_threshold"] - z_scale = config["z_scale"] + scale = config["scale"] debug = config["debug"] - gold_swc_tree.z_rescale(z_scale) - test_swc_tree.z_rescale(z_scale) + gold_swc_tree.rescale(scale) + test_swc_tree.rescale(scale) gold_swc_tree.set_node_type_by_topo(root_id=1) test_swc_tree.set_node_type_by_topo(root_id=5) diff --git a/pyneval/metric/link_metric.py b/pyneval/metric/link_metric.py index 94785da..c3df6e1 100644 --- a/pyneval/metric/link_metric.py +++ b/pyneval/metric/link_metric.py @@ -39,9 +39,9 @@ def get_extra_pos_nodes(big_set, subset): def link_metric(gold_swc_tree, test_swc_tree, config): - z_scale = config['z_scale'] - gold_swc_tree.z_rescale(z_scale) - test_swc_tree.z_rescale(z_scale) + scale = config['scale'] + gold_swc_tree.rescale(scale) + test_swc_tree.rescale(scale) gold_list = gold_swc_tree.get_node_list() test_list = test_swc_tree.get_node_list() diff --git a/pyneval/metric/ssd_metric.py b/pyneval/metric/ssd_metric.py index f216b63..28f84d8 100644 --- a/pyneval/metric/ssd_metric.py +++ b/pyneval/metric/ssd_metric.py @@ -103,10 +103,10 @@ def ssd_metric(gold_swc_tree: swc_node.SwcTree, test_swc_tree: swc_node.SwcTree, threshold_mode = config["threshold_mode"] ssd_threshold = config["ssd_threshold"] up_sample_threshold = config["up_sample_threshold"] - z_scale = config["z_scale"] + scale = config["scale"] - gold_swc_tree.z_rescale(z_scale) - test_swc_tree.z_rescale(z_scale) + gold_swc_tree.rescale(scale) + test_swc_tree.rescale(scale) u_gold_swc_tree = re_sample.up_sample_swc_tree(swc_tree=gold_swc_tree, length_threshold=up_sample_threshold) u_test_swc_tree = re_sample.up_sample_swc_tree(swc_tree=test_swc_tree, diff --git a/pyneval/metric/utils/diadam_match_utils.py b/pyneval/metric/utils/diadam_match_utils.py index 6454ffd..03cfd88 100644 --- a/pyneval/metric/utils/diadam_match_utils.py +++ b/pyneval/metric/utils/diadam_match_utils.py @@ -8,7 +8,7 @@ _2D = "2d" -global TRAJECTORY_NONE +TRAJECTORY_NONE = -1.0 global g_xy_threshold global g_z_threshold global g_default_xy_path_error_threshold @@ -24,7 +24,6 @@ def diadem_utils_init(config): global g_default_z_path_error_threshold global g_local_path_error_threshold - TRAJECTORY_NONE = config["TRAJECTORY_NONE"] g_xy_threshold = config["xy_threshold"] g_z_threshold = config["z_threshold"] g_default_xy_path_error_threshold = config["default_xy_path_error_threshold"] diff --git a/pyneval/model/swc_node.py b/pyneval/model/swc_node.py index 221d71f..8535817 100644 --- a/pyneval/model/swc_node.py +++ b/pyneval/model/swc_node.py @@ -469,9 +469,11 @@ def scale(self, sx, sy, sz, adjusting_radius=True): for tn in niter: tn.scale(sx, sy, sz, adjusting_radius) - def z_rescale(self, z_scale): + def rescale(self, scale): for node in self.get_node_list(): - node.set_z(node.get_z() * z_scale) + node.set_z(node.get_z() * scale[2]) + node.set_y(node.get_y() * scale[1]) + node.set_x(node.get_x() * scale[0]) def length(self, force_update=False): if self._total_length is not None and force_update == False: diff --git a/setup.py b/setup.py index a99ccfb..4330914 100644 --- a/setup.py +++ b/setup.py @@ -9,10 +9,12 @@ url='https://github.com/bennieHan/PyNeval.git', packages=['pyneval', 'pyneval.cli', 'test', 'test.test_model', 'test.test_model.diadem_metric', 'test.test_model.length_metric', - 'pyneval.io', 'pyneval.metric', 'pyneval.metric.utils', 'pyneval.metric.utils.klib', 'pyneval.model', 'pyneval.tools', 'pyneval.tools.optimize'], + 'pyneval.io', 'pyneval.metric', 'pyneval.metric.utils', 'pyneval.metric.utils.klib', 'pyneval.model', + 'pyneval.tools', 'pyneval.tools.optimize'], py_modules=['pyneval', 'pyneval.cli', 'test', 'test.test_model', 'test.test_model.diadem_metric', 'test.test_model.length_metric', - 'pyneval.io', 'pyneval.metric', 'pyneval.metric.utils', 'pyneval.metric.utils.klib', 'pyneval.model', 'pyneval.tools', 'pyneval.tools.optimize'], + 'pyneval.io', 'pyneval.metric', 'pyneval.metric.utils', 'pyneval.metric.utils.klib', 'pyneval.model', + 'pyneval.tools', 'pyneval.tools.optimize'], data_files=[('config', glob.glob('config/*.json')), ("config/schemas", glob.glob('config/schemas/*.json'))], install_requires=[