Skip to content

Question: how to ONLY add "manual_labels" when using "apply_curation" #3584

Open
@borrepp

Description

@borrepp

Hello,
I'm trying to add some labels ["good", "noise", "mua", "artifact"] to a sorting_analyzer, but when I wanted to do it by creating a dictionary with empty "removed_units" & "merge_units_groups" it throws an error saying that merge_unit_groups must contain at least two units. But I don't want to merge anything. I only want to add labels. Is there a way to do it by "curation_dict", The alternative I found was by setting a property to the "sorting_analyzer.sorting.set_property('quality', ['mua'])". I only have one unit, so it was not complicated, but it might be useful to allow "apply_curation" when there are no merge_units_groups.

A related question after I set the property is: What is the best practice for saving this change?
I did it by saving the sorting analyzer again:
"sorting_analyzer.save_as(format="binary_folder", folder=sorter_analyzer_folder+'_curated')"
Is there a way to avoid rewriting the folder?

Thanks in advance for your help.

Here is the dictionary that I created for curation:

# Sample Dictionary to be applied on the result to have a “clean” result
curation_dict = dict(
    format_version = "1",
    # Define LABELS
    # For label category with exclusive=True : a column is created and values are the unique label.
    # For label category with exclusive=False : one column per possible is created and values are boolean.
    label_definitions = dict(
        quality = dict(label_options = ["good", "noise", "mua", "artifact"], exclusive = True)
        # Keep adding custom labels. Example:
        # putative_type = dict(label_options = ["excitatory", "inhibitory", "pyramidal", "mitral"], exclusive = False)
    ),
    # 
    unit_ids = sorting_analyzer.unit_ids,
    removed_units = [], # List of units to remove. Example: [31, 42]
    merge_unit_groups = [[], []], # List of Lists of units to merge (at least 2 units require). Example: [[3, 6], [10, 14, 20]]
    manual_labels = [
        dict(unit_id = 1, quality = ["mua"]),
        # Keep adding neurons' labels. Example:
        # dict(unit_id = 2, quality = ["noise"], putative_type = ["excitatory", "pyramidal"])
    ],
)

Here is the error when trying "apply_curation" with that dictionary:

--> [343](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:343) analyzer, new_unit_ids = analyzer.merge_units(
    [344](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:344)     curation_dict["merge_unit_groups"],
    [345](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:345)     censor_ms=censor_ms,
    [346](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:346)     merging_mode=merging_mode,
    [347](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:347)     sparsity_overlap=sparsity_overlap,
    [348](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:348)     new_id_strategy=new_id_strategy,
    [349](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:349)     return_new_unit_ids=True,
    [350](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:350)     format="memory",
    [351](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:351)     verbose=verbose,
    [352](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:352)     **job_kwargs,
    [353](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:353) )
    [354](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:354) apply_curation_labels(analyzer.sorting, new_unit_ids, curation_dict)
    [355](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/curation/curation_format.py:355) return analyzer

File m:\Monkey_Python\SIenv\Lib\site-packages\spikeinterface\core\sortinganalyzer.py:1101, in SortingAnalyzer.merge_units(self, merge_unit_groups, new_unit_ids, censor_ms, merging_mode, sparsity_overlap, new_id_strategy, return_new_unit_ids, format, folder, verbose, **job_kwargs)
   [1098](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1098) for units in merge_unit_groups:
   [1099](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1099)     # TODO more checks like one units is only in one group
   [1100](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1100)     if len(units) < 2:
-> [1101](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1101)         raise ValueError("Merging requires at least two units to merge")
   [1103](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1103) # TODO : no this function did not exists before
   [1104](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1104) if not isinstance(merge_unit_groups[0], (list, tuple)):
   [1105](file:///M:/Monkey_Python/SIenv/Lib/site-packages/spikeinterface/core/sortinganalyzer.py:1105)     # keep backward compatibility : the previous behavior was only one merge

ValueError: Merging requires at least two units to merge

Metadata

Metadata

Assignees

No one assigned

    Labels

    curationRelated to curation module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions