@@ -59,7 +59,7 @@ def __repr__(self):
5959 if num_segments > 1 :
6060 samples_per_segment = [self .get_num_samples (segment_index ) for segment_index in range (num_segments )]
6161 memory_per_segment_bytes = (self .get_memory_size (segment_index ) for segment_index in range (num_segments ))
62- durations = [self .get_duration (segment_index , use_times = False ) for segment_index in range (num_segments )]
62+ durations = [self .get_duration (segment_index ) for segment_index in range (num_segments )]
6363
6464 samples_per_segment_formated = [f"{ samples :,} " for samples in samples_per_segment ]
6565 durations_per_segment_formated = [convert_seconds_to_str (d ) for d in durations ]
@@ -95,7 +95,7 @@ def _repr_header(self):
9595 dtype = self .get_dtype ()
9696
9797 total_samples = self .get_total_samples ()
98- total_duration = self .get_total_duration (use_times = False )
98+ total_duration = self .get_total_duration ()
9999 total_memory_size = self .get_total_memory_size ()
100100
101101 sf_hz = self .get_sampling_frequency ()
@@ -216,7 +216,7 @@ def get_total_samples(self) -> int:
216216
217217 return sum (samples_per_segment )
218218
219- def get_duration (self , segment_index = None , use_times = True ) -> float :
219+ def get_duration (self , segment_index = None ) -> float :
220220 """
221221 Returns the duration in seconds.
222222
@@ -226,44 +226,27 @@ def get_duration(self, segment_index=None, use_times=True) -> float:
226226 The sample index to retrieve the duration for.
227227 For multi-segment objects, it is required, default: None
228228 With single segment recording returns the duration of the single segment
229- use_times : bool, default: True
230- If True, the duration is calculated using the time vector if available.
231- If False, the duration is calculated using the number of samples and the sampling frequency.
232229
233230 Returns
234231 -------
235232 float
236233 The duration in seconds
237234 """
238- segment_index = self ._check_segment_index (segment_index )
239-
240- if self .has_time_vector (segment_index ) and use_times :
241- times = self .get_times (segment_index )
242- segment_duration = times [- 1 ] - times [0 ] + (1 / self .get_sampling_frequency ())
243- else :
244- segment_num_samples = self .get_num_samples (segment_index = segment_index )
245- segment_duration = segment_num_samples / self .get_sampling_frequency ()
246-
235+ segment_duration = (
236+ self .get_stop_time (segment_index ) - self .get_start_time (segment_index ) + (1 / self .get_sampling_frequency ())
237+ )
247238 return segment_duration
248239
249- def get_total_duration (self , use_times = True ) -> float :
240+ def get_total_duration (self ) -> float :
250241 """
251242 Returns the total duration in seconds
252243
253- Parameters
254- ----------
255- use_times : bool, default: True
256- If True, the duration is calculated using the time vector if available.
257- If False, the duration is calculated using the number of samples and the sampling frequency.
258-
259244 Returns
260245 -------
261246 float
262247 The duration in seconds
263248 """
264- duration = sum (
265- [self .get_duration (segment_index , use_times ) for segment_index in range (self .get_num_segments ())]
266- )
249+ duration = sum ([self .get_duration (segment_index ) for segment_index in range (self .get_num_segments ())])
267250 return duration
268251
269252 def get_memory_size (self , segment_index = None ) -> int :
@@ -456,6 +439,40 @@ def get_times(self, segment_index=None) -> np.ndarray:
456439 times = rs .get_times ()
457440 return times
458441
442+ def get_start_time (self , segment_index = None ) -> float :
443+ """Get the start time of the recording segment.
444+
445+ Parameters
446+ ----------
447+ segment_index : int or None, default: None
448+ The segment index (required for multi-segment)
449+
450+ Returns
451+ -------
452+ float
453+ The start time in seconds
454+ """
455+ segment_index = self ._check_segment_index (segment_index )
456+ rs = self ._recording_segments [segment_index ]
457+ return rs .get_start_time ()
458+
459+ def get_stop_time (self , segment_index = None ) -> float :
460+ """Get the stop time of the recording segment.
461+
462+ Parameters
463+ ----------
464+ segment_index : int or None, default: None
465+ The segment index (required for multi-segment)
466+
467+ Returns
468+ -------
469+ float
470+ The stop time in seconds
471+ """
472+ segment_index = self ._check_segment_index (segment_index )
473+ rs = self ._recording_segments [segment_index ]
474+ return rs .get_stop_time ()
475+
459476 def has_time_vector (self , segment_index = None ):
460477 """Check if the segment of the recording has a time vector.
461478
@@ -914,6 +931,21 @@ def get_times(self) -> np.ndarray:
914931 time_vector += self .t_start
915932 return time_vector
916933
934+ def get_start_time (self ) -> float :
935+ if self .time_vector is not None :
936+ return self .time_vector [0 ]
937+ else :
938+ return self .t_start if self .t_start is not None else 0.0
939+
940+ def get_stop_time (self ) -> float :
941+ if self .time_vector is not None :
942+ return self .time_vector [- 1 ]
943+ else :
944+ t_stop = self .get_num_samples () / self .sampling_frequency
945+ if self .t_start is not None :
946+ t_stop += self .t_start
947+ return t_stop
948+
917949 def get_times_kwargs (self ) -> dict :
918950 """
919951 Retrieves the timing attributes characterizing a RecordingSegment
0 commit comments