Skip to content

Fix kcoords for non-int groups #3944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/scripts/test_kilosort4_ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
PARAMS_TO_TEST_DICT.update({"cluster_neighbors": 11})
PARAMETERS_NOT_AFFECTING_RESULTS.append("cluster_neighbors")

if parse(kilosort.__version__) >= parse("4.0.37"):
PARAMS_TO_TEST_DICT.update({"max_cluster_subset": 20})
PARAMETERS_NOT_AFFECTING_RESULTS.append("max_cluster_subset")


PARAMS_TO_TEST = list(PARAMS_TO_TEST_DICT.keys())

Expand Down Expand Up @@ -254,6 +258,8 @@ def test_initialize_ops_arguments(self):
"device",
"save_preprocessed_copy",
]
if parse(kilosort.__version__) >= parse("4.0.37"):
expected_arguments += ["gui_mode"]

self._check_arguments(
initialize_ops,
Expand Down
4 changes: 3 additions & 1 deletion src/spikeinterface/sorters/external/kilosort4.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def _setup_json_probe_map(cls, recording, sorter_output_folder):
chanMap = np.arange(n_chan)
xc = positions[:, 0]
yc = positions[:, 1]
kcoords = groups.astype(float)
unique_groups = set(groups)
group_map = {group: idx for idx, group in enumerate(unique_groups)}
kcoords = np.array([group_map[group] for group in groups], dtype=int)
Copy link
Member

Choose a reason for hiding this comment

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

I guess the other option here is

kcoords = np.array(group_map.values(), dtype=int)

This just makes it more readable for me, but doesn't help with the code so feel free to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

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

@zm711 just realized that doesn't work. We need kcoords to be the same length as x and y. Reverted

Copy link
Member

Choose a reason for hiding this comment

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

Hello, is this np.array gonna fail when the groups have a different number of electrodes in each one? i.e. when you have some configuration with 182 electodes on shank 1, 96 on shank 2 and 96 on shank 3.

Copy link
Member Author

Choose a reason for hiding this comment

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

No because it returns a flat list of inta from 0 to Ngroups-1

Copy link
Member

Choose a reason for hiding this comment

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

my bad. I actually had the same thought as I was falling asleep last night and was going to post when I woke up!


probe = {
"chanMap": chanMap,
Expand Down