Skip to content

Commit

Permalink
Merge pull request #3478 from chrishalcrow/fix_tm_check
Browse files Browse the repository at this point in the history
Only load `template_metrics` extension on compute if keeping some metrics
  • Loading branch information
alejoe91 authored Jan 31, 2025
2 parents f5a50c8 + cedabd9 commit 12a1276
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/spikeinterface/core/sortinganalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2033,19 +2033,18 @@ def load(cls, sorting_analyzer):
return None

def load_run_info(self):
run_info = None
if self.format == "binary_folder":
extension_folder = self._get_binary_extension_folder()
run_info_file = extension_folder / "run_info.json"
if run_info_file.is_file():
with open(str(run_info_file), "r") as f:
run_info = json.load(f)
else:
warnings.warn(f"Found no run_info file for {self.extension_name}, extension should be re-computed.")
run_info = None

elif self.format == "zarr":
extension_group = self._get_zarr_extension_group(mode="r")
run_info = extension_group.attrs.get("run_info", None)

if run_info is None:
warnings.warn(f"Found no run_info file for {self.extension_name}, extension should be re-computed.")
self.run_info = run_info
Expand Down
19 changes: 12 additions & 7 deletions src/spikeinterface/postprocessing/template_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,18 @@ def _run(self, verbose=False):
)

existing_metrics = []
tm_extension = self.sorting_analyzer.get_extension("template_metrics")
if (
delete_existing_metrics is False
and tm_extension is not None
and tm_extension.data.get("metrics") is not None
):
existing_metrics = tm_extension.params["metric_names"]

# Check if we need to propogate any old metrics. If so, we'll do that.
# Otherwise, we'll avoid attempting to load an empty template_metrics.
if set(self.params["metrics_to_compute"]) != set(self.params["metric_names"]):

tm_extension = self.sorting_analyzer.get_extension("template_metrics")
if (
delete_existing_metrics is False
and tm_extension is not None
and tm_extension.data.get("metrics") is not None
):
existing_metrics = tm_extension.params["metric_names"]

existing_metrics = []
# here we get in the loaded via the dict only (to avoid full loading from disk after params reset)
Expand Down

0 comments on commit 12a1276

Please sign in to comment.