-
Notifications
You must be signed in to change notification settings - Fork 230
Add similarity_method param in automerge and fix multi-segment cross-contamination #4201
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
Merged
+100
−102
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4e7ad00
add similarity_method param in automerge and fix multi-segment cross-…
alejoe91 cbc7a91
Clean up auto-merge tests and add multi-segment
alejoe91 b134e47
Update src/spikeinterface/curation/tests/common.py
alejoe91 87d5f02
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into …
alejoe91 b6a4f82
Merge branch 'automerge-fixes' of github.com:alejoe91/spikeinterface …
alejoe91 6cccee9
Back to 300s to make model-based curation pass
alejoe91 6bbc2bf
concatenate multi-segment sorting for cross-contamination
alejoe91 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,7 +74,7 @@ | |
| "sigma_smooth_ms": 0.6, | ||
| "adaptative_window_thresh": 0.5, | ||
| }, | ||
| "template_similarity": {"template_diff_thresh": 0.25}, | ||
| "template_similarity": {"similarity_method": "l1", "template_diff_thresh": 0.25}, | ||
| "presence_distance": {"presence_distance_thresh": 100}, | ||
| "knn": {"k_nn": 10}, | ||
| "cross_contamination": { | ||
|
|
@@ -310,7 +310,13 @@ def compute_merge_unit_groups( | |
| # STEP : check if potential merge with CC also have template similarity | ||
| elif step == "template_similarity": | ||
| template_similarity_ext = sorting_analyzer.get_extension("template_similarity") | ||
| templates_similarity = template_similarity_ext.get_data() | ||
| if template_similarity_ext.params["method"] == params["similarity_method"]: | ||
| templates_similarity = template_similarity_ext.get_data() | ||
| else: | ||
| template_similarity_ext = sorting_analyzer.compute( | ||
| "template_similarity", method=params["similarity_method"], save=False | ||
| ) | ||
| templates_similarity = template_similarity_ext.get_data() | ||
| templates_diff = 1 - templates_similarity | ||
| pair_mask = pair_mask & (templates_diff < params["template_diff_thresh"]) | ||
| outs["templates_diff"] = templates_diff | ||
|
|
@@ -1054,28 +1060,34 @@ def compute_cross_contaminations(analyzer, pair_mask, cc_thresh, refractory_peri | |
| if pair_mask is None: | ||
| pair_mask = np.ones((n, n), dtype="bool") | ||
|
|
||
| CC = np.zeros((n, n), dtype=np.float32) | ||
| p_values = np.zeros((n, n), dtype=np.float32) | ||
|
|
||
| for unit_ind1 in range(len(unit_ids)): | ||
| num_segments = sorting.get_num_segments() | ||
| CC = np.zeros((num_segments, n, n), dtype=np.float32) | ||
| p_values = np.zeros((num_segments, n, n), dtype=np.float32) | ||
|
|
||
| unit_id1 = unit_ids[unit_ind1] | ||
| spike_train1 = np.array(sorting.get_unit_spike_train(unit_id1)) | ||
| for segment_index in range(num_segments): | ||
|
||
| for unit_ind1 in range(len(unit_ids)): | ||
| unit_id1 = unit_ids[unit_ind1] | ||
| spike_train1 = np.array(sorting.get_unit_spike_train(unit_id1, segment_index=segment_index)) | ||
| for unit_ind2 in range(unit_ind1 + 1, len(unit_ids)): | ||
| if not pair_mask[unit_ind1, unit_ind2]: | ||
| continue | ||
|
|
||
| for unit_ind2 in range(unit_ind1 + 1, len(unit_ids)): | ||
| if not pair_mask[unit_ind1, unit_ind2]: | ||
| continue | ||
| unit_id2 = unit_ids[unit_ind2] | ||
| spike_train2 = np.array(sorting.get_unit_spike_train(unit_id2, segment_index=segment_index)) | ||
| # Compuyting the cross-contamination difference | ||
| if contaminations is not None: | ||
| C1 = contaminations[unit_ind1] | ||
| else: | ||
| C1 = None | ||
| CC[segment_index, unit_ind1, unit_ind2], p_values[segment_index, unit_ind1, unit_ind2] = ( | ||
| estimate_cross_contamination( | ||
| spike_train1, spike_train2, sf, n_frames, refractory_period, limit=cc_thresh, C1=C1 | ||
| ) | ||
| ) | ||
|
|
||
| unit_id2 = unit_ids[unit_ind2] | ||
| spike_train2 = np.array(sorting.get_unit_spike_train(unit_id2)) | ||
| # Compuyting the cross-contamination difference | ||
| if contaminations is not None: | ||
| C1 = contaminations[unit_ind1] | ||
| else: | ||
| C1 = None | ||
| CC[unit_ind1, unit_ind2], p_values[unit_ind1, unit_ind2] = estimate_cross_contamination( | ||
| spike_train1, spike_train2, sf, n_frames, refractory_period, limit=cc_thresh, C1=C1 | ||
| ) | ||
| # average over segments | ||
| CC = np.mean(CC, axis=0) | ||
| p_values = np.mean(p_values, axis=0) | ||
|
|
||
| return CC, p_values | ||
|
|
||
|
|
@@ -1194,8 +1206,8 @@ def presence_distance(sorting, unit1, unit2, bin_duration_s=2, bins=None, num_sa | |
| ns = num_samples[segment_index] | ||
| bins = np.arange(0, ns, bin_size) | ||
|
|
||
| st1 = sorting.get_unit_spike_train(unit_id=unit1) | ||
| st2 = sorting.get_unit_spike_train(unit_id=unit2) | ||
| st1 = sorting.get_unit_spike_train(unit_id=unit1, segment_index=segment_index) | ||
| st2 = sorting.get_unit_spike_train(unit_id=unit2, segment_index=segment_index) | ||
|
|
||
| h1, _ = np.histogram(st1, bins) | ||
| h1 = h1.astype(float) | ||
|
|
||
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
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.