-
Notifications
You must be signed in to change notification settings - Fork 23
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
Detect mismatch errors between group and group names when writing ElectrodeGroups
#1165
Draft
h-mayorquin
wants to merge
7
commits into
main
Choose a base branch
from
add_electrode_group_and_mismatch_test_on_spikeinterface
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
86b820e
add failing test
h-mayorquin 333ad69
add passing test
h-mayorquin c8f91c7
add changelog
h-mayorquin 3a8a8b1
add tests to detect mismatch errors and fix it
h-mayorquin cf579d6
CHANGELOG.md
h-mayorquin a58436a
Merge branch 'main' into add_electrode_group_and_mismatch_test_on_spi…
h-mayorquin 366bc8f
use set instead of np.unique
h-mayorquin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,11 +245,19 @@ def _get_group_name(recording: BaseRecording) -> np.ndarray: | |
An array containing the group names. If the `group_name` property is not | ||
available, the channel groups will be returned. If the group names are | ||
empty, a default value 'ElectrodeGroup' will be used. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
If the number of unique group names doesn't match the number of unique groups, | ||
or if the mapping between group names and group numbers is inconsistent. | ||
""" | ||
default_value = "ElectrodeGroup" | ||
group_names = recording.get_property("group_name") | ||
groups = recording.get_channel_groups() | ||
|
||
if group_names is None: | ||
group_names = recording.get_channel_groups() | ||
group_names = groups | ||
if group_names is None: | ||
group_names = np.full(recording.get_num_channels(), fill_value=default_value) | ||
|
||
|
@@ -259,6 +267,23 @@ def _get_group_name(recording: BaseRecording) -> np.ndarray: | |
# If for any reason the group names are empty, fill them with the default | ||
group_names[group_names == ""] = default_value | ||
|
||
# Validate group names against groups | ||
if groups is not None: | ||
unique_groups = np.unique(groups) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmm I will change this to sets as I remember np.unique being buggy for strings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the correction. |
||
unique_names = np.unique(group_names) | ||
|
||
if len(unique_names) != len(unique_groups): | ||
raise ValueError("The number of group names must match the number of groups") | ||
|
||
# Check consistency of group name to group number mapping | ||
group_to_name_map = {} | ||
for group, name in zip(groups, group_names): | ||
if group in group_to_name_map: | ||
if group_to_name_map[group] != name: | ||
raise ValueError("Inconsistent mapping between group numbers and group names") | ||
else: | ||
group_to_name_map[group] = name | ||
|
||
return group_names | ||
|
||
|
||
|
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this us never None, so L262 will never be reached