Skip to content

Commit

Permalink
Add time vector case to 'get_durations'.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZiminski committed Jul 1, 2024
1 parent 9167040 commit acd57a6
Showing 1 changed file with 9 additions and 3 deletions.
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())
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 self.get_num_segments()])
return duration

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

0 comments on commit acd57a6

Please sign in to comment.