diff --git a/src/spikeinterface/extractors/neoextractors/biocam.py b/src/spikeinterface/extractors/neoextractors/biocam.py index b3ccb92cbd..a9d1b970ee 100644 --- a/src/spikeinterface/extractors/neoextractors/biocam.py +++ b/src/spikeinterface/extractors/neoextractors/biocam.py @@ -85,7 +85,7 @@ def __init__( ) @classmethod - def map_to_neo_kwargs(cls, file_path, fill_gaps_strategy): + def map_to_neo_kwargs(cls, file_path, fill_gaps_strategy=None): neo_kwargs = { "filename": str(file_path), "fill_gaps_strategy": fill_gaps_strategy, diff --git a/src/spikeinterface/extractors/neoextractors/blackrock.py b/src/spikeinterface/extractors/neoextractors/blackrock.py index 08b3645bb2..dcfaf0661a 100644 --- a/src/spikeinterface/extractors/neoextractors/blackrock.py +++ b/src/spikeinterface/extractors/neoextractors/blackrock.py @@ -43,9 +43,7 @@ def __init__( use_names_as_ids: bool = False, gap_tolerance_ms: float | None = None, ): - neo_kwargs = self.map_to_neo_kwargs(file_path) - if gap_tolerance_ms is not None: - neo_kwargs["gap_tolerance_ms"] = gap_tolerance_ms + neo_kwargs = self.map_to_neo_kwargs(file_path, gap_tolerance_ms=gap_tolerance_ms) neo_kwargs["load_nev"] = False # Avoid loading spikes release in neo 0.12.0 # trick to avoid to select automatically the correct stream_id @@ -63,8 +61,10 @@ def __init__( self._kwargs.update({"file_path": str(Path(file_path).absolute()), "gap_tolerance_ms": gap_tolerance_ms}) @classmethod - def map_to_neo_kwargs(cls, file_path): + def map_to_neo_kwargs(cls, file_path, gap_tolerance_ms=None): neo_kwargs = {"filename": str(file_path)} + if gap_tolerance_ms is not None: + neo_kwargs["gap_tolerance_ms"] = gap_tolerance_ms return neo_kwargs @@ -109,9 +109,7 @@ def __init__( nsx_to_load: int | list | str | None = None, gap_tolerance_ms: float | None = None, ): - neo_kwargs = self.map_to_neo_kwargs(file_path) - if gap_tolerance_ms is not None: - neo_kwargs["gap_tolerance_ms"] = gap_tolerance_ms + neo_kwargs = self.map_to_neo_kwargs(file_path, gap_tolerance_ms=gap_tolerance_ms) NeoBaseSortingExtractor.__init__( self, stream_id=stream_id, @@ -130,8 +128,10 @@ def __init__( } @classmethod - def map_to_neo_kwargs(cls, file_path): + def map_to_neo_kwargs(cls, file_path, gap_tolerance_ms=None): neo_kwargs = {"filename": str(file_path)} + if gap_tolerance_ms is not None: + neo_kwargs["gap_tolerance_ms"] = gap_tolerance_ms return neo_kwargs diff --git a/src/spikeinterface/extractors/neoextractors/neuralynx.py b/src/spikeinterface/extractors/neoextractors/neuralynx.py index 81f507535c..9f7ec6f5c5 100644 --- a/src/spikeinterface/extractors/neoextractors/neuralynx.py +++ b/src/spikeinterface/extractors/neoextractors/neuralynx.py @@ -67,7 +67,7 @@ def __init__( ) @classmethod - def map_to_neo_kwargs(cls, folder_path, exclude_filename, strict_gap_mode): + def map_to_neo_kwargs(cls, folder_path, exclude_filename=None, strict_gap_mode=False): neo_kwargs = {"dirname": str(folder_path), "exclude_filename": exclude_filename} if version("neo") >= "0.13.1": neo_kwargs["strict_gap_mode"] = strict_gap_mode @@ -92,6 +92,9 @@ class NeuralynxSortingExtractor(NeoBaseSortingExtractor): Used to extract information about the sampling frequency and t_start from the analog signal if provided. stream_name : str, default: None Used to extract information about the sampling frequency and t_start from the analog signal if provided. + exclude_filename : list[str], default: None + List of filename to exclude from the loading. + For example, use `exclude_filename=["events.nev"]` to skip loading the event file. """ NeoRawIOClass = "NeuralynxRawIO" @@ -104,8 +107,9 @@ def __init__( sampling_frequency: float | None = None, stream_id: str | None = None, stream_name: str | None = None, + exclude_filename: list[str] | None = None, ): - neo_kwargs = self.map_to_neo_kwargs(folder_path) + neo_kwargs = self.map_to_neo_kwargs(folder_path, exclude_filename) NeoBaseSortingExtractor.__init__( self, sampling_frequency=sampling_frequency, @@ -119,11 +123,12 @@ def __init__( "sampling_frequency": sampling_frequency, "stream_id": stream_id, "stream_name": stream_name, + "exclude_filename": exclude_filename, } @classmethod - def map_to_neo_kwargs(cls, folder_path): - neo_kwargs = {"dirname": str(folder_path)} + def map_to_neo_kwargs(cls, folder_path, exclude_filename=None): + neo_kwargs = {"dirname": str(folder_path), "exclude_filename": exclude_filename} return neo_kwargs diff --git a/src/spikeinterface/extractors/tests/common_tests.py b/src/spikeinterface/extractors/tests/common_tests.py index 3a26a53df3..ea733a368b 100644 --- a/src/spikeinterface/extractors/tests/common_tests.py +++ b/src/spikeinterface/extractors/tests/common_tests.py @@ -1,4 +1,5 @@ import pickle +import inspect import numpy as np @@ -75,6 +76,24 @@ def test_open(self): trace_scaled = rec.get_traces(segment_index=segment_index, return_in_uV=True, end_frame=2) assert trace_scaled.dtype == "float32" + def test_get_streams(self): + for entity in self.entities: + if isinstance(entity, tuple): + path, kwargs = entity + elif isinstance(entity, str): + path = entity + kwargs = {} + + if not hasattr(self.ExtractorClass, "NeoRawIOClass"): + continue + + # get_streams is called before the extractor exists, with the path and whatever neo needs to open it + neo_parameters = inspect.signature(self.ExtractorClass.map_to_neo_kwargs).parameters + neo_kwargs = {key: value for key, value in kwargs.items() if key in neo_parameters} + + stream_names, stream_ids = self.ExtractorClass.get_streams(self.get_full_path(path), **neo_kwargs) + assert len(stream_names) == len(stream_ids) + def test_neo_annotations(self): for entity in self.entities: if isinstance(entity, tuple):