@@ -458,12 +458,26 @@ def has_time_vector(self, segment_index=None):
458
458
return d ["time_vector" ] is not None
459
459
460
460
def set_times (self , times , segment_index = None , with_warning = True ):
461
- """Set times for a recording segment.
461
+ """Set times for a recording segment. Any existing times
462
+ will be overwritten.
463
+
464
+ Times can be manually set on the recording segment. If times are
465
+ not set, the sample index and sampling frequency are used to
466
+ calculate time. Otherwise, `t_start` or `time_vector` can be
467
+ provided:
468
+
469
+ `t_start` - the start time for the segment. The times for
470
+ this recording segment will be calculated as
471
+ t_start + sample_index * (1 / sampling_frequency)
472
+
473
+ `time_vector` - A vector of length segment.get_num_samples()
474
+ that holds the exact time for each sample in the recording.
462
475
463
476
Parameters
464
477
----------
465
- times : 1d np.array
466
- The time vector
478
+ times : float | 1d np.array
479
+ If `int`, this is the `t_start` for the segment,
480
+ otherwise, it is the time vector.
467
481
segment_index : int or None, default: None
468
482
The segment index (required for multi-segment)
469
483
with_warning : bool, default: True
@@ -472,11 +486,18 @@ def set_times(self, times, segment_index=None, with_warning=True):
472
486
segment_index = self ._check_segment_index (segment_index )
473
487
rs = self ._recording_segments [segment_index ]
474
488
475
- assert times .ndim == 1 , "Time must have ndim=1"
476
- assert rs .get_num_samples () == times .shape [0 ], "times have wrong shape"
489
+ if isinstance (times , float ) or isinstance (times , int ):
490
+ rs .t_start = times
491
+ rs .time_vector = None
492
+ elif isinstance (times , np .ndarray ):
477
493
478
- rs .t_start = None
479
- rs .time_vector = times .astype ("float64" , copy = False )
494
+ assert times .ndim == 1 , "Time must have ndim=1"
495
+ assert rs .get_num_samples () == times .shape [0 ], "times have wrong shape"
496
+
497
+ rs .t_start = None
498
+ rs .time_vector = times .astype ("float64" , copy = False )
499
+ else :
500
+ raise TypeError ("`times` must be an integer / float (`t_start`) or " "numpy array (`time_vector`)." )
480
501
481
502
if with_warning :
482
503
warnings .warn (
0 commit comments