From 4d71d43e0395926351d6fd6fe4d670cbbe314591 Mon Sep 17 00:00:00 2001 From: Samuel Garcia Date: Wed, 6 Mar 2024 16:09:35 +0100 Subject: [PATCH 1/3] Add strict_gap_mode in read_neuralynx to reflect neo. --- .../extractors/neoextractors/neuralynx.py | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/extractors/neoextractors/neuralynx.py b/src/spikeinterface/extractors/neoextractors/neuralynx.py index 88ecc69c53..3df8a8d255 100644 --- a/src/spikeinterface/extractors/neoextractors/neuralynx.py +++ b/src/spikeinterface/extractors/neoextractors/neuralynx.py @@ -3,11 +3,15 @@ from typing import Optional from pathlib import Path +from importlib.metadata import version + from spikeinterface.core.core_tools import define_function_from_class from .neobaseextractor import NeoBaseRecordingExtractor, NeoBaseSortingExtractor + + class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): """ Class for reading neuralynx folder @@ -27,22 +31,33 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): exlude_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. + strict_gap_mode: bool, default: False + See neo documentation. + Detect gaps using strict mode or not. + * strict_gap_mode = True then a gap is consider when timstamp difference between two + consequtive data packet is more than one sample interval. + * strict_gap_mode = False then a gap has an increased tolerance. Some new system with different clock need this option + otherwise, too many gaps are detected + Note hat here the default is False contrary to neo. """ mode = "folder" NeoRawIOClass = "NeuralynxRawIO" name = "neuralynx" - def __init__(self, folder_path, stream_id=None, stream_name=None, all_annotations=False, exclude_filename=None): - neo_kwargs = self.map_to_neo_kwargs(folder_path, exclude_filename) + def __init__(self, folder_path, stream_id=None, stream_name=None, all_annotations=False, exclude_filename=None, strict_gap_mode=False): + neo_kwargs = self.map_to_neo_kwargs(folder_path, exclude_filename, strict_gap_mode) NeoBaseRecordingExtractor.__init__( self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs ) - self._kwargs.update(dict(folder_path=str(Path(folder_path).absolute()), exclude_filename=exclude_filename)) + self._kwargs.update(dict(folder_path=str(Path(folder_path).absolute()), exclude_filename=exclude_filename), strict_gap_mode=strict_gap_mode) @classmethod - def map_to_neo_kwargs(cls, folder_path, exclude_filename): + def map_to_neo_kwargs(cls, folder_path, exclude_filename, strict_gap_mode): neo_kwargs = {"dirname": str(folder_path), "exclude_filename": exclude_filename} + if version("neo") >= "0.13.1": + neo_kwargs["strict_gap_mode"] = strict_gap_mode + return neo_kwargs From 254985cee62d1487f52d57380a1004650b2de610 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:10:47 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../extractors/neoextractors/neuralynx.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/extractors/neoextractors/neuralynx.py b/src/spikeinterface/extractors/neoextractors/neuralynx.py index 3df8a8d255..cc270d8029 100644 --- a/src/spikeinterface/extractors/neoextractors/neuralynx.py +++ b/src/spikeinterface/extractors/neoextractors/neuralynx.py @@ -10,8 +10,6 @@ from .neobaseextractor import NeoBaseRecordingExtractor, NeoBaseSortingExtractor - - class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): """ Class for reading neuralynx folder @@ -34,7 +32,7 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): strict_gap_mode: bool, default: False See neo documentation. Detect gaps using strict mode or not. - * strict_gap_mode = True then a gap is consider when timstamp difference between two + * strict_gap_mode = True then a gap is consider when timstamp difference between two consequtive data packet is more than one sample interval. * strict_gap_mode = False then a gap has an increased tolerance. Some new system with different clock need this option otherwise, too many gaps are detected @@ -45,12 +43,23 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): NeoRawIOClass = "NeuralynxRawIO" name = "neuralynx" - def __init__(self, folder_path, stream_id=None, stream_name=None, all_annotations=False, exclude_filename=None, strict_gap_mode=False): + def __init__( + self, + folder_path, + stream_id=None, + stream_name=None, + all_annotations=False, + exclude_filename=None, + strict_gap_mode=False, + ): neo_kwargs = self.map_to_neo_kwargs(folder_path, exclude_filename, strict_gap_mode) NeoBaseRecordingExtractor.__init__( self, stream_id=stream_id, stream_name=stream_name, all_annotations=all_annotations, **neo_kwargs ) - self._kwargs.update(dict(folder_path=str(Path(folder_path).absolute()), exclude_filename=exclude_filename), strict_gap_mode=strict_gap_mode) + self._kwargs.update( + dict(folder_path=str(Path(folder_path).absolute()), exclude_filename=exclude_filename), + strict_gap_mode=strict_gap_mode, + ) @classmethod def map_to_neo_kwargs(cls, folder_path, exclude_filename, strict_gap_mode): From 0b420e9f60bca9d8b61651b52687265272392824 Mon Sep 17 00:00:00 2001 From: Garcia Samuel Date: Wed, 6 Mar 2024 19:27:18 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/extractors/neoextractors/neuralynx.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/extractors/neoextractors/neuralynx.py b/src/spikeinterface/extractors/neoextractors/neuralynx.py index cc270d8029..cc89302e59 100644 --- a/src/spikeinterface/extractors/neoextractors/neuralynx.py +++ b/src/spikeinterface/extractors/neoextractors/neuralynx.py @@ -33,10 +33,10 @@ class NeuralynxRecordingExtractor(NeoBaseRecordingExtractor): See neo documentation. Detect gaps using strict mode or not. * strict_gap_mode = True then a gap is consider when timstamp difference between two - consequtive data packet is more than one sample interval. - * strict_gap_mode = False then a gap has an increased tolerance. Some new system with different clock need this option + consecutive data packets is more than one sample interval. + * strict_gap_mode = False then a gap has an increased tolerance. Some new systems with different clocks need this option otherwise, too many gaps are detected - Note hat here the default is False contrary to neo. + Note that here the default is False contrary to neo. """ mode = "folder"