From 3b77acbada0ebef08cee3203f504dc96d741d238 Mon Sep 17 00:00:00 2001 From: Robin Kim Date: Thu, 15 Aug 2024 15:09:00 -0500 Subject: [PATCH 1/3] Add no merge test --- src/spikeinterface/curation/curation_format.py | 3 ++- .../tests/sv-sorting-curation-no-merge.json | 1 + .../curation/tests/test_sortingview_curation.py | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/spikeinterface/curation/tests/sv-sorting-curation-no-merge.json diff --git a/src/spikeinterface/curation/curation_format.py b/src/spikeinterface/curation/curation_format.py index babe7aac40..5a57692597 100644 --- a/src/spikeinterface/curation/curation_format.py +++ b/src/spikeinterface/curation/curation_format.py @@ -92,7 +92,8 @@ def convert_from_sortingview_curation_format_v0(sortingview_dict, destination_fo """ assert destination_format == "1" - + if "mergeGroups" not in sortingview_dict.keys(): + sortingview_dict["mergeGroups"] = [] merge_groups = sortingview_dict["mergeGroups"] merged_units = sum(merge_groups, []) if len(merged_units) > 0: diff --git a/src/spikeinterface/curation/tests/sv-sorting-curation-no-merge.json b/src/spikeinterface/curation/tests/sv-sorting-curation-no-merge.json new file mode 100644 index 0000000000..2a350340f3 --- /dev/null +++ b/src/spikeinterface/curation/tests/sv-sorting-curation-no-merge.json @@ -0,0 +1 @@ +{"labelsByUnit":{"2":["mua"],"3":["mua"],"4":["mua"],"5":["accept"],"6":["accept"],"7":["accept"],"8":["artifact"],"9":["artifact"]}} diff --git a/src/spikeinterface/curation/tests/test_sortingview_curation.py b/src/spikeinterface/curation/tests/test_sortingview_curation.py index bb152e7f71..24bd44a4c8 100644 --- a/src/spikeinterface/curation/tests/test_sortingview_curation.py +++ b/src/spikeinterface/curation/tests/test_sortingview_curation.py @@ -243,6 +243,18 @@ def test_label_inheritance_str(): assert np.all(sorting_include_accept.get_property("accept")) +def test_json_no_merge_curation(): + """ + Test curation with no merges using a JSON file. + """ + sorting = generate_sorting(num_units=10) + + # from curation.json + json_file = parent_folder / "sv-sorting-curation-no-merge.json" + # print(f"Sorting: {sorting.get_unit_ids()}") + sorting_curated_json = apply_sortingview_curation(sorting, uri_or_json=json_file) + + if __name__ == "__main__": # generate_sortingview_curation_dataset() # test_sha1_curation() @@ -251,3 +263,4 @@ def test_label_inheritance_str(): test_false_positive_curation() test_label_inheritance_int() test_label_inheritance_str() + test_json_no_merge_curation() From 1356d3a362174cdfdb3382e777e0f3c3af126e4e Mon Sep 17 00:00:00 2001 From: Robin Kim Date: Thu, 15 Aug 2024 15:11:39 -0500 Subject: [PATCH 2/3] Add comment describing test fail --- src/spikeinterface/curation/tests/test_sortingview_curation.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/spikeinterface/curation/tests/test_sortingview_curation.py b/src/spikeinterface/curation/tests/test_sortingview_curation.py index 24bd44a4c8..6c6dc482c3 100644 --- a/src/spikeinterface/curation/tests/test_sortingview_curation.py +++ b/src/spikeinterface/curation/tests/test_sortingview_curation.py @@ -249,10 +249,9 @@ def test_json_no_merge_curation(): """ sorting = generate_sorting(num_units=10) - # from curation.json json_file = parent_folder / "sv-sorting-curation-no-merge.json" - # print(f"Sorting: {sorting.get_unit_ids()}") sorting_curated_json = apply_sortingview_curation(sorting, uri_or_json=json_file) + # ValueError: Curation format: some labeled units are not in the unit list if __name__ == "__main__": From d029f7d974020145ad6f309e05b3b1456693318b Mon Sep 17 00:00:00 2001 From: Robin Kim Date: Fri, 16 Aug 2024 11:56:39 -0500 Subject: [PATCH 3/3] Fix value error by checking first dict key type --- src/spikeinterface/curation/curation_format.py | 7 +++++-- .../curation/tests/test_sortingview_curation.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/curation/curation_format.py b/src/spikeinterface/curation/curation_format.py index 5a57692597..511abb7801 100644 --- a/src/spikeinterface/curation/curation_format.py +++ b/src/spikeinterface/curation/curation_format.py @@ -96,10 +96,13 @@ def convert_from_sortingview_curation_format_v0(sortingview_dict, destination_fo sortingview_dict["mergeGroups"] = [] merge_groups = sortingview_dict["mergeGroups"] merged_units = sum(merge_groups, []) - if len(merged_units) > 0: - unit_id_type = int if isinstance(merged_units[0], int) else str + + first_unit_id = next(iter(sortingview_dict["labelsByUnit"].keys())) + if str.isdigit(first_unit_id): + unit_id_type = int else: unit_id_type = str + all_units = [] all_labels = [] manual_labels = [] diff --git a/src/spikeinterface/curation/tests/test_sortingview_curation.py b/src/spikeinterface/curation/tests/test_sortingview_curation.py index 6c6dc482c3..945aca7937 100644 --- a/src/spikeinterface/curation/tests/test_sortingview_curation.py +++ b/src/spikeinterface/curation/tests/test_sortingview_curation.py @@ -250,13 +250,13 @@ def test_json_no_merge_curation(): sorting = generate_sorting(num_units=10) json_file = parent_folder / "sv-sorting-curation-no-merge.json" - sorting_curated_json = apply_sortingview_curation(sorting, uri_or_json=json_file) - # ValueError: Curation format: some labeled units are not in the unit list + sorting_curated = apply_sortingview_curation(sorting, uri_or_json=json_file) if __name__ == "__main__": # generate_sortingview_curation_dataset() # test_sha1_curation() + test_gh_curation() test_json_curation() test_false_positive_curation()