Skip to content

Commit cb7ffd6

Browse files
committed
Only load template_metrics on compute if propogating some metrics
1 parent 65d4b1e commit cb7ffd6

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/spikeinterface/core/sortinganalyzer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,19 +2033,18 @@ def load(cls, sorting_analyzer):
20332033
return None
20342034

20352035
def load_run_info(self):
2036+
run_info = None
20362037
if self.format == "binary_folder":
20372038
extension_folder = self._get_binary_extension_folder()
20382039
run_info_file = extension_folder / "run_info.json"
20392040
if run_info_file.is_file():
20402041
with open(str(run_info_file), "r") as f:
20412042
run_info = json.load(f)
2042-
else:
2043-
warnings.warn(f"Found no run_info file for {self.extension_name}, extension should be re-computed.")
2044-
run_info = None
20452043

20462044
elif self.format == "zarr":
20472045
extension_group = self._get_zarr_extension_group(mode="r")
20482046
run_info = extension_group.attrs.get("run_info", None)
2047+
20492048
if run_info is None:
20502049
warnings.warn(f"Found no run_info file for {self.extension_name}, extension should be re-computed.")
20512050
self.run_info = run_info

src/spikeinterface/postprocessing/template_metrics.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,18 @@ def _run(self, verbose=False):
335335
)
336336

337337
existing_metrics = []
338-
tm_extension = self.sorting_analyzer.get_extension("template_metrics")
339-
if (
340-
delete_existing_metrics is False
341-
and tm_extension is not None
342-
and tm_extension.data.get("metrics") is not None
343-
):
344-
existing_metrics = tm_extension.params["metric_names"]
338+
339+
# Check if we need to propogate any old metrics. If so, we'll do that.
340+
# Otherwise, we'll avoid attempting to load an empty template_metrics.
341+
if set(self.params["metrics_to_compute"]) != set(self.params["metric_names"]):
342+
343+
tm_extension = self.sorting_analyzer.get_extension("template_metrics")
344+
if (
345+
delete_existing_metrics is False
346+
and tm_extension is not None
347+
and tm_extension.data.get("metrics") is not None
348+
):
349+
existing_metrics = tm_extension.params["metric_names"]
345350

346351
# append the metrics which were previously computed
347352
for metric_name in set(existing_metrics).difference(metrics_to_compute):

0 commit comments

Comments
 (0)