Skip to content

Commit

Permalink
Renaming curation dictionary keys
Browse files Browse the repository at this point in the history
Took 10 minutes
  • Loading branch information
remi-pr committed May 30, 2024
1 parent 1021163 commit 8094053
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
22 changes: 11 additions & 11 deletions src/spikeinterface/curation/curation_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def validate_curation_dict(curation_dict):
f"Only {supported_versions} are valid")
# Check the labels exclusivity
for lbl in curation_dict["manual_labels"]:
lbl_key = lbl["label_category_key"]
is_exclusive = curation_dict["labels_definition"][lbl_key]["auto_eclusive"]
if is_exclusive and not isinstance(lbl["label_category_value"], str):
raise ValueError(f"{lbl_key} are mutually exclusive labels. {lbl['label_category_value']} is invalid")
elif not is_exclusive and not isinstance(lbl["label_category_value"], list):
lbl_key = lbl["label_category"]
is_exclusive = curation_dict["label_definitions"][lbl_key]["auto_exclusive"]
if is_exclusive and not isinstance(lbl["labels"], str):
raise ValueError(f"{lbl_key} are mutually exclusive labels. {lbl['labels']} is invalid")
elif not is_exclusive and not isinstance(lbl["labels"], list):
raise ValueError(f"{lbl_key} are not mutually exclusive labels. "
f"{lbl['label_category_value']} should be a lists")
f"{lbl['labels']} should be a lists")
return True


Expand Down Expand Up @@ -82,15 +82,15 @@ def convert_from_sortingview(sortingview_dict, destination_format=1):
all_labels.extend(l_labels)
u_id = unit_id_type(unit_id)
all_units.append(u_id)
manual_labels.append({'unit_id': u_id, "label_category_key": general_cat,
"label_category_value": l_labels})
manual_labels.append({'unit_id': u_id, "label_category": general_cat,
"labels": l_labels})
labels_def = {"all_labels":
{"name": "all_labels",
"labels": all_labels,
"auto_eclusive": False}}
"label_options": all_labels,
"auto_exclusive": False}}

curation_dict = {"unit_ids": None,
"labels_definition": labels_def,
"label_definitions": labels_def,
"manual_labels": manual_labels,
"merged_unit_groups": merge_groups,
"removed_units": [],
Expand Down
94 changes: 47 additions & 47 deletions src/spikeinterface/curation/tests/test_curation_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

"""example = {
'unit_ids': List[str, int],
'labels_definition': {
'label_definitions': {
'category_key1':
{'name': str,
'labels': List[str],
'auto_eclusive': bool}
'label_options': List[str],
'auto_exclusive': bool}
},
'manual_labels': [
{'unit_id': str or int,
'label_category_key': str,
'label_category_value': list or str
'label_category': str,
'labels': list or str
}
],
'merged_unit_groups': List[List[unit_ids]], # one cell goes into at most one list
Expand All @@ -23,18 +23,18 @@

valid_int = {
"unit_ids": [1, 2, 3, 6, 10, 14, 20, 31, 42],
"labels_definition": {
"quality": {"name": "quality", "labels": ["good", "noise", "MUA", "artifact"], "auto_eclusive": True},
"label_definitions": {
"quality": {"name": "quality", "label_options": ["good", "noise", "MUA", "artifact"], "auto_exclusive": True},
"experimental": {
"name": "experimental",
"labels": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_eclusive": False,
"label_options": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_exclusive": False,
},
},
"manual_labels": [
{"unit_id": 1, "label_category_key": "quality", "label_category_value": "good"},
{"unit_id": 2, "label_category_key": "quality", "label_category_value": "noise"},
{"unit_id": 2, "label_category_key": "experimental", "label_category_value": ["chronic", "headfixed"]},
{"unit_id": 1, "label_category": "quality", "labels": "good"},
{"unit_id": 2, "label_category": "quality", "labels": "noise"},
{"unit_id": 2, "label_category": "experimental", "labels": ["chronic", "headfixed"]},
],
"merged_unit_groups": [[3, 6], [10, 14, 20]], # one cell goes into at most one list
"removed_units": [31, 42], # Can not be in the merged_units
Expand All @@ -44,18 +44,18 @@

valid_str = {
"unit_ids": ["u1", "u2", "u3", "u6", "u10", "u14", "u20", "u31", "u42"],
"labels_definition": {
"quality": {"name": "quality", "labels": ["good", "noise", "MUA", "artifact"], "auto_eclusive": True},
"label_definitions": {
"quality": {"name": "quality", "label_options": ["good", "noise", "MUA", "artifact"], "auto_exclusive": True},
"experimental": {
"name": "experimental",
"labels": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_eclusive": False,
"label_options": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_exclusive": False,
},
},
"manual_labels": [
{"unit_id": "u1", "label_category_key": "quality", "label_category_value": "good"},
{"unit_id": "u2", "label_category_key": "quality", "label_category_value": "noise"},
{"unit_id": "u2", "label_category_key": "experimental", "label_category_value": ["chronic", "headfixed"]},
{"unit_id": "u1", "label_category": "quality", "labels": "good"},
{"unit_id": "u2", "label_category": "quality", "labels": "noise"},
{"unit_id": "u2", "label_category": "experimental", "labels": ["chronic", "headfixed"]},
],
"merged_unit_groups": [["u3", "u6"], ["u10", "u14", "u20"]], # one cell goes into at most one list
"removed_units": ["u31", "u42"], # Can not be in the merged_units
Expand All @@ -65,18 +65,18 @@
# This is a failure example
duplicate_merge = {
"unit_ids": [1, 2, 3, 6, 10, 14, 20, 31, 42],
"labels_definition": {
"quality": {"name": "quality", "labels": ["good", "noise", "MUA", "artifact"], "auto_eclusive": True},
"label_definitions": {
"quality": {"name": "quality", "label_options": ["good", "noise", "MUA", "artifact"], "auto_exclusive": True},
"experimental": {
"name": "experimental",
"labels": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_eclusive": False,
"label_options": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_exclusive": False,
},
},
"manual_labels": [
{"unit_id": 1, "label_category_key": "quality", "label_category_value": "good"},
{"unit_id": 2, "label_category_key": "quality", "label_category_value": "noise"},
{"unit_id": 2, "label_category_key": "experimental", "label_category_value": ["chronic", "headfixed"]},
{"unit_id": 1, "label_category": "quality", "labels": "good"},
{"unit_id": 2, "label_category": "quality", "labels": "noise"},
{"unit_id": 2, "label_category": "experimental", "labels": ["chronic", "headfixed"]},
],
"merged_unit_groups": [[3, 6, 10], [10, 14, 20]], # one cell goes into at most one list
"removed_units": [31, 42], # Can not be in the merged_units
Expand All @@ -87,18 +87,18 @@
# This is a failure example
merged_and_removed = {
"unit_ids": [1, 2, 3, 6, 10, 14, 20, 31, 42],
"labels_definition": {
"quality": {"name": "quality", "labels": ["good", "noise", "MUA", "artifact"], "auto_eclusive": True},
"label_definitions": {
"quality": {"name": "quality", "label_options": ["good", "noise", "MUA", "artifact"], "auto_exclusive": True},
"experimental": {
"name": "experimental",
"labels": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_eclusive": False,
"label_options": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_exclusive": False,
},
},
"manual_labels": [
{"unit_id": 1, "label_category_key": "quality", "label_category_value": "good"},
{"unit_id": 2, "label_category_key": "quality", "label_category_value": "noise"},
{"unit_id": 2, "label_category_key": "experimental", "label_category_value": ["chronic", "headfixed"]},
{"unit_id": 1, "label_category": "quality", "labels": "good"},
{"unit_id": 2, "label_category": "quality", "labels": "noise"},
{"unit_id": 2, "label_category": "experimental", "labels": ["chronic", "headfixed"]},
],
"merged_unit_groups": [[3, 6], [10, 14, 20]], # one cell goes into at most one list
"removed_units": [3, 31, 42], # Can not be in the merged_units
Expand All @@ -108,18 +108,18 @@

unknown_merged_unit = {
"unit_ids": [1, 2, 3, 6, 10, 14, 20, 31, 42],
"labels_definition": {
"quality": {"name": "quality", "labels": ["good", "noise", "MUA", "artifact"], "auto_eclusive": True},
"label_definitions": {
"quality": {"name": "quality", "label_options": ["good", "noise", "MUA", "artifact"], "auto_exclusive": True},
"experimental": {
"name": "experimental",
"labels": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_eclusive": False,
"label_options": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_exclusive": False,
},
},
"manual_labels": [
{"unit_id": 1, "label_category_key": "quality", "label_category_value": "good"},
{"unit_id": 2, "label_category_key": "quality", "label_category_value": "noise"},
{"unit_id": 2, "label_category_key": "experimental", "label_category_value": ["chronic", "headfixed"]},
{"unit_id": 1, "label_category": "quality", "labels": "good"},
{"unit_id": 2, "label_category": "quality", "labels": "noise"},
{"unit_id": 2, "label_category": "experimental", "labels": ["chronic", "headfixed"]},
],
"merged_unit_groups": [[3, 6, 99], [10, 14, 20]], # one cell goes into at most one list
"removed_units": [31, 42], # Can not be in the merged_units
Expand All @@ -129,18 +129,18 @@

unknown_removed_unit = {
"unit_ids": [1, 2, 3, 6, 10, 14, 20, 31, 42],
"labels_definition": {
"quality": {"name": "quality", "labels": ["good", "noise", "MUA", "artifact"], "auto_eclusive": True},
"label_definitions": {
"quality": {"name": "quality", "label_options": ["good", "noise", "MUA", "artifact"], "auto_exclusive": True},
"experimental": {
"name": "experimental",
"labels": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_eclusive": False,
"label_options": ["acute", "chronic", "headfixed", "freelymoving"],
"auto_exclusive": False,
},
},
"manual_labels": [
{"unit_id": 1, "label_category_key": "quality", "label_category_value": "good"},
{"unit_id": 2, "label_category_key": "quality", "label_category_value": "noise"},
{"unit_id": 2, "label_category_key": "experimental", "label_category_value": ["chronic", "headfixed"]},
{"unit_id": 1, "label_category": "quality", "labels": "good"},
{"unit_id": 2, "label_category": "quality", "labels": "noise"},
{"unit_id": 2, "label_category": "experimental", "labels": ["chronic", "headfixed"]},
],
"merged_unit_groups": [[3, 6], [10, 14, 20]], # one cell goes into at most one list
"removed_units": [31, 42, 99], # Can not be in the merged_units
Expand Down

0 comments on commit 8094053

Please sign in to comment.