Add main_channel_id when running Kilosort - #4725
chrishalcrow wants to merge 1 commit into
Conversation
| 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]) |
There was a problem hiding this comment.
Smart! So they are loaded automatically as properties :)
There was a problem hiding this comment.
Maybe we can move this to KilosortBase as a static method so that KS2/2.5/3 could also do it?
There was a problem hiding this comment.
After discussion we should:
- load
channel_idsfromspikeinterface_recoridng.jsoninKilosortBase._get_result_from_folder(without loading the recording, just parsing the JSON) - modify the
KiloSortSortingExtractorto optionally accept achannel_idsinput: if given, then add the argmax logic there and set themain_channel_idproperty
|
I am not sure to like the idea of adding extra files to the original KS folder... Also we can imagine another way : save in the parent (where we have the params.json) a numpysorting version that contains all properties. |
|
We need to do it during |
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