Add main_channel_id when running Kilosort - #4725
Draft
chrishalcrow wants to merge 1 commit into
Draft
Conversation
alejoe91
reviewed
Jul 31, 2026
Comment on lines
+460
to
+471
| if (results_dir / "templates.npy").is_file(): | ||
| # Note: these are the whitened templates | ||
| templates = np.load(results_dir / "templates.npy") | ||
| # main channel indices are the argmax of the ptp of the templates | ||
| main_channel_indices = np.argmax(np.ptp(templates, axis=1), axis=1) | ||
| main_channel_ids = recording.channel_ids[main_channel_indices] | ||
| # save main_channel_ids | ||
| with open(results_dir / "cluster_main_channel_id.tsv", "w", newline="", encoding="utf-8") as f: | ||
| writer = csv.writer(f, delimiter="\t") | ||
| writer.writerow(["cluster_id", "main_channel_id"]) | ||
| for unit_index, item in enumerate(main_channel_ids): | ||
| writer.writerow([unit_index, item]) |
Member
There was a problem hiding this comment.
Smart! So they are loaded automatically as properties :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Starts work on #4692
We recently added the sorting property
main_channel_idand the analyzer propertymain_channel_indexwhich allows sorters to tell us which channel each unit is localized on.It would be great to get this information from each sorter when it's run. Doing so means: 1) we don't need to guess the main channel => the results should be closer to the original sorter output 2) we can do an almost-instantaneous sparsity calculation.
But no external sorters actually give us the
main_channel_idyet. One way to overcome this is to guess themain_channel_idstraight after the sorting has completed (i.e. the end ofrun_sorter). At this point, we have access to whatever the sorter outputs, and we still have access to the recording. This PR implements that option.One downside of this option is that we usually don't touch the
sorter_outputfolder: that's usually just what the sorter outputs. I think this is the first time (for kilosort at least) that we're adding some additional information.Other possible options:
main_channel_idunless the sorter tells us what it is