Skip to content

Fix aggregate_channels merging of channel ids with different string sub type #3740

Merged
alejoe91 merged 9 commits into
SpikeInterface:mainfrom
h-mayorquin:fix_chris_bug
Mar 7, 2025
Merged

Fix aggregate_channels merging of channel ids with different string sub type #3740
alejoe91 merged 9 commits into
SpikeInterface:mainfrom
h-mayorquin:fix_chris_bug

Conversation

@h-mayorquin

Copy link
Copy Markdown
Contributor

This will fix @chrishalcrow bug on #3733.

The current check for all_channels_have_same_type is too strict. I added a test.

@h-mayorquin h-mayorquin added the bug Something isn't working label Mar 4, 2025
@h-mayorquin h-mayorquin self-assigned this Mar 4, 2025
@h-mayorquin

Copy link
Copy Markdown
Contributor Author

The error comes from the token limit : P

Comment thread src/spikeinterface/core/channelslice.py Outdated
chan_id in parents_chan_ids for chan_id in self._channel_ids
), "ChannelSliceRecording : channel ids are not all in parents"
is_channel_in_parent = [chan_id in parents_chan_ids.tolist() for chan_id in self._channel_ids.tolist()]
assert all(is_channel_in_parent), "ChannelSliceRecording : channel ids are not all in parents"

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.

Could be helpful to list them? Something like

channels_not_in_parents = [chan_id for chan_id in self._challen_ids.tolist() if chan_id not in parents_chan_ids.tolist()]
assert len(channels_not_in_parents) == 0, f"ChannelSliceRecording : channel ids {channels_not_in_parents} are not all in parent ids {parents_chan_ids}"

Or maybe this is totally overwhelming for large dense probes?

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.

I think it would be good to add the channel list in the error message

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I will add in the next commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

assert list(aggregated_recording.get_channel_ids()) == ["0", "1", "2", "3", "4"]


def test_channel_aggregation_with_string_dtypes_of_different_size():

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.

Lovely test!
Would be nice to have a docstring with a brief description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a docstring. Let me know what you think.

@chrishalcrow

Copy link
Copy Markdown
Member

Works for me, and looks less hacky than my proposed solution. Just made some doc-y comments.

Comment thread src/spikeinterface/core/channelslice.py Outdated
), "ChannelSliceRecording : channel_ids are not unique"

sampling_frequency = parent_recording.get_sampling_frequency()
assert sampling_frequency > 0, "Sampling frequency must be positive."

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.

why not move it to BaseRecording.__init__?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is already there, I must have push tab with the new copilot feature. Removing.

Comment thread src/spikeinterface/core/channelslice.py Outdated
@alejoe91
alejoe91 merged commit 3cef709 into SpikeInterface:main Mar 7, 2025
@h-mayorquin
h-mayorquin deleted the fix_chris_bug branch March 7, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants