Skip to content

Commit 9817050

Browse files
authored
Add template_operator to template metrics backwards compatibility (#4714)
1 parent a5f7dbb commit 9817050

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/spikeinterface/metrics/template/template_metrics.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,18 @@ def _handle_backward_compatibility_on_load(self):
176176
if "peaks_data" not in self.data:
177177
self.tmp_data_to_save = []
178178

179+
# We used to use whichever `template_operator` was available in the template computation, but now the user
180+
# can specify. Default to "average" unless the only computed templates were computed with median.
181+
if "template_operator" not in self.params:
182+
self.params["template_operator"] = "average"
183+
if self.sorting_analyzer.has_extension("templates"):
184+
available_template_keys = self.sorting_analyzer.get_extension("templates").data.keys()
185+
template_keys_which_are_operators = [
186+
key for key in available_template_keys if key in ["average", "median"]
187+
]
188+
if len(template_keys_which_are_operators) == 1:
189+
self.params["template_operator"] = template_keys_which_are_operators[0]
190+
179191
def _set_params(
180192
self,
181193
metric_names: list[str] | None = None,

0 commit comments

Comments
 (0)