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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

alejoe91
Copy link
Member

Introduced by #3852, if the channel groups are not strings they cannot be cast to float. This makes a map to integers

@alejoe91 alejoe91 added bug Something isn't working sorters Related to sorters module labels May 21, 2025
@alejoe91 alejoe91 requested a review from zm711 May 21, 2025 16:23
@@ -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 = np.unique(groups)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remember the bug with np.unique, we should use set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right! Let me change that!

Copy link
Member

Choose a reason for hiding this comment

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

What's the np.unique bug? We use it a lot!

Copy link
Member Author

Choose a reason for hiding this comment

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

I vaguely remember a potential overflow issue since numpy is returning np.int* instead of Python int (of course in case the elements are ints). @h-mayorquin how wrong am I?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi, guys, sorry I should have been more clear but I actually don't remember. At some point we encountered some bug with np.unique with mixed types and I have been weary of using since most of the times a set just does the same.

They are enhancing the np.unique so maybe the old bug is gone but I don't have time to track it:

numpy/numpy#28375

kcoords = groups.astype(float)
unique_groups = np.unique(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!

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sorters Related to sorters module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants