From c410a52cca743f50ef53d4e31a1f779df99cbeea Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Thu, 29 Aug 2024 11:15:34 +0200 Subject: [PATCH 1/3] Add load_sorting_analyzer_or_waveforms function --- src/spikeinterface/core/__init__.py | 6 +++++- .../waveforms_extractor_backwards_compatibility.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/spikeinterface/core/__init__.py b/src/spikeinterface/core/__init__.py index 674f1ac463..ead7007920 100644 --- a/src/spikeinterface/core/__init__.py +++ b/src/spikeinterface/core/__init__.py @@ -166,4 +166,8 @@ # Important not for compatibility!! # This wil be uncommented after 0.100 -from .waveforms_extractor_backwards_compatibility import extract_waveforms, load_waveforms +from .waveforms_extractor_backwards_compatibility import ( + extract_waveforms, + load_waveforms, + load_sorting_analyzer_or_waveforms, +) diff --git a/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py b/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py index da1f5a71f5..c07bf57c4a 100644 --- a/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py +++ b/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py @@ -343,6 +343,16 @@ def get_template( return templates[0] +def load_sorting_analyzer_or_waveforms(folder, sorting=None): + folder = Path(folder) + if folder.suffix == ".zarr": + return load_sorting_analyzer(folder) + elif (folder / "spikeinterface_info.json").exists(): + return load_sorting_analyzer(folder) + else: + return load_waveforms(folder, sorting=sorting, output="SortingAnalyzer") + + def load_waveforms( folder, with_recording: bool = True, From 4d39df51c8b23e35e4f4e35b063f1daa0422b6ec Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Sat, 31 Aug 2024 10:07:43 +0200 Subject: [PATCH 2/3] Add docstring and API --- doc/api.rst | 13 +++++++++++++ ...waveforms_extractor_backwards_compatibility.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/doc/api.rst b/doc/api.rst index 42f9fec299..77ec895a97 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -73,6 +73,19 @@ Low-level .. autoclass:: ChunkRecordingExecutor + +Back-compatibility with ``WaveformExtraxctor`` (version < 0.101.0) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. automodule:: spikeinterface.core + :noindex: + + .. autofunction:: extract_waveforms + .. autofunction:: load_waveforms + .. autofunction:: load_sorting_analyzer_or_waveforms + + + spikeinterface.extractors ------------------------- diff --git a/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py b/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py index c07bf57c4a..749ec7c1f0 100644 --- a/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py +++ b/src/spikeinterface/core/waveforms_extractor_backwards_compatibility.py @@ -344,6 +344,21 @@ def get_template( def load_sorting_analyzer_or_waveforms(folder, sorting=None): + """ + Load a SortingAnalyzer from either a newly saved SortingAnalyzer folder or an old WaveformExtractor folder. + + Parameters + ---------- + folder: str | Path + The folder to the sorting analyzer or waveform extractor + sorting: BaseSorting | None, default: None + The sorting object to instantiate with the SortingAnalyzer (only used for old WaveformExtractor) + + Returns + ------- + sorting_analyzer: SortingAnalyzer + The returned SortingAnalyzer. + """ folder = Path(folder) if folder.suffix == ".zarr": return load_sorting_analyzer(folder) From 7501eda2fe8184817feebf6c9ec2df75d51e379f Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 2 Sep 2024 15:22:21 +0200 Subject: [PATCH 3/3] Update doc/api.rst Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- doc/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api.rst b/doc/api.rst index 77ec895a97..6bb9b39091 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -74,7 +74,7 @@ Low-level .. autoclass:: ChunkRecordingExecutor -Back-compatibility with ``WaveformExtraxctor`` (version < 0.101.0) +Back-compatibility with ``WaveformExtractor`` (version < 0.101.0) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. automodule:: spikeinterface.core