-
Notifications
You must be signed in to change notification settings - Fork 271
Fix channel order bug and make select_channels private
#4712
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
chrishalcrow
wants to merge
11
commits into
SpikeInterface:main
Choose a base branch
from
chrishalcrow:select-channel-fixes
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.
Open
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b84613b
Fix channel order bug
chrishalcrow f21e73f
add waveforms and pc slicing
chrishalcrow cacbb31
add and fix tests for selected analyzers
chrishalcrow 66396fb
respond to alessio
chrishalcrow c9e1caa
oups in tests
chrishalcrow 9502b82
Move PCA test to postprocessing
chrishalcrow 821aeb6
tweak loop when selecting
chrishalcrow 3132f3b
deal with zero channel case
chrishalcrow 14d9a00
respond to alessio review
chrishalcrow 29a7d08
Merge branch 'main' into select-channel-fixes
chrishalcrow eb2c9f0
update channel_indices naming
chrishalcrow 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -98,6 +98,42 @@ def _select_units_extension_data(self, unit_ids): | |||||||||||||||||||||
| new_data[k] = v | ||||||||||||||||||||||
| return new_data | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def _select_channels_extension_data(self, channel_ids): | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| unit_ids = self.sorting_analyzer.unit_ids | ||||||||||||||||||||||
| old_unit_id_to_channel_ids = self.sorting_analyzer.sparsity.unit_id_to_channel_ids | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| unit_sparsity_slices = {} | ||||||||||||||||||||||
| for unit_id in unit_ids: | ||||||||||||||||||||||
| channel_indices = [] | ||||||||||||||||||||||
| unit_channel_ids = old_unit_id_to_channel_ids[unit_id] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| for channel_id in channel_ids: | ||||||||||||||||||||||
| if channel_id in unit_channel_ids: | ||||||||||||||||||||||
| idx = np.where(old_unit_id_to_channel_ids[unit_id] == channel_id)[0][0] | ||||||||||||||||||||||
| channel_indices.append(idx) | ||||||||||||||||||||||
|
Member
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.
Suggested change
same here |
||||||||||||||||||||||
| unit_sparsity_slices[unit_id] = np.array(channel_indices) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| old_pcs = self.data["pca_projection"] | ||||||||||||||||||||||
| random_spikes = self.sorting_analyzer.get_extension("random_spikes").get_random_spikes() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| new_waveforms = np.zeros_like(old_pcs) | ||||||||||||||||||||||
| max_num_active_channels = 0 | ||||||||||||||||||||||
| for waveform_index, (waveform, spike) in enumerate(zip(old_pcs, random_spikes)): | ||||||||||||||||||||||
|
chrishalcrow marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| unit_index = spike["unit_index"] | ||||||||||||||||||||||
| unit_id = unit_ids[unit_index] | ||||||||||||||||||||||
| channel_slice = unit_sparsity_slices[unit_id] | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| size_of_new_mask = len(channel_slice) | ||||||||||||||||||||||
| new_waveforms[waveform_index, :, :size_of_new_mask] = waveform[:, channel_slice] | ||||||||||||||||||||||
|
chrishalcrow marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| max_num_active_channels = max(max_num_active_channels, size_of_new_mask) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| data = {"pca_projection": new_waveforms[:, :, :max_num_active_channels]} | ||||||||||||||||||||||
|
chrishalcrow marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return data | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def _merge_extension_data( | ||||||||||||||||||||||
| self, merge_unit_groups, new_unit_ids, new_sorting_analyzer, keep_mask=None, verbose=False, **job_kwargs | ||||||||||||||||||||||
| ): | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
Uh oh!
There was an error while loading. Please reload this page.
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 that this does the exact same thing, 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.
You need the old
channel_ids_to_indices, not the new ones fromself.sorting_analyzer.channel_ids_to_indicesThere 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.
selfis the old analyzer, no?See:
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.
Oop - we're both wrong. The
channel_indicestell you how to map between the channel_indices with respect to the sparsity mask for each unit (no the overall channel_indices). You can make the code look very simple if you have access to the new sorting_analyzer's sparsity mask, which we don't easily have.I've updated the variables names, which I think should help avoid confusion.