From a97a1f056fd2eb95c75bbfb97535e7c698a6981f Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Fri, 5 Jul 2024 09:56:44 +0200 Subject: [PATCH 1/2] Remove unused legacy class name/mode from extractors --- src/spikeinterface/core/binaryfolder.py | 3 -- .../core/binaryrecordingextractor.py | 3 -- .../core/npzsortingextractor.py | 3 -- src/spikeinterface/core/numpyextractors.py | 8 --- src/spikeinterface/core/zarrextractors.py | 12 ----- .../extractors/alfsortingextractor.py | 3 +- src/spikeinterface/extractors/cbin_ibl.py | 4 +- .../cellexplorersortingextractor.py | 1 - .../extractors/combinatoextractors.py | 14 ++---- .../extractors/extractorlist.py | 49 ------------------- .../extractors/hdsortextractors.py | 3 -- .../extractors/herdingspikesextractors.py | 19 ++----- .../extractors/iblextractors.py | 3 -- .../extractors/klustaextractors.py | 20 ++------ .../extractors/mclustextractors.py | 2 - .../extractors/mcsh5extractors.py | 8 +-- .../extractors/mdaextractors.py | 6 --- .../extractors/neoextractors/alphaomega.py | 2 - .../extractors/neoextractors/axona.py | 2 - .../extractors/neoextractors/biocam.py | 4 -- .../extractors/neoextractors/blackrock.py | 4 -- .../extractors/neoextractors/ced.py | 2 - .../extractors/neoextractors/edf.py | 2 - .../extractors/neoextractors/intan.py | 2 - .../extractors/neoextractors/maxwell.py | 4 -- .../extractors/neoextractors/mcsraw.py | 2 - .../extractors/neoextractors/mearec.py | 4 -- .../extractors/neoextractors/neuralynx.py | 4 -- .../extractors/neoextractors/neuroexplorer.py | 2 - .../extractors/neoextractors/neuroscope.py | 4 -- .../extractors/neoextractors/nix.py | 2 - .../extractors/neoextractors/openephys.py | 6 --- .../extractors/neoextractors/plexon.py | 4 -- .../extractors/neoextractors/plexon2.py | 6 --- .../extractors/neoextractors/spike2.py | 2 - .../extractors/neoextractors/spikegadgets.py | 2 - .../extractors/neoextractors/spikeglx.py | 4 -- .../extractors/neoextractors/tdt.py | 2 - .../extractors/nwbextractors.py | 4 -- .../extractors/phykilosortextractors.py | 13 +---- .../extractors/shybridextractors.py | 23 ++------- .../extractors/sinapsrecordingextractors.py | 8 --- .../extractors/spykingcircusextractors.py | 15 ++---- .../extractors/tridesclousextractors.py | 2 - .../extractors/waveclussnippetstextractors.py | 1 - .../extractors/waveclustextractors.py | 2 - .../extractors/yassextractors.py | 19 ++----- 47 files changed, 32 insertions(+), 282 deletions(-) diff --git a/src/spikeinterface/core/binaryfolder.py b/src/spikeinterface/core/binaryfolder.py index fca08d9c26..86f14faa30 100644 --- a/src/spikeinterface/core/binaryfolder.py +++ b/src/spikeinterface/core/binaryfolder.py @@ -25,9 +25,6 @@ class BinaryFolderRecording(BinaryRecordingExtractor): The recording """ - mode = "folder" - name = "binaryfolder" - def __init__(self, folder_path): folder_path = Path(folder_path) diff --git a/src/spikeinterface/core/binaryrecordingextractor.py b/src/spikeinterface/core/binaryrecordingextractor.py index 64c1b9b2e6..84d06a599f 100644 --- a/src/spikeinterface/core/binaryrecordingextractor.py +++ b/src/spikeinterface/core/binaryrecordingextractor.py @@ -52,9 +52,6 @@ class BinaryRecordingExtractor(BaseRecording): The recording Extractor """ - mode = "file" - name = "binary" - def __init__( self, file_paths, diff --git a/src/spikeinterface/core/npzsortingextractor.py b/src/spikeinterface/core/npzsortingextractor.py index f60dadd8ec..b8e7357e8c 100644 --- a/src/spikeinterface/core/npzsortingextractor.py +++ b/src/spikeinterface/core/npzsortingextractor.py @@ -16,9 +16,6 @@ class NpzSortingExtractor(BaseSorting): All spike are store in two columns maner index+labels """ - mode = "file" - name = "npz" - def __init__(self, file_path): self.npz_filename = file_path diff --git a/src/spikeinterface/core/numpyextractors.py b/src/spikeinterface/core/numpyextractors.py index 1ee472ffa4..09ba743a8c 100644 --- a/src/spikeinterface/core/numpyextractors.py +++ b/src/spikeinterface/core/numpyextractors.py @@ -37,9 +37,6 @@ class NumpyRecording(BaseRecording): An optional list of channel_ids. If None, linear channels are assumed """ - mode = "memory" - name = "numpy" - def __init__(self, traces_list, sampling_frequency, t_starts=None, channel_ids=None): if isinstance(traces_list, list): all_elements_are_list = all(isinstance(e, list) for e in traces_list) @@ -142,9 +139,6 @@ class SharedMemoryRecording(BaseRecording): If True, the main instance will unlink the sharedmem buffer when deleted """ - mode = "memory" - name = "SharedMemory" - def __init__( self, shm_names, shape_list, dtype, sampling_frequency, channel_ids=None, t_starts=None, main_shm_owner=True ): @@ -252,8 +246,6 @@ class NumpySorting(BaseSorting): A list of unit_ids. """ - name = "numpy" - def __init__(self, spikes, sampling_frequency, unit_ids): """ """ BaseSorting.__init__(self, sampling_frequency, unit_ids) diff --git a/src/spikeinterface/core/zarrextractors.py b/src/spikeinterface/core/zarrextractors.py index 4851c0eb5c..1b9637e097 100644 --- a/src/spikeinterface/core/zarrextractors.py +++ b/src/spikeinterface/core/zarrextractors.py @@ -31,13 +31,7 @@ class ZarrRecordingExtractor(BaseRecording): The recording Extractor """ - installed = True - mode = "folder" - installation_mesg = "" - name = "zarr" - def __init__(self, folder_path: Path | str, storage_options: dict | None = None): - assert self.installed, self.installation_mesg folder_path, folder_path_kwarg = resolve_zarr_path(folder_path) @@ -167,13 +161,7 @@ class ZarrSortingExtractor(BaseSorting): The sorting Extractor """ - installed = True - mode = "folder" - installation_mesg = "" - name = "zarr" - def __init__(self, folder_path: Path | str, storage_options: dict | None = None, zarr_group: str | None = None): - assert self.installed, self.installation_mesg folder_path, folder_path_kwarg = resolve_zarr_path(folder_path) diff --git a/src/spikeinterface/extractors/alfsortingextractor.py b/src/spikeinterface/extractors/alfsortingextractor.py index fa6490135c..f7b5401182 100644 --- a/src/spikeinterface/extractors/alfsortingextractor.py +++ b/src/spikeinterface/extractors/alfsortingextractor.py @@ -25,12 +25,11 @@ class ALFSortingExtractor(BaseSorting): """ installation_mesg = "To use the ALF extractors, install ONE-api: \n\n pip install ONE-api\n\n" - name = "alf" def __init__(self, folder_path, sampling_frequency=30000): try: import one.alf.io as alfio - except ImportError as e: + except ImportError: raise ImportError(self.installation_mesg) self._folder_path = Path(folder_path) diff --git a/src/spikeinterface/extractors/cbin_ibl.py b/src/spikeinterface/extractors/cbin_ibl.py index a09cea9863..d7e5b58e11 100644 --- a/src/spikeinterface/extractors/cbin_ibl.py +++ b/src/spikeinterface/extractors/cbin_ibl.py @@ -39,16 +39,14 @@ class CompressedBinaryIblExtractor(BaseRecording): The loaded data. """ - mode = "folder" installation_mesg = "To use the CompressedBinaryIblExtractor, install mtscomp: \n\n pip install mtscomp\n\n" - name = "cbin_ibl" def __init__(self, folder_path=None, load_sync_channel=False, stream_name="ap", cbin_file=None): from neo.rawio.spikeglxrawio import read_meta_file try: import mtscomp - except: + except ImportError: raise ImportError(self.installation_mesg) if cbin_file is None: folder_path = Path(folder_path) diff --git a/src/spikeinterface/extractors/cellexplorersortingextractor.py b/src/spikeinterface/extractors/cellexplorersortingextractor.py index 736927a1ee..0dfa3a85ad 100644 --- a/src/spikeinterface/extractors/cellexplorersortingextractor.py +++ b/src/spikeinterface/extractors/cellexplorersortingextractor.py @@ -29,7 +29,6 @@ class CellExplorerSortingExtractor(BaseSorting): Path to the `sessionInfo.mat` file. If None, it will be inferred from the file_path. """ - mode = "file" installation_mesg = "To use the CellExplorerSortingExtractor install pymatreader" def __init__( diff --git a/src/spikeinterface/extractors/combinatoextractors.py b/src/spikeinterface/extractors/combinatoextractors.py index 8828ea8b64..35fce3a8e3 100644 --- a/src/spikeinterface/extractors/combinatoextractors.py +++ b/src/spikeinterface/extractors/combinatoextractors.py @@ -7,13 +7,6 @@ from spikeinterface.core import BaseSorting, BaseSortingSegment from spikeinterface.core.core_tools import define_function_from_class -try: - import h5py - - HAVE_H5PY = True -except ImportError: - HAVE_H5PY = False - class CombinatoSortingExtractor(BaseSorting): """Load Combinato format data as a sorting extractor. @@ -37,11 +30,14 @@ class CombinatoSortingExtractor(BaseSorting): The loaded data. """ - installed = HAVE_H5PY installation_mesg = "To use the CombinatoSortingExtractor install h5py: \n\n pip install h5py\n\n" - name = "combinato" def __init__(self, folder_path, sampling_frequency=None, user="simple", det_sign="both", keep_good_only=True): + try: + import h5py + except ImportError: + raise ImportError(self.installation_mesg) + folder_path = Path(folder_path) assert folder_path.is_dir(), "Folder {} doesn't exist".format(folder_path) if sampling_frequency is None: diff --git a/src/spikeinterface/extractors/extractorlist.py b/src/spikeinterface/extractors/extractorlist.py index 8948aad606..e56d4fff52 100644 --- a/src/spikeinterface/extractors/extractorlist.py +++ b/src/spikeinterface/extractors/extractorlist.py @@ -116,52 +116,3 @@ event_extractor_full_list += neo_event_extractors_list snippets_extractor_full_list = [NpySnippetsExtractor, WaveClusSnippetsExtractor] - - -recording_extractor_full_dict = {recext.name: recext for recext in recording_extractor_full_list} -sorting_extractor_full_dict = {recext.name: recext for recext in sorting_extractor_full_list} -snippets_extractor_full_dict = {recext.name: recext for recext in snippets_extractor_full_list} - - -def get_recording_extractor_from_name(name: str) -> Type[BaseRecording]: - """ - Returns the Recording Extractor class based on its name. - - Parameters - ---------- - name: str - The Recording Extractor's name. - - Returns - ------- - recording_extractor: BaseRecording - The Recording Extractor class. - """ - - for recording_extractor in recording_extractor_full_list: - if recording_extractor.__name__ == name: - return recording_extractor - - raise ValueError(f"Recording extractor '{name}' not found.") - - -def get_sorting_extractor_from_name(name: str) -> Type[BaseSorting]: - """ - Returns the Sorting Extractor class based on its name. - - Parameters - ---------- - name: str - The Sorting Extractor's name. - - Returns - ------- - sorting_extractor: BaseSorting - The Sorting Extractor class. - """ - - for sorting_extractor in sorting_extractor_full_list: - if sorting_extractor.__name__ == name: - return sorting_extractor - - raise ValueError(f"Sorting extractor '{name}' not found.") diff --git a/src/spikeinterface/extractors/hdsortextractors.py b/src/spikeinterface/extractors/hdsortextractors.py index 19038344ee..fa627d2ee3 100644 --- a/src/spikeinterface/extractors/hdsortextractors.py +++ b/src/spikeinterface/extractors/hdsortextractors.py @@ -25,9 +25,6 @@ class HDSortSortingExtractor(MatlabHelper, BaseSorting): The loaded data. """ - mode = "file" - name = "hdsort" - def __init__(self, file_path, keep_good_only=True): MatlabHelper.__init__(self, file_path) diff --git a/src/spikeinterface/extractors/herdingspikesextractors.py b/src/spikeinterface/extractors/herdingspikesextractors.py index 4fe915a96b..de4929218b 100644 --- a/src/spikeinterface/extractors/herdingspikesextractors.py +++ b/src/spikeinterface/extractors/herdingspikesextractors.py @@ -7,13 +7,6 @@ from spikeinterface.core import BaseSorting, BaseSortingSegment from spikeinterface.core.core_tools import define_function_from_class -try: - import h5py - - HAVE_HS2SX = True -except ImportError: - HAVE_HS2SX = False - class HerdingspikesSortingExtractor(BaseSorting): """Load HerdingSpikes format data as a sorting extractor. @@ -31,15 +24,13 @@ class HerdingspikesSortingExtractor(BaseSorting): The loaded data. """ - installed = HAVE_HS2SX # check at class level if installed or not - mode = "file" - installation_mesg = ( - "To use the HS2SortingExtractor install h5py: \n\n pip install h5py\n\n" # error message when not installed - ) - name = "herdingspikes" + installation_mesg = "To use the HS2SortingExtractor install h5py: \n\n pip install h5py\n\n" def __init__(self, file_path, load_unit_info=True): - assert self.installed, self.installation_mesg + try: + import h5py + except ImportError: + raise ImportError(self.installation_mesg) self._recording_file = file_path self._rf = h5py.File(self._recording_file, mode="r") diff --git a/src/spikeinterface/extractors/iblextractors.py b/src/spikeinterface/extractors/iblextractors.py index 34481c94f1..5dd549347d 100644 --- a/src/spikeinterface/extractors/iblextractors.py +++ b/src/spikeinterface/extractors/iblextractors.py @@ -65,9 +65,7 @@ class IblRecordingExtractor(BaseRecording): The recording extractor which allows access to the traces. """ - mode = "folder" installation_mesg = "To use the IblRecordingSegment, install ibllib: \n\n pip install ONE-api\npip install ibllib\n" - name = "ibl_recording" @staticmethod def _get_default_one(cache_folder: Optional[Union[Path, str]] = None): @@ -304,7 +302,6 @@ class IblSortingExtractor(BaseSorting): The loaded data. """ - name = "ibl" installation_mesg = "IBL extractors require ibllib as a dependency." " To install, run: \n\n pip install ibllib\n\n" def __init__(self, pid: str, good_clusters_only: bool = False, load_unit_properties: bool = True, one=None): diff --git a/src/spikeinterface/extractors/klustaextractors.py b/src/spikeinterface/extractors/klustaextractors.py index 82534771a1..162376cb3c 100644 --- a/src/spikeinterface/extractors/klustaextractors.py +++ b/src/spikeinterface/extractors/klustaextractors.py @@ -18,13 +18,6 @@ from spikeinterface.core import BaseRecording, BaseSorting, BaseRecordingSegment, BaseSortingSegment, read_python from spikeinterface.core.core_tools import define_function_from_class -try: - import h5py - - HAVE_H5PY = True -except ImportError: - HAVE_H5PY = False - # noinspection SpellCheckingInspection class KlustaSortingExtractor(BaseSorting): @@ -43,18 +36,15 @@ class KlustaSortingExtractor(BaseSorting): The loaded data. """ - installed = HAVE_H5PY # check at class level if installed or not - installation_mesg = ( - "To use the KlustaSortingExtractor install h5py: \n\n pip install h5py\n\n" # error message when not installed - ) - mode = "file_or_folder" - name = "klusta" + installation_mesg = "To use the KlustaSortingExtractor install h5py: \n\n pip install h5py\n\n" default_cluster_groups = {0: "Noise", 1: "MUA", 2: "Good", 3: "Unsorted"} def __init__(self, file_or_folder_path, exclude_cluster_groups=None): - assert HAVE_H5PY, self.installation_mesg - # ~ SortingExtractor.__init__(self) + try: + import h5py + except ImportError: + raise ImportError(self.installation_mesg) kwik_file_or_folder = Path(file_or_folder_path) kwikfile = None diff --git a/src/spikeinterface/extractors/mclustextractors.py b/src/spikeinterface/extractors/mclustextractors.py index 5cfa583054..d611a1576a 100644 --- a/src/spikeinterface/extractors/mclustextractors.py +++ b/src/spikeinterface/extractors/mclustextractors.py @@ -29,8 +29,6 @@ class MClustSortingExtractor(BaseSorting): Loaded data. """ - name = "mclust" - def __init__(self, folder_path, sampling_frequency, sampling_frequency_raw=None): end_header_str = "%%ENDHEADER" ext_list = ["t64", "t32", "t", "raw64", "raw32"] diff --git a/src/spikeinterface/extractors/mcsh5extractors.py b/src/spikeinterface/extractors/mcsh5extractors.py index f419b7e64d..d86969e005 100644 --- a/src/spikeinterface/extractors/mcsh5extractors.py +++ b/src/spikeinterface/extractors/mcsh5extractors.py @@ -24,18 +24,12 @@ class MCSH5RecordingExtractor(BaseRecording): The loaded data. """ - mode = "file" - installation_mesg = ( - "To use the MCSH5RecordingExtractor install h5py: \n\n pip install h5py\n\n" # error message when not installed - ) - name = "mcsh5" + installation_mesg = "To use the MCSH5RecordingExtractor install h5py: \n\n pip install h5py\n\n" def __init__(self, file_path, stream_id=0): try: import h5py - - HAVE_MCSH5 = True except ImportError: raise ImportError(self.installation_mesg) diff --git a/src/spikeinterface/extractors/mdaextractors.py b/src/spikeinterface/extractors/mdaextractors.py index acc7be58dd..f055e1d7c9 100644 --- a/src/spikeinterface/extractors/mdaextractors.py +++ b/src/spikeinterface/extractors/mdaextractors.py @@ -36,9 +36,6 @@ class MdaRecordingExtractor(BaseRecording): The loaded data. """ - mode = "folder" - name = "mda" - def __init__(self, folder_path, raw_fname="raw.mda", params_fname="params.json", geom_fname="geom.csv"): folder_path = Path(folder_path) self._folder_path = folder_path @@ -192,9 +189,6 @@ class MdaSortingExtractor(BaseSorting): The loaded data. """ - mode = "file" - name = "mda" - def __init__(self, file_path, sampling_frequency): firings = readmda(str(Path(file_path).absolute())) labels = firings[2, :] diff --git a/src/spikeinterface/extractors/neoextractors/alphaomega.py b/src/spikeinterface/extractors/neoextractors/alphaomega.py index 239928f66d..2e70d5ba41 100644 --- a/src/spikeinterface/extractors/neoextractors/alphaomega.py +++ b/src/spikeinterface/extractors/neoextractors/alphaomega.py @@ -27,9 +27,7 @@ class AlphaOmegaRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "folder" NeoRawIOClass = "AlphaOmegaRawIO" - name = "alphaomega" def __init__(self, folder_path, lsx_files=None, stream_id="RAW", stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(folder_path, lsx_files) diff --git a/src/spikeinterface/extractors/neoextractors/axona.py b/src/spikeinterface/extractors/neoextractors/axona.py index 71e1277946..e086cb5dde 100644 --- a/src/spikeinterface/extractors/neoextractors/axona.py +++ b/src/spikeinterface/extractors/neoextractors/axona.py @@ -21,9 +21,7 @@ class AxonaRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "folder" NeoRawIOClass = "AxonaRawIO" - name = "axona" def __init__(self, file_path, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/biocam.py b/src/spikeinterface/extractors/neoextractors/biocam.py index 9f23575dba..15953ff6d7 100644 --- a/src/spikeinterface/extractors/neoextractors/biocam.py +++ b/src/spikeinterface/extractors/neoextractors/biocam.py @@ -31,10 +31,6 @@ class BiocamRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" - NeoRawIOClass = "BiocamRawIO" - name = "biocam" - def __init__( self, file_path, diff --git a/src/spikeinterface/extractors/neoextractors/blackrock.py b/src/spikeinterface/extractors/neoextractors/blackrock.py index ab3710e05e..9bd2b05f24 100644 --- a/src/spikeinterface/extractors/neoextractors/blackrock.py +++ b/src/spikeinterface/extractors/neoextractors/blackrock.py @@ -31,9 +31,7 @@ class BlackrockRecordingExtractor(NeoBaseRecordingExtractor): """ - mode = "file" NeoRawIOClass = "BlackrockRawIO" - name = "blackrock" def __init__( self, @@ -87,10 +85,8 @@ class BlackrockSortingExtractor(NeoBaseSortingExtractor): Used to extract information about the sampling frequency and t_start from the analog signal if provided. """ - mode = "file" NeoRawIOClass = "BlackrockRawIO" neo_returns_frames = False - name = "blackrock" def __init__( self, diff --git a/src/spikeinterface/extractors/neoextractors/ced.py b/src/spikeinterface/extractors/neoextractors/ced.py index e2c79478fa..73a783ec5d 100644 --- a/src/spikeinterface/extractors/neoextractors/ced.py +++ b/src/spikeinterface/extractors/neoextractors/ced.py @@ -27,9 +27,7 @@ class CedRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "CedRawIO" - name = "ced" def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/edf.py b/src/spikeinterface/extractors/neoextractors/edf.py index 90627d5772..8369369922 100644 --- a/src/spikeinterface/extractors/neoextractors/edf.py +++ b/src/spikeinterface/extractors/neoextractors/edf.py @@ -26,9 +26,7 @@ class EDFRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "EDFRawIO" - name = "edf" def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = {"filename": str(file_path)} diff --git a/src/spikeinterface/extractors/neoextractors/intan.py b/src/spikeinterface/extractors/neoextractors/intan.py index 43439b80c9..34c8bf2eb5 100644 --- a/src/spikeinterface/extractors/neoextractors/intan.py +++ b/src/spikeinterface/extractors/neoextractors/intan.py @@ -33,9 +33,7 @@ class IntanRecordingExtractor(NeoBaseRecordingExtractor): """ - mode = "file" NeoRawIOClass = "IntanRawIO" - name = "intan" def __init__( self, diff --git a/src/spikeinterface/extractors/neoextractors/maxwell.py b/src/spikeinterface/extractors/neoextractors/maxwell.py index a66075b451..6c72696e16 100644 --- a/src/spikeinterface/extractors/neoextractors/maxwell.py +++ b/src/spikeinterface/extractors/neoextractors/maxwell.py @@ -39,9 +39,7 @@ class MaxwellRecordingExtractor(NeoBaseRecordingExtractor): If there are several blocks (experiments), specify the block index you want to load """ - mode = "file" NeoRawIOClass = "MaxwellRawIO" - name = "maxwell" def __init__( self, @@ -96,8 +94,6 @@ class MaxwellEventExtractor(BaseEvent): Class for reading TTL events from Maxwell files. """ - name = "maxwell" - def __init__(self, file_path): import h5py diff --git a/src/spikeinterface/extractors/neoextractors/mcsraw.py b/src/spikeinterface/extractors/neoextractors/mcsraw.py index 0cbd9263ba..307a6c1fba 100644 --- a/src/spikeinterface/extractors/neoextractors/mcsraw.py +++ b/src/spikeinterface/extractors/neoextractors/mcsraw.py @@ -30,9 +30,7 @@ class MCSRawRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "RawMCSRawIO" - name = "mcsraw" def __init__(self, file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/mearec.py b/src/spikeinterface/extractors/neoextractors/mearec.py index 76f0b29f54..21a597029b 100644 --- a/src/spikeinterface/extractors/neoextractors/mearec.py +++ b/src/spikeinterface/extractors/neoextractors/mearec.py @@ -40,9 +40,7 @@ class MEArecRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "MEArecRawIO" - name = "mearec" def __init__(self, file_path: Union[str, Path], all_annotations: bool = False): neo_kwargs = self.map_to_neo_kwargs(file_path) @@ -75,10 +73,8 @@ def map_to_neo_kwargs( class MEArecSortingExtractor(NeoBaseSortingExtractor): - mode = "file" NeoRawIOClass = "MEArecRawIO" neo_returns_frames = False - name = "mearec" def __init__(self, file_path: Union[str, Path]): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/neuralynx.py b/src/spikeinterface/extractors/neoextractors/neuralynx.py index 0670371ba9..98f4a7c2ff 100644 --- a/src/spikeinterface/extractors/neoextractors/neuralynx.py +++ b/src/spikeinterface/extractors/neoextractors/neuralynx.py @@ -40,9 +40,7 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): Note that here the default is False contrary to neo. """ - mode = "folder" NeoRawIOClass = "NeuralynxRawIO" - name = "neuralynx" def __init__( self, @@ -90,11 +88,9 @@ class NeuralynxSortingExtractor(NeoBaseSortingExtractor): Used to extract information about the sampling frequency and t_start from the analog signal if provided. """ - mode = "folder" NeoRawIOClass = "NeuralynxRawIO" neo_returns_frames = True need_t_start_from_signal_stream = True - name = "neuralynx" def __init__( self, diff --git a/src/spikeinterface/extractors/neoextractors/neuroexplorer.py b/src/spikeinterface/extractors/neoextractors/neuroexplorer.py index 49784418e1..ac569c0df0 100644 --- a/src/spikeinterface/extractors/neoextractors/neuroexplorer.py +++ b/src/spikeinterface/extractors/neoextractors/neuroexplorer.py @@ -47,9 +47,7 @@ class NeuroExplorerRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "NeuroExplorerRawIO" - name = "neuroexplorer" def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = {"filename": str(file_path)} diff --git a/src/spikeinterface/extractors/neoextractors/neuroscope.py b/src/spikeinterface/extractors/neoextractors/neuroscope.py index 104f47af24..6c6f1d4bea 100644 --- a/src/spikeinterface/extractors/neoextractors/neuroscope.py +++ b/src/spikeinterface/extractors/neoextractors/neuroscope.py @@ -37,9 +37,7 @@ class NeuroScopeRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "NeuroScopeRawIO" - name = "neuroscope" def __init__(self, file_path, xml_file_path=None, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path, xml_file_path) @@ -103,8 +101,6 @@ class NeuroScopeSortingExtractor(BaseSorting): Path to the .xml file referenced by this sorting. """ - name = "neuroscope" - def __init__( self, folder_path: OptionalPathType = None, diff --git a/src/spikeinterface/extractors/neoextractors/nix.py b/src/spikeinterface/extractors/neoextractors/nix.py index 00e5f8bfc1..b869936fa3 100644 --- a/src/spikeinterface/extractors/neoextractors/nix.py +++ b/src/spikeinterface/extractors/neoextractors/nix.py @@ -27,9 +27,7 @@ class NixRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "NIXRawIO" - name = "nix" def __init__(self, file_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/openephys.py b/src/spikeinterface/extractors/neoextractors/openephys.py index f3363b9013..04c25998f0 100644 --- a/src/spikeinterface/extractors/neoextractors/openephys.py +++ b/src/spikeinterface/extractors/neoextractors/openephys.py @@ -64,9 +64,7 @@ class OpenEphysLegacyRecordingExtractor(NeoBaseRecordingExtractor): neo.OpenEphysRawIO is now handling gaps directly but makes the read slower. """ - mode = "folder" NeoRawIOClass = "OpenEphysRawIO" - name = "openephyslegacy" def __init__( self, @@ -138,9 +136,7 @@ class OpenEphysBinaryRecordingExtractor(NeoBaseRecordingExtractor): """ - mode = "folder" NeoRawIOClass = "OpenEphysBinaryRawIO" - name = "openephys" def __init__( self, @@ -287,9 +283,7 @@ class OpenEphysBinaryEventExtractor(NeoBaseEventExtractor): """ - mode = "folder" NeoRawIOClass = "OpenEphysBinaryRawIO" - name = "openephys" def __init__(self, folder_path, block_index=None): neo_kwargs = self.map_to_neo_kwargs(folder_path) diff --git a/src/spikeinterface/extractors/neoextractors/plexon.py b/src/spikeinterface/extractors/neoextractors/plexon.py index cf08778ffa..9c2586dd5a 100644 --- a/src/spikeinterface/extractors/neoextractors/plexon.py +++ b/src/spikeinterface/extractors/neoextractors/plexon.py @@ -25,9 +25,7 @@ class PlexonRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "PlexonRawIO" - name = "plexon" def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) @@ -54,9 +52,7 @@ class PlexonSortingExtractor(NeoBaseSortingExtractor): The file path to load the recordings from. """ - mode = "file" NeoRawIOClass = "PlexonRawIO" - name = "plexon" neo_returns_frames = True def __init__(self, file_path): diff --git a/src/spikeinterface/extractors/neoextractors/plexon2.py b/src/spikeinterface/extractors/neoextractors/plexon2.py index 6c9160f13b..4434d02cc1 100644 --- a/src/spikeinterface/extractors/neoextractors/plexon2.py +++ b/src/spikeinterface/extractors/neoextractors/plexon2.py @@ -30,9 +30,7 @@ class Plexon2RecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "Plexon2RawIO" - name = "plexon2" def __init__(self, file_path, stream_id=None, stream_name=None, use_names_as_ids=True, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) @@ -66,10 +64,8 @@ class Plexon2SortingExtractor(NeoBaseSortingExtractor): The sampling frequency of the sorting (required for multiple streams with different sampling frequencies). """ - mode = "file" NeoRawIOClass = "Plexon2RawIO" neo_returns_frames = True - name = "plexon2" def __init__(self, file_path, sampling_frequency=None): from neo.rawio import Plexon2RawIO @@ -98,9 +94,7 @@ class Plexon2EventExtractor(NeoBaseEventExtractor): """ - mode = "file" NeoRawIOClass = "Plexon2RawIO" - name = "plexon2" def __init__(self, folder_path, block_index=None): neo_kwargs = self.map_to_neo_kwargs(folder_path) diff --git a/src/spikeinterface/extractors/neoextractors/spike2.py b/src/spikeinterface/extractors/neoextractors/spike2.py index 1bd0351553..cbc1db3f74 100644 --- a/src/spikeinterface/extractors/neoextractors/spike2.py +++ b/src/spikeinterface/extractors/neoextractors/spike2.py @@ -26,9 +26,7 @@ class Spike2RecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "Spike2RawIO" - name = "spike2" def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/spikegadgets.py b/src/spikeinterface/extractors/neoextractors/spikegadgets.py index 3d57817f88..e7c31b8afa 100644 --- a/src/spikeinterface/extractors/neoextractors/spikegadgets.py +++ b/src/spikeinterface/extractors/neoextractors/spikegadgets.py @@ -28,9 +28,7 @@ class SpikeGadgetsRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "file" NeoRawIOClass = "SpikeGadgetsRawIO" - name = "spikegadgets" def __init__(self, file_path, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(file_path) diff --git a/src/spikeinterface/extractors/neoextractors/spikeglx.py b/src/spikeinterface/extractors/neoextractors/spikeglx.py index adfd0f702e..10a1f78265 100644 --- a/src/spikeinterface/extractors/neoextractors/spikeglx.py +++ b/src/spikeinterface/extractors/neoextractors/spikeglx.py @@ -40,9 +40,7 @@ class SpikeGLXRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ - mode = "folder" NeoRawIOClass = "SpikeGLXRawIO" - name = "spikeglx" def __init__(self, folder_path, load_sync_channel=False, stream_id=None, stream_name=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(folder_path, load_sync_channel=load_sync_channel) @@ -110,9 +108,7 @@ class SpikeGLXEventExtractor(NeoBaseEventExtractor): """ - mode = "folder" NeoRawIOClass = "SpikeGLXRawIO" - name = "spikeglx" def __init__(self, folder_path, block_index=None): neo_kwargs = self.map_to_neo_kwargs(folder_path) diff --git a/src/spikeinterface/extractors/neoextractors/tdt.py b/src/spikeinterface/extractors/neoextractors/tdt.py index 27b456102f..a1298dece7 100644 --- a/src/spikeinterface/extractors/neoextractors/tdt.py +++ b/src/spikeinterface/extractors/neoextractors/tdt.py @@ -27,9 +27,7 @@ class TdtRecordingExtractor(NeoBaseRecordingExtractor): If there are several blocks (experiments), specify the block index you want to load """ - mode = "folder" NeoRawIOClass = "TdtRawIO" - name = "tdt" def __init__(self, folder_path, stream_id=None, stream_name=None, block_index=None, all_annotations=False): neo_kwargs = self.map_to_neo_kwargs(folder_path) diff --git a/src/spikeinterface/extractors/nwbextractors.py b/src/spikeinterface/extractors/nwbextractors.py index 9786766af1..13fd56e959 100644 --- a/src/spikeinterface/extractors/nwbextractors.py +++ b/src/spikeinterface/extractors/nwbextractors.py @@ -472,8 +472,6 @@ class NwbRecordingExtractor(BaseRecording): >>> rec = NwbRecordingExtractor(s3_url, stream_mode="fsspec", stream_cache_path="cache") """ - mode = "file" - name = "nwb" installation_mesg = "To use the Nwb extractors, install pynwb: \n\n pip install pynwb\n\n" def __init__( @@ -1000,9 +998,7 @@ class NwbSortingExtractor(BaseSorting): The sorting extractor for the NWB file. """ - mode = "file" installation_mesg = "To use the Nwb extractors, install pynwb: \n\n pip install pynwb\n\n" - name = "nwb" def __init__( self, diff --git a/src/spikeinterface/extractors/phykilosortextractors.py b/src/spikeinterface/extractors/phykilosortextractors.py index 3287f7422f..737a88c51a 100644 --- a/src/spikeinterface/extractors/phykilosortextractors.py +++ b/src/spikeinterface/extractors/phykilosortextractors.py @@ -26,12 +26,9 @@ class BasePhyKilosortSortingExtractor(BaseSorting): If True, all cluster properties are loaded from the tsv/csv files. """ - installed = False # check at class level if installed or not - mode = "folder" installation_mesg = ( "To use the PhySortingExtractor install pandas: \n\n pip install pandas\n\n" # error message when not installed ) - name = "phykilosort" def __init__( self, @@ -43,14 +40,10 @@ def __init__( ): try: import pandas as pd - - HAVE_PD = True except ImportError: - HAVE_PD = False - assert HAVE_PD, self.installation_mesg + raise ImportError(self.installation_mesg) phy_folder = Path(folder_path) - spike_times = np.load(phy_folder / "spike_times.npy").astype(int) if (phy_folder / "spike_clusters.npy").is_file(): @@ -228,8 +221,6 @@ class PhySortingExtractor(BasePhyKilosortSortingExtractor): The loaded Sorting object. """ - name = "phy" - def __init__( self, folder_path: Path | str, @@ -269,8 +260,6 @@ class KiloSortSortingExtractor(BasePhyKilosortSortingExtractor): The loaded Sorting object. """ - name = "kilosort" - def __init__(self, folder_path: Path | str, keep_good_only: bool = False, remove_empty_units: bool = True): BasePhyKilosortSortingExtractor.__init__( self, diff --git a/src/spikeinterface/extractors/shybridextractors.py b/src/spikeinterface/extractors/shybridextractors.py index b53b3b2056..1c5c147c6a 100644 --- a/src/spikeinterface/extractors/shybridextractors.py +++ b/src/spikeinterface/extractors/shybridextractors.py @@ -30,24 +30,19 @@ class SHYBRIDRecordingExtractor(BinaryRecordingExtractor): Loaded data. """ - mode = "folder" installation_mesg = ( "To use the SHYBRID extractors, install SHYBRID and pyyaml: " "\n\n pip install shybrid pyyaml\n\n" ) - name = "shybrid" def __init__(self, file_path): try: import hybridizer.io as sbio import hybridizer.probes as sbprb import yaml - - HAVE_SBEX = True except ImportError: - HAVE_SBEX = False + raise ImportError(self.installation_mesg) # load params file related to the given shybrid recording - assert HAVE_SBEX, self.installation_mesg assert Path(file_path).suffix in [".yml", ".yaml"], "The 'file_path' should be a yaml file!" params = sbio.get_params(file_path)["data"] file_path = Path(file_path) @@ -102,12 +97,9 @@ def write_recording(recording, save_path, initial_sorting_fn, dtype="float32", * import hybridizer.io as sbio import hybridizer.probes as sbprb import yaml - - HAVE_SBEX = True except ImportError: - HAVE_SBEX = False + raise ImportError(SHYBRIDRecordingExtractor.installation_mesg) - assert HAVE_SBEX, SHYBRIDRecordingExtractor.installation_mesg assert recording.get_num_segments() == 1, "SHYBRID can only write single segment recordings" save_path = Path(save_path) recording_name = "recording.bin" @@ -159,18 +151,14 @@ class SHYBRIDSortingExtractor(BaseSorting): """ installation_mesg = "To use the SHYBRID extractors, install SHYBRID: \n\n pip install shybrid\n\n" - name = "shybrid" def __init__(self, file_path, sampling_frequency, delimiter=","): try: import hybridizer.io as sbio import hybridizer.probes as sbprb - - HAVE_SBEX = True except ImportError: - HAVE_SBEX = False + raise ImportError(self.installation_mesg) - assert HAVE_SBEX, self.installation_mesg assert Path(file_path).suffix == ".csv", "The 'file_path' should be a csv file!" if Path(file_path).is_file(): @@ -205,12 +193,9 @@ def write_sorting(sorting, save_path): try: import hybridizer.io as sbio import hybridizer.probes as sbprb - - HAVE_SBEX = True except ImportError: - HAVE_SBEX = False + raise ImportError(SHYBRIDSortingExtractor.installation_mesg) - assert HAVE_SBEX, SHYBRIDSortingExtractor.installation_mesg assert sorting.get_num_segments() == 1, "SHYBRID can only write single segment sortings" save_path = Path(save_path) diff --git a/src/spikeinterface/extractors/sinapsrecordingextractors.py b/src/spikeinterface/extractors/sinapsrecordingextractors.py index 522f639760..c3e92a63ff 100644 --- a/src/spikeinterface/extractors/sinapsrecordingextractors.py +++ b/src/spikeinterface/extractors/sinapsrecordingextractors.py @@ -23,10 +23,6 @@ class SinapsResearchPlatformRecordingExtractor(ChannelSliceRecording): "filt" extracts the filtered data, "raw" extracts the raw data, and "aux" extracts the auxiliary data. """ - extractor_name = "SinapsResearchPlatform" - mode = "file" - name = "sinaps_research_platform" - def __init__(self, file_path: str | Path, stream_name: str = "filt"): from ..preprocessing import UnsignedToSignedRecording @@ -91,10 +87,6 @@ class SinapsResearchPlatformH5RecordingExtractor(BaseRecording): Path to the SiNAPS .h5 file. """ - extractor_name = "SinapsResearchPlatformH5" - mode = "file" - name = "sinaps_research_platform_h5" - def __init__(self, file_path: str | Path): self._file_path = file_path diff --git a/src/spikeinterface/extractors/spykingcircusextractors.py b/src/spikeinterface/extractors/spykingcircusextractors.py index 7c3fb154fe..b8a1e5635e 100644 --- a/src/spikeinterface/extractors/spykingcircusextractors.py +++ b/src/spikeinterface/extractors/spykingcircusextractors.py @@ -7,13 +7,6 @@ from spikeinterface.core import BaseSorting, BaseSortingSegment from spikeinterface.core.core_tools import define_function_from_class -try: - import h5py - - HAVE_H5PY = True -except ImportError: - HAVE_H5PY = False - class SpykingCircusSortingExtractor(BaseSorting): """Load SpykingCircus format data as a recording extractor. @@ -29,13 +22,13 @@ class SpykingCircusSortingExtractor(BaseSorting): Loaded data. """ - installed = HAVE_H5PY # check at class level if installed or not - mode = "folder" installation_mesg = "To use the SpykingCircusSortingExtractor install h5py: \n\n pip install h5py\n\n" - name = "spykingcircus" def __init__(self, folder_path): - assert HAVE_H5PY, self.installation_mesg + try: + import h5py + except ImportError: + raise ImportError(self.installation_mesg) spykingcircus_folder = Path(folder_path) listfiles = spykingcircus_folder.iterdir() diff --git a/src/spikeinterface/extractors/tridesclousextractors.py b/src/spikeinterface/extractors/tridesclousextractors.py index 8589f03fd4..ac1ce4727b 100644 --- a/src/spikeinterface/extractors/tridesclousextractors.py +++ b/src/spikeinterface/extractors/tridesclousextractors.py @@ -22,9 +22,7 @@ class TridesclousSortingExtractor(BaseSorting): Loaded data. """ - mode = "folder" installation_mesg = "To use the TridesclousSortingExtractor install tridesclous: \n\n pip install tridesclous\n\n" # error message when not installed - name = "tridesclous" def __init__(self, folder_path, chan_grp=None): try: diff --git a/src/spikeinterface/extractors/waveclussnippetstextractors.py b/src/spikeinterface/extractors/waveclussnippetstextractors.py index 7c26eee7bd..75bae32519 100644 --- a/src/spikeinterface/extractors/waveclussnippetstextractors.py +++ b/src/spikeinterface/extractors/waveclussnippetstextractors.py @@ -10,7 +10,6 @@ class WaveClusSnippetsExtractor(MatlabHelper, BaseSnippets): - name = "waveclus" def __init__(self, file_path): file_path = Path(file_path) if isinstance(file_path, str) else file_path diff --git a/src/spikeinterface/extractors/waveclustextractors.py b/src/spikeinterface/extractors/waveclustextractors.py index 844b1cc7cf..3d024910fa 100644 --- a/src/spikeinterface/extractors/waveclustextractors.py +++ b/src/spikeinterface/extractors/waveclustextractors.py @@ -25,8 +25,6 @@ class WaveClusSortingExtractor(MatlabHelper, BaseSorting): Loaded data. """ - name = "waveclus" - def __init__(self, file_path, keep_good_only=True): MatlabHelper.__init__(self, file_path) diff --git a/src/spikeinterface/extractors/yassextractors.py b/src/spikeinterface/extractors/yassextractors.py index 61a49ccf01..7a76906acc 100644 --- a/src/spikeinterface/extractors/yassextractors.py +++ b/src/spikeinterface/extractors/yassextractors.py @@ -7,13 +7,6 @@ from spikeinterface.core import BaseSorting, BaseSortingSegment from spikeinterface.core.core_tools import define_function_from_class -try: - import yaml - - HAVE_YAML = True -except: - HAVE_YAML = False - class YassSortingExtractor(BaseSorting): """Load YASS format data as a sorting extractor. @@ -29,15 +22,13 @@ class YassSortingExtractor(BaseSorting): Loaded data. """ - mode = "folder" - installed = HAVE_YAML # check at class level if installed or not - installation_mesg = ( - "To use the Yass extractor, install pyyaml: \n\n pip install pyyaml\n\n" # error message when not installed - ) - name = "yass" + installation_mesg = "To use the Yass extractor, install pyyaml: \n\n pip install pyyaml\n\n" def __init__(self, folder_path): - assert HAVE_YAML, self.installation_mesg + try: + import yaml + except: + raise ImportError(self.installation_mesg) folder_path = Path(folder_path) From 5b663ad012534c85fc0565f1cf32ad5d0d739096 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Fri, 5 Jul 2024 10:33:59 +0200 Subject: [PATCH 2/2] Fix biocam --- src/spikeinterface/extractors/neoextractors/biocam.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spikeinterface/extractors/neoextractors/biocam.py b/src/spikeinterface/extractors/neoextractors/biocam.py index 15953ff6d7..e7b6199ea9 100644 --- a/src/spikeinterface/extractors/neoextractors/biocam.py +++ b/src/spikeinterface/extractors/neoextractors/biocam.py @@ -31,6 +31,8 @@ class BiocamRecordingExtractor(NeoBaseRecordingExtractor): Load exhaustively all annotations from neo. """ + NeoRawIOClass = "BiocamRawIO" + def __init__( self, file_path,