From c1239397b9bec50acf06c8b3cbc11ee93861786f Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Tue, 20 Aug 2024 15:14:12 +0200 Subject: [PATCH 1/2] Lazy loading of zarr timestamps --- src/spikeinterface/core/baserecording.py | 7 +++---- src/spikeinterface/core/zarrextractors.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/spikeinterface/core/baserecording.py b/src/spikeinterface/core/baserecording.py index e65afabaca..efa6d03f56 100644 --- a/src/spikeinterface/core/baserecording.py +++ b/src/spikeinterface/core/baserecording.py @@ -811,10 +811,9 @@ def __init__(self, sampling_frequency=None, t_start=None, time_vector=None): def get_times(self): if self.time_vector is not None: - if isinstance(self.time_vector, np.ndarray): - return self.time_vector - else: - return np.array(self.time_vector) + if not isinstance(self.time_vector, np.ndarray): + self.time_vector = np.array(self.time_vector) + return self.time_vector else: time_vector = np.arange(self.get_num_samples(), dtype="float64") time_vector /= self.sampling_frequency diff --git a/src/spikeinterface/core/zarrextractors.py b/src/spikeinterface/core/zarrextractors.py index 1b9637e097..17f1ac08b3 100644 --- a/src/spikeinterface/core/zarrextractors.py +++ b/src/spikeinterface/core/zarrextractors.py @@ -66,7 +66,7 @@ def __init__(self, folder_path: Path | str, storage_options: dict | None = None) time_kwargs = {} time_vector = self._root.get(f"times_seg{segment_index}", None) if time_vector is not None: - time_kwargs["time_vector"] = time_vector[:] + time_kwargs["time_vector"] = time_vector else: if t_starts is None: t_start = None From 522260cdda14ffab5a49675bf63b9bc8c44cbec5 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Tue, 20 Aug 2024 18:51:20 +0200 Subject: [PATCH 2/2] asarray and annotations --- src/spikeinterface/core/baserecording.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/core/baserecording.py b/src/spikeinterface/core/baserecording.py index efa6d03f56..dbec8a3730 100644 --- a/src/spikeinterface/core/baserecording.py +++ b/src/spikeinterface/core/baserecording.py @@ -422,7 +422,7 @@ def get_time_info(self, segment_index=None) -> dict: return time_kwargs - def get_times(self, segment_index=None): + def get_times(self, segment_index=None) -> np.ndarray: """Get time vector for a recording segment. If the segment has a time_vector, then it is returned. Otherwise @@ -809,10 +809,9 @@ def __init__(self, sampling_frequency=None, t_start=None, time_vector=None): BaseSegment.__init__(self) - def get_times(self): + def get_times(self) -> np.ndarray: if self.time_vector is not None: - if not isinstance(self.time_vector, np.ndarray): - self.time_vector = np.array(self.time_vector) + self.time_vector = np.asarray(self.time_vector) return self.time_vector else: time_vector = np.arange(self.get_num_samples(), dtype="float64")