diff --git a/src/spikeinterface/core/base.py b/src/spikeinterface/core/base.py index 5800166f39..304a85e74f 100644 --- a/src/spikeinterface/core/base.py +++ b/src/spikeinterface/core/base.py @@ -7,7 +7,6 @@ import weakref import json import pickle -import os import random import string from packaging.version import parse @@ -928,13 +927,14 @@ def save_to_folder( folder.mkdir(parents=True, exist_ok=False) # dump provenance - provenance_file = folder / f"provenance.json" if self.check_serializability("json"): + provenance_file = folder / f"provenance.json" + self.dump(provenance_file) + elif self.check_serializability("pickle"): + provenance_file = folder / f"provenance.pkl" self.dump(provenance_file) else: - provenance_file.write_text( - json.dumps({"warning": "the provenace is not json serializable!!!"}), encoding="utf8" - ) + warnings.warn("The extractor is not serializable to file. The provenance will not be saved.") self.save_metadata_to_folder(folder) @@ -1001,7 +1001,6 @@ def save_to_zarr( cached: ZarrExtractor Saved copy of the extractor. """ - import zarr from .zarrextractors import read_zarr save_kwargs.pop("format", None) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 11909bce0e..4e265f3766 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1738,6 +1738,8 @@ def __init__( ) self.add_recording_segment(recording_segment) + # to discuss: maybe we could set json serializability to False always + # because templates could be large! if not sorting.check_serializability("json"): self._serializability["json"] = False if parent_recording is not None: diff --git a/src/spikeinterface/generation/drift_tools.py b/src/spikeinterface/generation/drift_tools.py index cce2e08b58..70e13160f4 100644 --- a/src/spikeinterface/generation/drift_tools.py +++ b/src/spikeinterface/generation/drift_tools.py @@ -458,6 +458,9 @@ def __init__( self.set_probe(drifting_templates.probe, in_place=True) + # templates are too large, we don't serialize them to JSON + self._serializability["json"] = False + self._kwargs = { "sorting": sorting, "drifting_templates": drifting_templates,