Skip to content

Initial dartsort wrapper implementation. - #2125

Open
samuelgarcia wants to merge 31 commits into
SpikeInterface:mainfrom
samuelgarcia:dartsort_wrapper
Open

Initial dartsort wrapper implementation.#2125
samuelgarcia wants to merge 31 commits into
SpikeInterface:mainfrom
samuelgarcia:dartsort_wrapper

Conversation

@samuelgarcia

Copy link
Copy Markdown
Member

@alejoe91 alejoe91 added the sorters Related to sorters module label Oct 25, 2023
@samuelgarcia

Copy link
Copy Markdown
Member Author

@cwindolf any news ?

@alejoe91
alejoe91 marked this pull request as draft February 3, 2025 09:50
@alejoe91 alejoe91 added this to the 0.106.0 milestone Jul 17, 2026
@alejoe91 alejoe91 modified the milestones: 0.106.0, 0.105.0 Sep 3, 2026
Comment thread src/spikeinterface/sorters/external/dartsort.py
Comment thread src/spikeinterface/sorters/external/dartsort.py Outdated
Comment thread src/spikeinterface/sorters/external/dartsort.py Outdated
sorting = NumpySorting.from_samples_and_labels(
[times_samples[mask]], [labels[mask]], dartsort_sorting.sampling_frequency
)

@chrishalcrow chrishalcrow Sep 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# The main channel ids are kept in the Templates, which are saved in the sorter_output_folder
matching_model_folders = list(Path(sorter_output_folder).glob("matching*_models"))
if len(matching_model_folders) > 0:
matching_model_folders.sort(key=lambda p: int(p.stem[8:-7]))
last_matching_model_folder = matching_model_folders[-1]
if (template_data_file := last_matching_model_folder / 'template_data.npz').is_file():
from dartsort.templates.templates import TemplateData
template_data = TemplateData.from_npz(template_data_file)
main_channel_indices = template_data.main_channels()
main_channel_ids = recording.channel_ids[main_channel_indices]
sorting.set_property('main_channel_id', main_channel_ids)

We can add main_channel_ids by taking them from the templates file (as suggested by @cwindolf). Am testing on some real data now...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this doesn't work. A unit can be made from spikes from several templates, so there's no one to one map from the templates to unit main_channel_ids.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but all templates associated to a unit should roughly have the same channels no? We could take the mode of the main channels from the templates associated to the same unit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cwindolf could this be implemented directly in dartsort? so that the to_numpy_sorting will already have this property

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spike_channels = dartsort_sorting.channels
main_channel_indices = [mode(spike_channels[labels == unit_id])[0] for unit_id in sorting.unit_ids]
main_channel_ids = recording.channel_ids[main_channel_indices]
sorting.set_property('main_channel_id', main_channel_ids)

Dartsort keeps the channel of each spike! So we can easily take the mode of the spike channels for each unit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works!!

samuelgarcia and others added 3 commits September 8, 2026 14:06
Co-authored-by: Chris Halcrow <57948917+chrishalcrow@users.noreply.github.com>
Co-authored-by: Chris Halcrow <57948917+chrishalcrow@users.noreply.github.com>
@samuelgarcia
samuelgarcia marked this pull request as ready for review September 8, 2026 13:57
Comment thread src/spikeinterface/sorters/external/dartsort.py
@alejoe91

Copy link
Copy Markdown
Member

Ok fixed a couple of stuff:

@alejoe91

Copy link
Copy Markdown
Member

Ok to merge?

@cwindolf cwindolf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thank you guys. Just adding some website links basically here.

Comment thread doc/index.rst Outdated
Comment thread doc/modules/sorters.rst Outdated
Comment thread src/spikeinterface/sorters/external/dartsort.py Outdated
Comment thread src/spikeinterface/sorters/external/dartsort.py Outdated
Comment thread README.md Outdated
Co-authored-by: Charlie Windolf <charliexwindolf@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sorters Related to sorters module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants