From 0f9c32cbdb82ce48120830fe55c88d0376a350b8 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 17:25:00 +0100 Subject: [PATCH 01/33] Add 'int' type to 'num_samples' on 'InjectTemplatesRecording'. --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 62aa7f37c3..e53f8cc539 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1714,7 +1714,7 @@ def __init__( amplitude_factor: Union[List[List[float]], List[float], float, None] = None, parent_recording: Union[BaseRecording, None] = None, num_samples: Optional[List[int]] = None, - upsample_vector: Union[List[int], None] = None, + upsample_vector: Union[List[int], int, None] = None, check_borders: bool = False, ) -> None: templates = np.asarray(templates) From 73c146f29828d073af08e91a7fd45a38430cff71 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:01:22 +0100 Subject: [PATCH 02/33] Remove some errneous Optional type hints and convert to | on 'generate_recording'. --- src/spikeinterface/core/generate.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index e53f8cc539..e9255d55cc 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -27,12 +27,12 @@ def _ensure_seed(seed): def generate_recording( - num_channels: Optional[int] = 2, - sampling_frequency: Optional[float] = 30000.0, - durations: Optional[List[float]] = [5.0, 2.5], - set_probe: Optional[bool] = True, - ndim: Optional[int] = 2, - seed: Optional[int] = None, + num_channels: int = 2, + sampling_frequency: float = 30000.0, + durations: List[float] = [5.0, 2.5], + set_probe: bool | None = True, + ndim: int | None = 2, + seed: int | None = None, ) -> BaseRecording: """ Generate a lazy recording object. @@ -1090,7 +1090,7 @@ def __init__( num_channels: int, sampling_frequency: float, durations: List[float], - noise_levels: float = 1.0, + noise_levels: float | np.array = 1.0, cov_matrix: Optional[np.array] = None, dtype: Optional[Union[np.dtype, str]] = "float32", seed: Optional[int] = None, From e5701f6202106c14c4307e2e541ad8167319dfdd Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:01:31 +0100 Subject: [PATCH 03/33] Remove some errneous Optional type hints and convert to | on 'generate_recording'. --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index e9255d55cc..c4665a7bd5 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1090,7 +1090,7 @@ def __init__( num_channels: int, sampling_frequency: float, durations: List[float], - noise_levels: float | np.array = 1.0, + noise_levels: float = 1.0, cov_matrix: Optional[np.array] = None, dtype: Optional[Union[np.dtype, str]] = "float32", seed: Optional[int] = None, From 098f8071b1aa0e7170b04d0966fc35526839b1e9 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:12:56 +0100 Subject: [PATCH 04/33] Convert NoiseGeneratorRecording. --- src/spikeinterface/core/generate.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index c4665a7bd5..9037109549 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1064,11 +1064,11 @@ class NoiseGeneratorRecording(BaseRecording): The durations of each segment in seconds. Note that the length of this list is the number of segments. noise_levels: float or array, default: 1 Std of the white noise (if an array, defined by per channels) - cov_matrix: np.array, default None + cov_matrix: np.array | None, default None The covariance matrix of the noise - dtype : Optional[Union[np.dtype, str]], default: "float32" + dtype : np.dtype | str |None, default: "float32" The dtype of the recording. Note that only np.float32 and np.float64 are supported. - seed : Optional[int], default: None + seed : int | None, default: None The seed for np.random.default_rng. strategy : "tile_pregenerated" or "on_the_fly" The strategy of generating noise chunk: @@ -1090,10 +1090,10 @@ def __init__( num_channels: int, sampling_frequency: float, durations: List[float], - noise_levels: float = 1.0, - cov_matrix: Optional[np.array] = None, - dtype: Optional[Union[np.dtype, str]] = "float32", - seed: Optional[int] = None, + noise_levels: float | np.array = 1.0, + cov_matrix: np.array | None = None, + dtype: np.dtype | str | None = "float32", + seed: int | None = None, strategy: Literal["tile_pregenerated", "on_the_fly"] = "tile_pregenerated", noise_block_size: int = 30000, ): From db0c30d37d443fcffad7caead7412d672e553d81 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:13:27 +0100 Subject: [PATCH 05/33] Remove duplicate noise level keys in NoiseGeneratorRecording. --- src/spikeinterface/core/generate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 9037109549..a3e77b57f0 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1150,7 +1150,6 @@ def __init__( "sampling_frequency": sampling_frequency, "noise_levels": noise_levels, "cov_matrix": cov_matrix, - "noise_levels": noise_levels, "dtype": dtype, "seed": seed, "strategy": strategy, From 013c834aba8ad0f0ac6a956db30bdc4a5e8b3598 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:16:44 +0100 Subject: [PATCH 06/33] substitute get_traces(). --- src/spikeinterface/core/generate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index a3e77b57f0..0d95668f2e 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1204,9 +1204,9 @@ def get_num_samples(self) -> int: def get_traces( self, - start_frame: Union[int, None] = None, - end_frame: Union[int, None] = None, - channel_indices: Union[List, None] = None, + start_frame: int | None = None, + end_frame: int | None = None, + channel_indices: List | None = None, ) -> np.ndarray: start_frame_within_block = start_frame % self.noise_block_size end_frame_within_block = end_frame % self.noise_block_size From 0cede16b03ca2b404783806353b30591e0116d03 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:17:17 +0100 Subject: [PATCH 07/33] Remove unused argument to generate_recording_by_size. --- src/spikeinterface/core/generate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 0d95668f2e..b48d8b40df 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1260,7 +1260,6 @@ def get_traces( def generate_recording_by_size( full_traces_size_GiB: float, - num_channels: int = 384, seed: Optional[int] = None, strategy: Literal["tile_pregenerated", "on_the_fly"] = "tile_pregenerated", ) -> NoiseGeneratorRecording: From bbc55b48233e1cca578c69bb6af0223fc0e0c1d0 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:17:38 +0100 Subject: [PATCH 08/33] Convert 'generate_recording_by_size'. --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index b48d8b40df..41b44792be 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1260,7 +1260,7 @@ def get_traces( def generate_recording_by_size( full_traces_size_GiB: float, - seed: Optional[int] = None, + seed: int | None = None, strategy: Literal["tile_pregenerated", "on_the_fly"] = "tile_pregenerated", ) -> NoiseGeneratorRecording: """ From c5af7f36b75d1f37d0e7e2d54ff81383a7928cc2 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:40:02 +0100 Subject: [PATCH 09/33] Fix type hints on InjectTemplatesRecording and convert. --- src/spikeinterface/core/generate.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 41b44792be..b9ab8f6d25 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1694,7 +1694,7 @@ class InjectTemplatesRecording(BaseRecording): num_samples: list[int] | int | None The number of samples in the recording per segment. You can use int for mono-segment objects. - upsample_vector: np.array or None, default: None. + upsample_vector: np.array | None, default: None. When templates is 4d we can simulate a jitter. Optional the upsample_vector is the jitter index with a number per spike in range 0-templates.shape[3]. @@ -1708,11 +1708,11 @@ def __init__( self, sorting: BaseSorting, templates: np.ndarray, - nbefore: Union[List[int], int, None] = None, - amplitude_factor: Union[List[List[float]], List[float], float, None] = None, - parent_recording: Union[BaseRecording, None] = None, - num_samples: Optional[List[int]] = None, - upsample_vector: Union[List[int], int, None] = None, + nbefore: List[int] | int | None = None, + amplitude_factor: List[List[float]] | List[float] | float | None = None, + parent_recording: BaseRecording | None = None, + num_samples: List[int] | int | None = None, + upsample_vector: np.array | None = None, check_borders: bool = False, ) -> None: templates = np.asarray(templates) From 16bf359de2c364f9681f193601aeb46304053762 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:43:55 +0100 Subject: [PATCH 10/33] Remove bad type hint on 'InjectTemplatesRecording'. --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index b9ab8f6d25..21edae8447 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1709,7 +1709,7 @@ def __init__( sorting: BaseSorting, templates: np.ndarray, nbefore: List[int] | int | None = None, - amplitude_factor: List[List[float]] | List[float] | float | None = None, + amplitude_factor: List[float] | float | None = None, parent_recording: BaseRecording | None = None, num_samples: List[int] | int | None = None, upsample_vector: np.array | None = None, From 1760d0f5a213356390069b387d4674fafbd314bb Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:54:30 +0100 Subject: [PATCH 11/33] Fix all other cases --- src/spikeinterface/core/generate.py | 60 ++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 21edae8447..6fc21a34dc 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -2,7 +2,7 @@ import math import warnings import numpy as np -from typing import Union, Optional, List, Literal +from typing import List, Literal from math import ceil from .basesorting import SpikeVectorSortingSegment @@ -47,10 +47,10 @@ def generate_recording( durations: List[float], default: [5.0, 2.5] The duration in seconds of each segment in the recording, default: [5.0, 2.5]. Note that the number of segments is determined by the length of this list. - set_probe: bool, default: True - ndim : int, default: 2 + set_probe: bool | None, default: True + ndim : int | None, default: 2 The number of dimensions of the probe, default: 2. Set to 3 to make 3 dimensional probe. - seed : Optional[int] + seed : int | None, default: None A seed for the np.ramdom.default_rng function Returns @@ -253,13 +253,13 @@ def generate_sorting_to_inject( num_samples: list of size num_segments. The number of samples in all the segments of the sorting, to generate spike times covering entire the entire duration of the segments. - max_injected_per_unit: int, default 1000 + max_injected_per_unit: int, default: 1000 The maximal number of spikes injected per units. - injected_rate: float, default 0.05 + injected_rate: float, default: 0.05 The rate at which spikes are injected. - refractory_period_ms: float, default 1.5 + refractory_period_ms: float, default: 1.5 The refractory period that should not be violated while injecting new spikes. - seed: int, default None + seed: int, default: None The random seed. Returns @@ -313,13 +313,13 @@ class TransformSorting(BaseSorting): ---------- sorting : BaseSorting The sorting object. - added_spikes_existing_units : np.array (spike_vector) + added_spikes_existing_units : np.array (spike_vector) | None, default: None The spikes that should be added to the sorting object, for existing units. - added_spikes_new_units: np.array (spike_vector) + added_spikes_new_units: np.array (spike_vector) | None, default: None The spikes that should be added to the sorting object, for new units. - new_units_ids: list + new_units_ids: list[str, int] | None, default: None The unit_ids that should be added if spikes for new units are added. - refractory_period_ms : float, default None + refractory_period_ms : float | None, default: None The refractory period violation to prevent duplicates and/or unphysiological addition of spikes. Any spike times in added_spikes violating the refractory period will be discarded. @@ -333,10 +333,10 @@ class TransformSorting(BaseSorting): def __init__( self, sorting: BaseSorting, - added_spikes_existing_units=None, - added_spikes_new_units=None, - new_unit_ids: Optional[List[Union[str, int]]] = None, - refractory_period_ms: Optional[float] = None, + added_spikes_existing_units: np.array | None = None, + added_spikes_new_units: np.array | None = None, + new_unit_ids: List[str | int] | None = None, + refractory_period_ms: float | None = None, ): sampling_frequency = sorting.get_sampling_frequency() unit_ids = list(sorting.get_unit_ids()) @@ -432,7 +432,7 @@ def add_from_sorting(sorting1: BaseSorting, sorting2: BaseSorting, refractory_pe The first sorting. sorting2: BaseSorting The second sorting. - refractory_period_ms : float, default None + refractory_period_ms : float, default: None The refractory period violation to prevent duplicates and/or unphysiological addition of spikes. Any spike times in added_spikes violating the refractory period will be discarded. @@ -498,7 +498,7 @@ def add_from_unit_dict( The first sorting dict_list: list of dict A list of dict with unit_ids as keys and spike times as values. - refractory_period_ms : float, default None + refractory_period_ms : float, default: None The refractory period violation to prevent duplicates and/or unphysiological addition of spikes. Any spike times in added_spikes violating the refractory period will be discarded. @@ -528,7 +528,7 @@ def from_times_labels( unit_ids: list or None, default: None The explicit list of unit_ids that should be extracted from labels_list If None, then it will be np.unique(labels_list). - refractory_period_ms : float, default None + refractory_period_ms : float, default: None The refractory period violation to prevent duplicates and/or unphysiological addition of spikes. Any spike times in added_spikes violating the refractory period will be discarded. @@ -1064,7 +1064,7 @@ class NoiseGeneratorRecording(BaseRecording): The durations of each segment in seconds. Note that the length of this list is the number of segments. noise_levels: float or array, default: 1 Std of the white noise (if an array, defined by per channels) - cov_matrix: np.array | None, default None + cov_matrix: np.array | None, default: None The covariance matrix of the noise dtype : np.dtype | str |None, default: "float32" The dtype of the recording. Note that only np.float32 and np.float64 are supported. @@ -1279,7 +1279,7 @@ def generate_recording_by_size( The size in gigabytes (GiB) of the recording. num_channels: int Number of channels. - seed : int, default: None + seed : int | None, default: None The seed for np.random.default_rng. Returns @@ -1688,10 +1688,10 @@ class InjectTemplatesRecording(BaseRecording): Can be None (no scaling). Can be scalar all spikes have the same factor (certainly useless). Can be a vector with same shape of spike_vector of the sorting. - parent_recording: BaseRecording | None + parent_recording: BaseRecording | None, default: None The recording over which to add the templates. If None, will default to traces containing all 0. - num_samples: list[int] | int | None + num_samples: list[int] | int | None, default: None The number of samples in the recording per segment. You can use int for mono-segment objects. upsample_vector: np.array | None, default: None. @@ -1844,10 +1844,10 @@ def __init__( spike_vector: np.ndarray, templates: np.ndarray, nbefore: int, - amplitude_vector: Union[List[float], None], - upsample_vector: Union[List[float], None], - parent_recording_segment: Union[BaseRecordingSegment, None] = None, - num_samples: Union[int, None] = None, + amplitude_vector: List[float] | None, + upsample_vector: List[float] | None, + parent_recording_segment: BaseRecordingSegment | None = None, + num_samples: int | None = None, ) -> None: BaseRecordingSegment.__init__( self, @@ -1867,9 +1867,9 @@ def __init__( def get_traces( self, - start_frame: Union[int, None] = None, - end_frame: Union[int, None] = None, - channel_indices: Union[List, None] = None, + start_frame: int | None = None, + end_frame: int | None = None, + channel_indices: List | None = None, ) -> np.ndarray: if channel_indices is None: n_channels = self.templates.shape[2] From f694e30e06ffaf3895ff3cbafd060551aabedd08 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Thu, 18 Jul 2024 18:55:40 +0100 Subject: [PATCH 12/33] List -> list. --- src/spikeinterface/core/generate.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 6fc21a34dc..ea58ab6ef8 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -2,7 +2,7 @@ import math import warnings import numpy as np -from typing import List, Literal +from typing import Literal from math import ceil from .basesorting import SpikeVectorSortingSegment @@ -29,7 +29,7 @@ def _ensure_seed(seed): def generate_recording( num_channels: int = 2, sampling_frequency: float = 30000.0, - durations: List[float] = [5.0, 2.5], + durations: list[float] = [5.0, 2.5], set_probe: bool | None = True, ndim: int | None = 2, seed: int | None = None, @@ -44,7 +44,7 @@ def generate_recording( The number of channels in the recording. sampling_frequency : float, default: 30000. (in Hz) The sampling frequency of the recording, default: 30000. - durations: List[float], default: [5.0, 2.5] + durations: list[float], default: [5.0, 2.5] The duration in seconds of each segment in the recording, default: [5.0, 2.5]. Note that the number of segments is determined by the length of this list. set_probe: bool | None, default: True @@ -236,7 +236,7 @@ def add_synchrony_to_sorting(sorting, sync_event_ratio=0.3, seed=None): def generate_sorting_to_inject( sorting: BaseSorting, - num_samples: List[int], + num_samples: list[int], max_injected_per_unit: int = 1000, injected_rate: float = 0.05, refractory_period_ms: float = 1.5, @@ -335,7 +335,7 @@ def __init__( sorting: BaseSorting, added_spikes_existing_units: np.array | None = None, added_spikes_new_units: np.array | None = None, - new_unit_ids: List[str | int] | None = None, + new_unit_ids: list[str | int] | None = None, refractory_period_ms: float | None = None, ): sampling_frequency = sorting.get_sampling_frequency() @@ -1060,7 +1060,7 @@ class NoiseGeneratorRecording(BaseRecording): The number of channels. sampling_frequency : float The sampling frequency of the recorder. - durations : List[float] + durations : list[float] The durations of each segment in seconds. Note that the length of this list is the number of segments. noise_levels: float or array, default: 1 Std of the white noise (if an array, defined by per channels) @@ -1089,7 +1089,7 @@ def __init__( self, num_channels: int, sampling_frequency: float, - durations: List[float], + durations: list[float], noise_levels: float | np.array = 1.0, cov_matrix: np.array | None = None, dtype: np.dtype | str | None = "float32", @@ -1206,7 +1206,7 @@ def get_traces( self, start_frame: int | None = None, end_frame: int | None = None, - channel_indices: List | None = None, + channel_indices: list | None = None, ) -> np.ndarray: start_frame_within_block = start_frame % self.noise_block_size end_frame_within_block = end_frame % self.noise_block_size @@ -1708,10 +1708,10 @@ def __init__( self, sorting: BaseSorting, templates: np.ndarray, - nbefore: List[int] | int | None = None, - amplitude_factor: List[float] | float | None = None, + nbefore: list[int] | int | None = None, + amplitude_factor: list[float] | float | None = None, parent_recording: BaseRecording | None = None, - num_samples: List[int] | int | None = None, + num_samples: list[int] | int | None = None, upsample_vector: np.array | None = None, check_borders: bool = False, ) -> None: @@ -1844,8 +1844,8 @@ def __init__( spike_vector: np.ndarray, templates: np.ndarray, nbefore: int, - amplitude_vector: List[float] | None, - upsample_vector: List[float] | None, + amplitude_vector: list[float] | None, + upsample_vector: list[float] | None, parent_recording_segment: BaseRecordingSegment | None = None, num_samples: int | None = None, ) -> None: @@ -1869,7 +1869,7 @@ def get_traces( self, start_frame: int | None = None, end_frame: int | None = None, - channel_indices: List | None = None, + channel_indices: list | None = None, ) -> np.ndarray: if channel_indices is None: n_channels = self.templates.shape[2] From bc2cc8a965ec8871c7a8f91edde8bf104792fde5 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:22:18 +0100 Subject: [PATCH 13/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index ea58ab6ef8..04d2135670 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -44,7 +44,7 @@ def generate_recording( The number of channels in the recording. sampling_frequency : float, default: 30000. (in Hz) The sampling frequency of the recording, default: 30000. - durations: list[float], default: [5.0, 2.5] + durations : list[float], default: [5.0, 2.5] The duration in seconds of each segment in the recording, default: [5.0, 2.5]. Note that the number of segments is determined by the length of this list. set_probe: bool | None, default: True From ff66a3815663e9f4909a505231008d5bd1779fb7 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:22:28 +0100 Subject: [PATCH 14/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 04d2135670..325008a4f2 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -259,7 +259,7 @@ def generate_sorting_to_inject( The rate at which spikes are injected. refractory_period_ms: float, default: 1.5 The refractory period that should not be violated while injecting new spikes. - seed: int, default: None + seed : int, default: None The random seed. Returns From 90b366dfe4b5fd7c4a73b858b5aff844d4703f1e Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:22:58 +0100 Subject: [PATCH 15/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 325008a4f2..10139918c2 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1688,7 +1688,7 @@ class InjectTemplatesRecording(BaseRecording): Can be None (no scaling). Can be scalar all spikes have the same factor (certainly useless). Can be a vector with same shape of spike_vector of the sorting. - parent_recording: BaseRecording | None, default: None + parent_recording : BaseRecording | None, default: None The recording over which to add the templates. If None, will default to traces containing all 0. num_samples: list[int] | int | None, default: None From adc40e6de25a3e001a4a2d0e1385fb18dec35b4a Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:23:17 +0100 Subject: [PATCH 16/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 10139918c2..d1f9ff97f3 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1694,7 +1694,7 @@ class InjectTemplatesRecording(BaseRecording): num_samples: list[int] | int | None, default: None The number of samples in the recording per segment. You can use int for mono-segment objects. - upsample_vector: np.array | None, default: None. + upsample_vector : np.array | None, default: None. When templates is 4d we can simulate a jitter. Optional the upsample_vector is the jitter index with a number per spike in range 0-templates.shape[3]. From 4c5d198b20806521b013c3ea9d37b067032edd03 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:23:32 +0100 Subject: [PATCH 17/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index d1f9ff97f3..3be5e166ab 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1708,11 +1708,11 @@ def __init__( self, sorting: BaseSorting, templates: np.ndarray, - nbefore: list[int] | int | None = None, - amplitude_factor: list[float] | float | None = None, - parent_recording: BaseRecording | None = None, - num_samples: list[int] | int | None = None, - upsample_vector: np.array | None = None, + nbefore : list[int] | int | None = None, + amplitude_factor : list[float] | float | None = None, + parent_recording : BaseRecording | None = None, + num_samples : list[int] | int | None = None, + upsample_vector : np.array | None = None, check_borders: bool = False, ) -> None: templates = np.asarray(templates) From a9400f999a73a7997c1160a90375d91210c1a5c0 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:23:47 +0100 Subject: [PATCH 18/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 3be5e166ab..6fc231f6f4 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1844,10 +1844,10 @@ def __init__( spike_vector: np.ndarray, templates: np.ndarray, nbefore: int, - amplitude_vector: list[float] | None, - upsample_vector: list[float] | None, - parent_recording_segment: BaseRecordingSegment | None = None, - num_samples: int | None = None, + amplitude_vector : list[float] | None, + upsample_vector : list[float] | None, + parent_recording_segment : BaseRecordingSegment | None = None, + num_samples : int | None = None, ) -> None: BaseRecordingSegment.__init__( self, From ef4d9e39440bb2f1924b2bba023a2f8d4ebc6c5a Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:24:01 +0100 Subject: [PATCH 19/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 6fc231f6f4..d51fe8101c 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1867,9 +1867,9 @@ def __init__( def get_traces( self, - start_frame: int | None = None, - end_frame: int | None = None, - channel_indices: list | None = None, + start_frame : int | None = None, + end_frame : int | None = None, + channel_indices : list | None = None, ) -> np.ndarray: if channel_indices is None: n_channels = self.templates.shape[2] From 6519ffa1e001f5abb37f07d88364af15665fb9c4 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:24:12 +0100 Subject: [PATCH 20/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index d51fe8101c..1098df8275 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -253,7 +253,7 @@ def generate_sorting_to_inject( num_samples: list of size num_segments. The number of samples in all the segments of the sorting, to generate spike times covering entire the entire duration of the segments. - max_injected_per_unit: int, default: 1000 + max_injected_per_unit : int, default: 1000 The maximal number of spikes injected per units. injected_rate: float, default: 0.05 The rate at which spikes are injected. From ab80c707be525130f5f50c33dddf1fa3868b08e0 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:24:27 +0100 Subject: [PATCH 21/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 1098df8275..68aa558543 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1089,11 +1089,11 @@ def __init__( self, num_channels: int, sampling_frequency: float, - durations: list[float], - noise_levels: float | np.array = 1.0, - cov_matrix: np.array | None = None, - dtype: np.dtype | str | None = "float32", - seed: int | None = None, + durations : list[float], + noise_levels : float | np.array = 1.0, + cov_matrix : np.array | None = None, + dtype : np.dtype | str | None = "float32", + seed : int | None = None, strategy: Literal["tile_pregenerated", "on_the_fly"] = "tile_pregenerated", noise_block_size: int = 30000, ): From 061a5fa47004c2aca2b5c0c28d6437a6e1af6d6a Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:24:42 +0100 Subject: [PATCH 22/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 68aa558543..c73954dcf5 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1064,7 +1064,7 @@ class NoiseGeneratorRecording(BaseRecording): The durations of each segment in seconds. Note that the length of this list is the number of segments. noise_levels: float or array, default: 1 Std of the white noise (if an array, defined by per channels) - cov_matrix: np.array | None, default: None + cov_matrix : np.array | None, default: None The covariance matrix of the noise dtype : np.dtype | str |None, default: "float32" The dtype of the recording. Note that only np.float32 and np.float64 are supported. From 34d09a9d9dd2b5db4213e0f2434ffd033d102ba0 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:24:53 +0100 Subject: [PATCH 23/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index c73954dcf5..b57767161f 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -255,7 +255,7 @@ def generate_sorting_to_inject( covering entire the entire duration of the segments. max_injected_per_unit : int, default: 1000 The maximal number of spikes injected per units. - injected_rate: float, default: 0.05 + injected_rate : float, default: 0.05 The rate at which spikes are injected. refractory_period_ms: float, default: 1.5 The refractory period that should not be violated while injecting new spikes. From 8257cd9a0783c48e93db69011d5960cc80ae1059 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:25:33 +0100 Subject: [PATCH 24/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index b57767161f..4abd407681 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -333,10 +333,10 @@ class TransformSorting(BaseSorting): def __init__( self, sorting: BaseSorting, - added_spikes_existing_units: np.array | None = None, - added_spikes_new_units: np.array | None = None, - new_unit_ids: list[str | int] | None = None, - refractory_period_ms: float | None = None, + added_spikes_existing_units : np.array | None = None, + added_spikes_new_units : np.array | None = None, + new_unit_ids : list[str | int] | None = None, + refractory_period_ms : float | None = None, ): sampling_frequency = sorting.get_sampling_frequency() unit_ids = list(sorting.get_unit_ids()) From c175b6b72563661a400752bece72e873e56e1abc Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:25:48 +0100 Subject: [PATCH 25/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 4abd407681..28cf7ec404 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -315,7 +315,7 @@ class TransformSorting(BaseSorting): The sorting object. added_spikes_existing_units : np.array (spike_vector) | None, default: None The spikes that should be added to the sorting object, for existing units. - added_spikes_new_units: np.array (spike_vector) | None, default: None + added_spikes_new_units : np.array (spike_vector) | None, default: None The spikes that should be added to the sorting object, for new units. new_units_ids: list[str, int] | None, default: None The unit_ids that should be added if spikes for new units are added. From 39d46a12aa14db08f23d18fe68f1b9a408be7bf3 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:26:04 +0100 Subject: [PATCH 26/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 28cf7ec404..09db185776 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -257,7 +257,7 @@ def generate_sorting_to_inject( The maximal number of spikes injected per units. injected_rate : float, default: 0.05 The rate at which spikes are injected. - refractory_period_ms: float, default: 1.5 + refractory_period_ms : float, default: 1.5 The refractory period that should not be violated while injecting new spikes. seed : int, default: None The random seed. From 16023bba5f325017f20a91fb4f6740edd9445ed5 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:26:19 +0100 Subject: [PATCH 27/33] space before colon Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 09db185776..57f79c87ae 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -317,7 +317,7 @@ class TransformSorting(BaseSorting): The spikes that should be added to the sorting object, for existing units. added_spikes_new_units : np.array (spike_vector) | None, default: None The spikes that should be added to the sorting object, for new units. - new_units_ids: list[str, int] | None, default: None + new_units_ids : list[str, int] | None, default: None The unit_ids that should be added if spikes for new units are added. refractory_period_ms : float | None, default: None The refractory period violation to prevent duplicates and/or unphysiological addition From 259562e2d554464a29bc68c944afc4ff3a9bbb65 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 15:29:32 +0000 Subject: [PATCH 28/33] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spikeinterface/core/generate.py | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 57f79c87ae..5749f31b10 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -333,10 +333,10 @@ class TransformSorting(BaseSorting): def __init__( self, sorting: BaseSorting, - added_spikes_existing_units : np.array | None = None, - added_spikes_new_units : np.array | None = None, - new_unit_ids : list[str | int] | None = None, - refractory_period_ms : float | None = None, + added_spikes_existing_units: np.array | None = None, + added_spikes_new_units: np.array | None = None, + new_unit_ids: list[str | int] | None = None, + refractory_period_ms: float | None = None, ): sampling_frequency = sorting.get_sampling_frequency() unit_ids = list(sorting.get_unit_ids()) @@ -1089,11 +1089,11 @@ def __init__( self, num_channels: int, sampling_frequency: float, - durations : list[float], - noise_levels : float | np.array = 1.0, - cov_matrix : np.array | None = None, - dtype : np.dtype | str | None = "float32", - seed : int | None = None, + durations: list[float], + noise_levels: float | np.array = 1.0, + cov_matrix: np.array | None = None, + dtype: np.dtype | str | None = "float32", + seed: int | None = None, strategy: Literal["tile_pregenerated", "on_the_fly"] = "tile_pregenerated", noise_block_size: int = 30000, ): @@ -1708,11 +1708,11 @@ def __init__( self, sorting: BaseSorting, templates: np.ndarray, - nbefore : list[int] | int | None = None, - amplitude_factor : list[float] | float | None = None, - parent_recording : BaseRecording | None = None, - num_samples : list[int] | int | None = None, - upsample_vector : np.array | None = None, + nbefore: list[int] | int | None = None, + amplitude_factor: list[float] | float | None = None, + parent_recording: BaseRecording | None = None, + num_samples: list[int] | int | None = None, + upsample_vector: np.array | None = None, check_borders: bool = False, ) -> None: templates = np.asarray(templates) @@ -1844,10 +1844,10 @@ def __init__( spike_vector: np.ndarray, templates: np.ndarray, nbefore: int, - amplitude_vector : list[float] | None, - upsample_vector : list[float] | None, - parent_recording_segment : BaseRecordingSegment | None = None, - num_samples : int | None = None, + amplitude_vector: list[float] | None, + upsample_vector: list[float] | None, + parent_recording_segment: BaseRecordingSegment | None = None, + num_samples: int | None = None, ) -> None: BaseRecordingSegment.__init__( self, @@ -1867,9 +1867,9 @@ def __init__( def get_traces( self, - start_frame : int | None = None, - end_frame : int | None = None, - channel_indices : list | None = None, + start_frame: int | None = None, + end_frame: int | None = None, + channel_indices: list | None = None, ) -> np.ndarray: if channel_indices is None: n_channels = self.templates.shape[2] From 67174c2893f4afaf767433bed223ba5906f7956f Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Mon, 22 Jul 2024 17:05:20 +0100 Subject: [PATCH 29/33] Add a few more fixes to docstrings. --- src/spikeinterface/core/generate.py | 185 +++++++++++++++------------- 1 file changed, 98 insertions(+), 87 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 57f79c87ae..a195b73aab 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -47,7 +47,7 @@ def generate_recording( durations : list[float], default: [5.0, 2.5] The duration in seconds of each segment in the recording, default: [5.0, 2.5]. Note that the number of segments is determined by the length of this list. - set_probe: bool | None, default: True + set_probe : bool | None, default: True ndim : int | None, default: 2 The number of dimensions of the probe, default: 2. Set to 3 to make 3 dimensional probe. seed : int | None, default: None @@ -188,7 +188,7 @@ def add_synchrony_to_sorting(sorting, sync_event_ratio=0.3, seed=None): ---------- sorting : BaseSorting The sorting object. - sync_event_ratio : float + sync_event_ratio : float, default: 0.3 The ratio of added synchronous spikes with respect to the total number of spikes. E.g., 0.5 means that the final sorting will have 1.5 times number of spikes, and all the extra spikes are synchronous (same sample_index), but on different units (not duplicates). @@ -250,7 +250,7 @@ def generate_sorting_to_inject( ---------- sorting : BaseSorting The sorting object. - num_samples: list of size num_segments. + num_samples : list[int] of size num_segments. The number of samples in all the segments of the sorting, to generate spike times covering entire the entire duration of the segments. max_injected_per_unit : int, default: 1000 @@ -333,10 +333,10 @@ class TransformSorting(BaseSorting): def __init__( self, sorting: BaseSorting, - added_spikes_existing_units : np.array | None = None, - added_spikes_new_units : np.array | None = None, - new_unit_ids : list[str | int] | None = None, - refractory_period_ms : float | None = None, + added_spikes_existing_units: np.array | None = None, + added_spikes_new_units: np.array | None = None, + new_unit_ids: list[str | int] | None = None, + refractory_period_ms: float | None = None, ): sampling_frequency = sorting.get_sampling_frequency() unit_ids = list(sorting.get_unit_ids()) @@ -428,9 +428,9 @@ def add_from_sorting(sorting1: BaseSorting, sorting2: BaseSorting, refractory_pe Parameters ---------- - sorting1: BaseSorting + sorting1 : BaseSorting The first sorting. - sorting2: BaseSorting + sorting2 : BaseSorting The second sorting. refractory_period_ms : float, default: None The refractory period violation to prevent duplicates and/or unphysiological addition @@ -484,7 +484,7 @@ def add_from_sorting(sorting1: BaseSorting, sorting2: BaseSorting, refractory_pe @staticmethod def add_from_unit_dict( - sorting1: BaseSorting, units_dict_list: dict, refractory_period_ms=None + sorting1: BaseSorting, units_dict_list: list[dict] | dict, refractory_period_ms=None ) -> "TransformSorting": """ Construct TransformSorting by adding one sorting with a @@ -494,9 +494,9 @@ def add_from_unit_dict( Parameters ---------- - sorting1: BaseSorting + sorting1 : BaseSorting The first sorting - dict_list: list of dict + dict_list : list[dict] | dict A list of dict with unit_ids as keys and spike times as values. refractory_period_ms : float, default: None The refractory period violation to prevent duplicates and/or unphysiological addition @@ -519,13 +519,15 @@ def from_times_labels( Parameters ---------- - sorting1: BaseSorting + sorting1 : BaseSorting The first sorting - times_list: list of array (or array) + times_list : list[np.array] | np.array An array of spike times (in frames). - labels_list: list of array (or array) + labels_list : list[np.array] | np.array An array of spike labels corresponding to the given times. - unit_ids: list or None, default: None + sampling_frequency : float, default: 30000. (in Hz) + The sampling frequency of the recording, default: 30000. + unit_ids : list | None, default: None The explicit list of unit_ids that should be extracted from labels_list If None, then it will be np.unique(labels_list). refractory_period_ms : float, default: None @@ -592,7 +594,7 @@ def generate_snippets( nafter=44, num_channels=2, wf_folder=None, - sampling_frequency=30000.0, # in Hz + sampling_frequency=30000.0, durations=[10.325, 3.5], #  in s for 2 segments set_probe=True, ndim=2, @@ -613,7 +615,7 @@ def generate_snippets( Number of channels. wf_folder : str | Path | None, default: None Optional folder to save the waveform snippets. If None, snippets are in memory. - sampling_frequency : float, default: 30000.0 + sampling_frequency : float, default: 30000.0 (in Hz) The sampling frequency of the snippets. ndim : int, default: 2 The number of dimensions of the probe. @@ -690,7 +692,7 @@ def synthesize_poisson_spike_vector( ---------- num_units : int, default: 20 Number of neuronal units to simulate. - sampling_frequency : float, default: 30000.0 + sampling_frequency : float, default: 30000.0 (in Hz) Sampling frequency in Hz. duration : float, default: 60.0 Duration of the simulation in seconds. @@ -793,20 +795,20 @@ def synthesize_random_firings( Parameters ---------- - num_units : int + num_units : int, default: 20 Number of units. - sampling_frequency : float + sampling_frequency : float, default: 30000.0 (in Hz) Sampling rate. - duration : float + duration : float, default: 60 Duration of the segment in seconds. - refractory_period_ms: float + refractory_period_ms : float, default: 4.0 Refractory period in ms. - firing_rates: float or list[float] + firing_rates : float or list[float], default: 3.0 The firing rate of each unit (in Hz). If float, all units will have the same firing rate. - add_shift_shuffle: bool, default: False + add_shift_shuffle : bool, default: False Optionally add a small shuffle on half of the spikes to make the autocorrelogram less flat. - seed: int, default: None + seed : int, default: None Seed for the generator. Returns @@ -899,12 +901,14 @@ def inject_some_duplicate_units(sorting, num=4, max_shift=5, ratio=None, seed=No ---------- sorting : Original sorting. - num : int + num : int, default: 4 Number of injected units. - max_shift : int + max_shift : int, default: 5 range of the shift in sample. - ratio: float + ratio : float | None, default: None Proportion of original spike in the injected units. + seed : int, default: None + Seed for the generator. Returns ------- @@ -1062,21 +1066,21 @@ class NoiseGeneratorRecording(BaseRecording): The sampling frequency of the recorder. durations : list[float] The durations of each segment in seconds. Note that the length of this list is the number of segments. - noise_levels: float or array, default: 1 + noise_levels : float | np.array, default: 1.0 Std of the white noise (if an array, defined by per channels) cov_matrix : np.array | None, default: None The covariance matrix of the noise - dtype : np.dtype | str |None, default: "float32" + dtype : np.dtype | str | None, default: "float32" The dtype of the recording. Note that only np.float32 and np.float64 are supported. seed : int | None, default: None The seed for np.random.default_rng. - strategy : "tile_pregenerated" or "on_the_fly" + strategy : "tile_pregenerated" | "on_the_fly", default: "tile_pregenerated" The strategy of generating noise chunk: * "tile_pregenerated": pregenerate a noise chunk of noise_block_size sample and repeat it very fast and cusume only one noise block. * "on_the_fly": generate on the fly a new noise block by combining seed + noise block index no memory preallocation but a bit more computaion (random) - noise_block_size: int + noise_block_size : int, default: 30000 Size in sample of noise block. Note @@ -1089,11 +1093,11 @@ def __init__( self, num_channels: int, sampling_frequency: float, - durations : list[float], - noise_levels : float | np.array = 1.0, - cov_matrix : np.array | None = None, - dtype : np.dtype | str | None = "float32", - seed : int | None = None, + durations: list[float], + noise_levels: float | np.array = 1.0, + cov_matrix: np.array | None = None, + dtype: np.dtype | str | None = "float32", + seed: int | None = None, strategy: Literal["tile_pregenerated", "on_the_fly"] = "tile_pregenerated", noise_block_size: int = 30000, ): @@ -1277,11 +1281,14 @@ def generate_recording_by_size( ---------- full_traces_size_GiB : float The size in gigabytes (GiB) of the recording. - num_channels: int - Number of channels. seed : int | None, default: None The seed for np.random.default_rng. - + strategy : "tile_pregenerated" | "on_the_fly", default: "tile_pregenerated" + The strategy of generating noise chunk: + * "tile_pregenerated": pregenerate a noise chunk of noise_block_size sample and repeat it + very fast and cusume only one noise block. + * "on_the_fly": generate on the fly a new noise block by combining seed + noise block index + no memory preallocation but a bit more computaion (random) Returns ------- GeneratorRecording @@ -1517,25 +1524,25 @@ def generate_templates( Parameters ---------- - channel_locations: np.ndarray + channel_locations : np.ndarray Channel locations. - units_locations: np.ndarray + units_locations : np.ndarray Must be 3D. - sampling_frequency: float + sampling_frequency : float Sampling frequency. - ms_before: float + ms_before : float Cut out in ms before spike peak. - ms_after: float + ms_after : float Cut out in ms after spike peak. - seed: int or None + seed : int | None A seed for random. - dtype: numpy.dtype, default: "float32" + dtype : numpy.dtype, default: "float32" Templates dtype - upsample_factor: None or int + upsample_factor : int | None, default: None If not None then template are generated upsampled by this factor. Then a new dimention (axis=3) is added to the template with intermediate inter sample representation. This allow easy random jitter by choising a template this new dim - unit_params: dict of arrays or dict of scalar of dict of tuple + unit_params : dict[np.array] | dict[float] | dict[tuple] | None, default: None An optional dict containing parameters per units. Keys are parameter names: @@ -1552,6 +1559,10 @@ def generate_templates( * array of the same length of units * scalar, then an array is created * tuple, then this difine a range for random values. + mode : "ellipsoid" | "sphere", default: "ellipsoid" + Method used to calculate the distance between unit and channel location. + Ellipoid injects some anisotropy dependent on unit shape, sphere is equivalent + to Euclidean distance. Returns ------- @@ -1672,18 +1683,18 @@ class InjectTemplatesRecording(BaseRecording): Parameters ---------- - sorting: BaseSorting + sorting : BaseSorting Sorting object containing all the units and their spike train. - templates: np.ndarray[n_units, n_samples, n_channels] or np.ndarray[n_units, n_samples, n_oversampling] + templates : np.ndarray[n_units, n_samples, n_channels] | np.ndarray[n_units, n_samples, n_oversampling] Array containing the templates to inject for all the units. Shape can be: * (num_units, num_samples, num_channels): standard case * (num_units, num_samples, num_channels, upsample_factor): case with oversample template to introduce sampling jitter. - nbefore: list[int] | int | None, default: None + nbefore : list[int] | int | None, default: None The number of samples before the peak of the template to align the spike. If None, will default to the highest peak. - amplitude_factor: list[float] | float | None, default: None + amplitude_factor : list[float] | float | None, default: None The amplitude of each spike for each unit. Can be None (no scaling). Can be scalar all spikes have the same factor (certainly useless). @@ -1691,7 +1702,7 @@ class InjectTemplatesRecording(BaseRecording): parent_recording : BaseRecording | None, default: None The recording over which to add the templates. If None, will default to traces containing all 0. - num_samples: list[int] | int | None, default: None + num_samples : list[int] | int | None, default: None The number of samples in the recording per segment. You can use int for mono-segment objects. upsample_vector : np.array | None, default: None. @@ -1708,11 +1719,11 @@ def __init__( self, sorting: BaseSorting, templates: np.ndarray, - nbefore : list[int] | int | None = None, - amplitude_factor : list[float] | float | None = None, - parent_recording : BaseRecording | None = None, - num_samples : list[int] | int | None = None, - upsample_vector : np.array | None = None, + nbefore: list[int] | int | None = None, + amplitude_factor: list[float] | float | None = None, + parent_recording: BaseRecording | None = None, + num_samples: list[int] | int | None = None, + upsample_vector: np.array | None = None, check_borders: bool = False, ) -> None: templates = np.asarray(templates) @@ -1844,10 +1855,10 @@ def __init__( spike_vector: np.ndarray, templates: np.ndarray, nbefore: int, - amplitude_vector : list[float] | None, - upsample_vector : list[float] | None, - parent_recording_segment : BaseRecordingSegment | None = None, - num_samples : int | None = None, + amplitude_vector: list[float] | None, + upsample_vector: list[float] | None, + parent_recording_segment: BaseRecordingSegment | None = None, + num_samples: int | None = None, ) -> None: BaseRecordingSegment.__init__( self, @@ -1867,9 +1878,9 @@ def __init__( def get_traces( self, - start_frame : int | None = None, - end_frame : int | None = None, - channel_indices : list | None = None, + start_frame: int | None = None, + end_frame: int | None = None, + channel_indices: list | None = None, ) -> np.ndarray: if channel_indices is None: n_channels = self.templates.shape[2] @@ -2040,55 +2051,55 @@ def generate_ground_truth_recording( Parameters ---------- - durations: list of float, default: [10.] + durations : list[float], default: [10.] Durations in seconds for all segments. - sampling_frequency: float, default: 25000 + sampling_frequency : float, default: 25000.0 Sampling frequency. - num_channels: int, default: 4 + num_channels : int, default: 4 Number of channels, not used when probe is given. - num_units: int, default: 10 + num_units : int, default: 10 Number of units, not used when sorting is given. - sorting: Sorting or None + sorting : Sorting | None An external sorting object. If not provide, one is genrated. - probe: Probe or None + probe : Probe | None An external Probe object. If not provided a probe is generated using generate_probe_kwargs. - generate_probe_kwargs: dict + generate_probe_kwargs : dict A dict to constuct the Probe using :py:func:`probeinterface.generate_multi_columns_probe()`. - templates: np.array or None + templates : np.array | None The templates of units. If None they are generated. Shape can be: * (num_units, num_samples, num_channels): standard case * (num_units, num_samples, num_channels, upsample_factor): case with oversample template to introduce jitter. - ms_before: float, default: 1.5 + ms_before : float, default: 1.5 Cut out in ms before spike peak. - ms_after: float, default: 3 + ms_after : float, default: 3 Cut out in ms after spike peak. - upsample_factor: None or int, default: None + upsample_factor : None | int, default: None A upsampling factor used only when templates are not provided. - upsample_vector: np.array or None + upsample_vector : np.array | None Optional the upsample_vector can given. This has the same shape as spike_vector - generate_sorting_kwargs: dict + generate_sorting_kwargs : dict When sorting is not provide, this dict is used to generated a Sorting. - noise_kwargs: dict + noise_kwargs : dict Dict used to generated the noise with NoiseGeneratorRecording. - generate_unit_locations_kwargs: dict + generate_unit_locations_kwargs : dict Dict used to generated template when template not provided. - generate_templates_kwargs: dict + generate_templates_kwargs : dict Dict used to generated template when template not provided. - dtype: np.dtype, default: "float32" + dtype : np.dtype, default: "float32" The dtype of the recording. - seed: int or None + seed : int | None Seed for random initialization. If None a diffrent Recording is generated at every call. Note: even with None a generated recording keep internaly a seed to regenerate the same signal after dump/load. Returns ------- - recording: Recording + recording : Recording The generated recording extractor. - sorting: Sorting + sorting : Sorting The generated sorting extractor. """ generate_templates_kwargs = generate_templates_kwargs or dict() From 535fe17e83872d983ef5fe96abde34c944d74a1d Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:04:46 +0100 Subject: [PATCH 30/33] typo fix Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index a195b73aab..d2a5f98fe8 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1561,7 +1561,7 @@ def generate_templates( * tuple, then this difine a range for random values. mode : "ellipsoid" | "sphere", default: "ellipsoid" Method used to calculate the distance between unit and channel location. - Ellipoid injects some anisotropy dependent on unit shape, sphere is equivalent + Ellipsoid injects some anisotropy dependent on unit shape, sphere is equivalent to Euclidean distance. Returns From e7ce974fe0f9e5fc72b8ebe708e58ac5371e120f Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:05:03 +0100 Subject: [PATCH 31/33] typo fix Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index d2a5f98fe8..09965b4550 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1286,7 +1286,7 @@ def generate_recording_by_size( strategy : "tile_pregenerated" | "on_the_fly", default: "tile_pregenerated" The strategy of generating noise chunk: * "tile_pregenerated": pregenerate a noise chunk of noise_block_size sample and repeat it - very fast and cusume only one noise block. + very fast and consume only one noise block. * "on_the_fly": generate on the fly a new noise block by combining seed + noise block index no memory preallocation but a bit more computaion (random) Returns From c7b5aa6810ab9019b54e10aef973d62a31f015e1 Mon Sep 17 00:00:00 2001 From: Joe Ziminski <55797454+JoeZiminski@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:05:15 +0100 Subject: [PATCH 32/33] typo fix Co-authored-by: Zach McKenzie <92116279+zm711@users.noreply.github.com> --- src/spikeinterface/core/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index 09965b4550..b2ffdcd88a 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -1288,7 +1288,7 @@ def generate_recording_by_size( * "tile_pregenerated": pregenerate a noise chunk of noise_block_size sample and repeat it very fast and consume only one noise block. * "on_the_fly": generate on the fly a new noise block by combining seed + noise block index - no memory preallocation but a bit more computaion (random) + no memory preallocation but a bit more computation (random) Returns ------- GeneratorRecording From 92ea6093e2312e60212798089dc552e6b2f15d21 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Wed, 24 Jul 2024 15:10:39 +0100 Subject: [PATCH 33/33] Move 'in Hz' to description for sampling frequency docstring. --- src/spikeinterface/core/generate.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/spikeinterface/core/generate.py b/src/spikeinterface/core/generate.py index b2ffdcd88a..73a159380c 100644 --- a/src/spikeinterface/core/generate.py +++ b/src/spikeinterface/core/generate.py @@ -42,8 +42,8 @@ def generate_recording( ---------- num_channels : int, default: 2 The number of channels in the recording. - sampling_frequency : float, default: 30000. (in Hz) - The sampling frequency of the recording, default: 30000. + sampling_frequency : float, default: 30000.0 + The sampling frequency of the recording in Hz durations : list[float], default: [5.0, 2.5] The duration in seconds of each segment in the recording, default: [5.0, 2.5]. Note that the number of segments is determined by the length of this list. @@ -105,7 +105,7 @@ def generate_sorting( num_units : int, default: 5 Number of units. sampling_frequency : float, default: 30000.0 - The sampling frequency. + The sampling frequency of the recording in Hz. durations : list, default: [10.325, 3.5] Duration of each segment in s. firing_rates : float, default: 3.0 @@ -525,8 +525,8 @@ def from_times_labels( An array of spike times (in frames). labels_list : list[np.array] | np.array An array of spike labels corresponding to the given times. - sampling_frequency : float, default: 30000. (in Hz) - The sampling frequency of the recording, default: 30000. + sampling_frequency : float, default: 30000.0 + The sampling frequency of the recording in Hz. unit_ids : list | None, default: None The explicit list of unit_ids that should be extracted from labels_list If None, then it will be np.unique(labels_list). @@ -615,8 +615,8 @@ def generate_snippets( Number of channels. wf_folder : str | Path | None, default: None Optional folder to save the waveform snippets. If None, snippets are in memory. - sampling_frequency : float, default: 30000.0 (in Hz) - The sampling frequency of the snippets. + sampling_frequency : float, default: 30000.0 + The sampling frequency of the snippets in Hz. ndim : int, default: 2 The number of dimensions of the probe. num_units : int, default: 5 @@ -692,7 +692,7 @@ def synthesize_poisson_spike_vector( ---------- num_units : int, default: 20 Number of neuronal units to simulate. - sampling_frequency : float, default: 30000.0 (in Hz) + sampling_frequency : float, default: 30000.0 Sampling frequency in Hz. duration : float, default: 60.0 Duration of the simulation in seconds. @@ -797,8 +797,8 @@ def synthesize_random_firings( ---------- num_units : int, default: 20 Number of units. - sampling_frequency : float, default: 30000.0 (in Hz) - Sampling rate. + sampling_frequency : float, default: 30000.0 + Sampling rate in Hz. duration : float, default: 60 Duration of the segment in seconds. refractory_period_ms : float, default: 4.0