Skip to content

Commit f220263

Browse files
committed
put back extra_outputs in find_spikes_from_templates()
1 parent 2300efe commit f220263

5 files changed

Lines changed: 45 additions & 25 deletions

File tree

src/spikeinterface/sortingcomponents/clustering/clustering_tools.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -602,21 +602,11 @@ def detect_mixtures(templates, method_kwargs={}, job_kwargs={}, tmp_folder=None,
602602

603603
sub_recording = recording.frame_slice(t_start, t_stop)
604604
local_params.update({"ignore_inds": ignore_inds + [i]})
605-
spikes, computed = find_spikes_from_templates(
605+
606+
spikes, more_outputs = find_spikes_from_templates(
606607
sub_recording, method="circus-omp-svd", method_kwargs=local_params, extra_outputs=True, **job_kwargs
607608
)
608-
local_params.update(
609-
{
610-
"overlaps": computed["overlaps"],
611-
"normed_templates": computed["normed_templates"],
612-
"norms": computed["norms"],
613-
"temporal": computed["temporal"],
614-
"spatial": computed["spatial"],
615-
"singular": computed["singular"],
616-
"units_overlaps": computed["units_overlaps"],
617-
"unit_overlaps_indices": computed["unit_overlaps_indices"],
618-
}
619-
)
609+
local_params["precomputed"] = more_outputs
620610
valid = (spikes["sample_index"] >= 0) * (spikes["sample_index"] < duration + 2 * margin)
621611

622612
if np.sum(valid) > 0:

src/spikeinterface/sortingcomponents/matching/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ def get_trace_margin(self):
2828
raise NotImplementedError
2929

3030
def compute(self, traces, start_frame, end_frame, segment_index, max_margin, *args):
31-
raise NotImplementedError
31+
raise NotImplementedError
32+
33+
def get_extra_outputs(self):
34+
# can be overwritten if need to ouput some variables with a dict
35+
return None

src/spikeinterface/sortingcomponents/matching/circus.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ class CircusOMPSVDPeeler(BaseTemplateMatching):
120120
of template temporal width)
121121
-----
122122
"""
123+
124+
_more_output_keys = [
125+
"norms",
126+
"temporal",
127+
"spatial",
128+
"singular",
129+
"units_overlaps",
130+
"unit_overlaps_indices",
131+
"normed_templates",
132+
]
133+
123134
def __init__(self, recording, return_output=True, parents=None,
124135
templates=None,
125136
amplitudes=[0.6, np.inf],
@@ -130,6 +141,7 @@ def __init__(self, recording, return_output=True, parents=None,
130141
rank=5,
131142
ignore_inds=[],
132143
vicinity=3,
144+
precomputed=None,
133145
):
134146

135147
BaseTemplateMatching.__init__(self, recording, templates, return_output=True, parents=None)
@@ -162,7 +174,12 @@ def __init__(self, recording, return_output=True, parents=None,
162174
# "unit_overlaps_indices",
163175
# ]:
164176
# assert d[key] is not None, "If templates are provided, %d should also be there" % key
165-
self._prepare_templates()
177+
if precomputed is None:
178+
self._prepare_templates()
179+
else:
180+
for key in self._more_output_keys:
181+
assert precomputed[key] is not None, "If templates are provided, %d should also be there" % key
182+
setattr(self, key, precomputed[key])
166183

167184

168185
self.ignore_inds = np.array(ignore_inds)
@@ -245,6 +262,14 @@ def _prepare_templates(self):
245262
self.temporal = np.moveaxis(self.temporal, [0, 1, 2], [1, 2, 0])
246263
self.singular = self.singular.T[:, :, np.newaxis]
247264

265+
def get_extra_outputs(self):
266+
output = {}
267+
for key in self._more_output_keys:
268+
output[key] = getattr(self, key)
269+
return output
270+
271+
272+
248273

249274
def get_trace_margin(self):
250275
return self.margin

src/spikeinterface/sortingcomponents/matching/main.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def find_spikes_from_templates(
2525
method_kwargs : dict, optional
2626
Keyword arguments for the chosen method
2727
extra_outputs : bool
28-
If True then method_kwargs is also returned
28+
If True then a dict is also returned is also returned
2929
**job_kwargs : dict
3030
Parameters for ChunkRecordingExecutor
3131
verbose : Bool, default: False
@@ -35,9 +35,8 @@ def find_spikes_from_templates(
3535
-------
3636
spikes : ndarray
3737
Spikes found from templates.
38-
method_kwargs:
38+
outputs:
3939
Optionaly returns for debug purpose.
40-
4140
"""
4241
from .method_list import matching_methods
4342

@@ -58,9 +57,8 @@ def find_spikes_from_templates(
5857
squeeze_output=True,
5958
)
6059
if extra_outputs:
61-
# TODO deprecated extra_outputs
62-
method_kwargs = {}
63-
return spikes, method_kwargs
60+
outputs = node0.get_extra_outputs()
61+
return spikes, outputs
6462
else:
6563
return spikes
6664

src/spikeinterface/sortingcomponents/tests/test_template_matching.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ def test_find_spikes_from_templates(method, sorting_analyzer):
5353
# }
5454

5555
method_kwargs.update(method_kwargs_all)
56-
spikes = find_spikes_from_templates(recording, method=method, method_kwargs=method_kwargs, **job_kwargs)
56+
spikes, info = find_spikes_from_templates(recording, method=method,
57+
method_kwargs=method_kwargs, extra_outputs=True, **job_kwargs)
58+
59+
# print(info)
5760

5861
# DEBUG = True
5962

@@ -66,7 +69,7 @@ def test_find_spikes_from_templates(method, sorting_analyzer):
6669

6770
# gt_sorting = sorting_analyzer.sorting
6871

69-
# sorting = NumpySorting.from_times_labels(spikes["sample_index"], spikes["cluster_index"], sampling_frequency)
72+
# sorting = NumpySorting.from_times_labels(spikes["sample_index"], spikes["cluster_index"], recording.sampling_frequency)
7073

7174
# ##metrics = si.compute_quality_metrics(sorting_analyzer, metric_names=["snr"])
7275

@@ -81,7 +84,7 @@ def test_find_spikes_from_templates(method, sorting_analyzer):
8184
sorting_analyzer = get_sorting_analyzer()
8285
# method = "naive"
8386
# method = "tdc-peeler"
84-
method = "circus"
85-
# method = "circus-omp-svd"
87+
# method = "circus"
88+
method = "circus-omp-svd"
8689
# method = "wobble"
8790
test_find_spikes_from_templates(method, sorting_analyzer)

0 commit comments

Comments
 (0)