Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time vector case to get_durations. #3118

12 changes: 9 additions & 3 deletions src/spikeinterface/core/baserecording.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved
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:
Expand All @@ -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 range(self.get_num_segments())])
return duration

def get_memory_size(self, segment_index=None) -> int:
Expand Down
Loading