SpikeInterface / SpikeInterface/spikeinterface

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

Open
#3,584 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

curation
Dominant language
Python
Stars
847
Forks
280
Avg merge
3d 9h
Merged PRs (30d)
29

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in curation/curation_format.py at apply_curation and in core/sortinganalyzer.py at merge_units, where the empty merge groups trigger the reported error. Trace how manual_labels and sorting properties are applied, then add coverage for label-only curation and verify the requested saving behavior; the issue does not name an existing test file.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.