-
Notifications
You must be signed in to change notification settings - Fork 230
Allow aggregate_channels to accept a dict of recordings
#3767
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
Allow aggregate_channels to accept a dict of recordings
#3767
Conversation
for more information, see https://pre-commit.ci
…chrishalcrow/spikeinterface into add-dicts-to-aggregate-channels
| # Check if the recordings were previously split using `split_by` | ||
| if recording_list[0].get_annotation("split_by_property") is None: | ||
| # If default 'group'ing (all equal 0), we label the recordings using the 'group' property | ||
| recording_groups = [] | ||
| for recording in recording_list: | ||
| if (group_property := recording.get_property("group")) is not None: | ||
| recording_groups.extend(group_property) | ||
| else: | ||
| recording_groups.extend([0]) | ||
| if np.all(np.unique(recording_groups) == np.array([0])): | ||
| for group_id, recording in enumerate(recording_list): | ||
| recording.set_property("group", group_id * np.ones(recording.get_num_channels())) |
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.
This should be done after the else, because it applies to both dicts and lists inputs. Right?
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.
No you're right. In case of dicts properties are correctly handled 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 we're both right: we should use the dictionary keys for group if we don't know how the recording was split up (ie if there's no split_by_property and groups are all 0). I've added this
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 also refactored a bit so this gross bit of code is contained
src/spikeinterface/core/tests/test_channelsaggregationrecording.py
Outdated
Show resolved
Hide resolved
| # If we don't label at all, aggregation will add a 'group' label | ||
| recording1.set_property("group", [0, 0, 0, 0]) | ||
| recording2.set_property("group", [0, 0]) | ||
| aggregated_recording = aggregate_channels([recording1, recording2]) | ||
| group_property = aggregated_recording.get_property("group") | ||
| assert np.all(group_property == [0, 0, 0, 0, 1, 1]) | ||
|
|
||
| # If we have different group labels, these should be respected | ||
| recording1.set_property("group", [2, 2, 2, 2]) | ||
| recording2.set_property("group", [6, 6]) | ||
| aggregated_recording = aggregate_channels([recording1, recording2]) | ||
| group_property = aggregated_recording.get_property("group") | ||
| assert np.all(group_property == [2, 2, 2, 2, 6, 6]) | ||
|
|
||
| # If we use `split_by`, aggregation should retain the split_by property, even if we only pass the list | ||
| recording1.set_property("user_group", [6, 7, 6, 7]) | ||
| recording_list = list(recording1.split_by("user_group").values()) | ||
| aggregated_recording = aggregate_channels(recording_list) | ||
| group_property = aggregated_recording.get_property("group") | ||
| assert np.all(group_property == [2, 2, 2, 2]) | ||
| user_group_property = aggregated_recording.get_property("user_group") | ||
| # Note, aggregation reorders the channel_ids into the order of the ids of each individual recording | ||
| assert np.all(user_group_property == [6, 6, 7, 7]) |
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.
Nice :)
…g.py Co-authored-by: Alessio Buccino <alejoe9187@gmail.com>
zm711
left a comment
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.
Two small comments (I think)
…chrishalcrow/spikeinterface into add-dicts-to-aggregate-channels
|
Thanks @chrishalcrow LGTM! Ready to merge? |
zm711
left a comment
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.
Me too
|
Parfait. |
Related to #3711
Allows
aggregate_channelsto accept a dict of recordings. This allows for the workflow (once #3711 is merged) of the kind:or the truly horrifying
edit: PR is mostly new tests