From acd57a68289bd1cd5b726aa8f50ec6a55af23a76 Mon Sep 17 00:00:00 2001 From: JoeZiminski Date: Mon, 1 Jul 2024 21:21:42 +0100 Subject: [PATCH] Add time vector case to 'get_durations'. --- src/spikeinterface/core/baserecording.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/spikeinterface/core/baserecording.py b/src/spikeinterface/core/baserecording.py index 734135368b..7d5427c435 100644 --- a/src/spikeinterface/core/baserecording.py +++ b/src/spikeinterface/core/baserecording.py @@ -233,8 +233,14 @@ def get_duration(self, segment_index=None) -> float: The duration in seconds """ segment_index = self._check_segment_index(segment_index) - segment_num_samples = self.get_num_samples(segment_index=segment_index) - segment_duration = segment_num_samples / self.get_sampling_frequency() + + if self.has_time_vector(segment_index): + times = self.get_times(segment_index) + segment_duration = times[-1] - times[0] + (1 / self.get_sampling_frequency()) + else: + segment_num_samples = self.get_num_samples(segment_index=segment_index) + segment_duration = segment_num_samples / self.get_sampling_frequency() + return segment_duration def get_total_duration(self) -> float: @@ -246,7 +252,7 @@ def get_total_duration(self) -> float: float The duration in seconds """ - duration = self.get_total_samples() / self.get_sampling_frequency() + duration = sum([self.get_duration(idx) for idx in self.get_num_segments()]) return duration def get_memory_size(self, segment_index=None) -> int: