From 1fc89b4a128f4584fc560f963200b076734d2654 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Fri, 6 Sep 2024 19:33:33 +0200 Subject: [PATCH 1/2] Reset-times: segment must have either time vector or sampling frequency --- src/spikeinterface/core/baserecording.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/spikeinterface/core/baserecording.py b/src/spikeinterface/core/baserecording.py index f7918be7b0..225f070d9d 100644 --- a/src/spikeinterface/core/baserecording.py +++ b/src/spikeinterface/core/baserecording.py @@ -506,6 +506,7 @@ def reset_times(self): rs = self._recording_segments[segment_index] rs.t_start = None rs.time_vector = None + rs.sampling_frequency = self.sampling_frequency def sample_index_to_time(self, sample_ind, segment_index=None): """ From a3fef7055d3702481cee99f17821f910b84921c3 Mon Sep 17 00:00:00 2001 From: Alessio Buccino Date: Mon, 9 Sep 2024 17:54:01 +0200 Subject: [PATCH 2/2] Reset times also sets t_start to None --- src/spikeinterface/core/baserecording.py | 9 +++++---- src/spikeinterface/core/tests/test_baserecording.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/spikeinterface/core/baserecording.py b/src/spikeinterface/core/baserecording.py index 225f070d9d..3e5e43b528 100644 --- a/src/spikeinterface/core/baserecording.py +++ b/src/spikeinterface/core/baserecording.py @@ -497,16 +497,17 @@ def set_times(self, times, segment_index=None, with_warning=True): def reset_times(self): """ - Reset times in-memory for all segments that have a time vector. + Reset time information in-memory for all segments that have a time vector. If the timestamps come from a file, the files won't be modified. but only the in-memory - attributes of the recording objects are deleted. + attributes of the recording objects are deleted. Also `t_start` is set to None and the + segment's sampling frequency is set to the recording's sampling frequency. """ for segment_index in range(self.get_num_segments()): if self.has_time_vector(segment_index): rs = self._recording_segments[segment_index] - rs.t_start = None rs.time_vector = None - rs.sampling_frequency = self.sampling_frequency + rs.t_start = None + rs.sampling_frequency = self.sampling_frequency def sample_index_to_time(self, sample_ind, segment_index=None): """ diff --git a/src/spikeinterface/core/tests/test_baserecording.py b/src/spikeinterface/core/tests/test_baserecording.py index 3758fc3b43..9c354510ac 100644 --- a/src/spikeinterface/core/tests/test_baserecording.py +++ b/src/spikeinterface/core/tests/test_baserecording.py @@ -292,7 +292,11 @@ def test_BaseRecording(create_cache_folder): # reset times rec.reset_times() for segm in range(num_seg): + time_info = rec.get_time_info(segment_index=segm) assert not rec.has_time_vector(segment_index=segm) + assert time_info["t_start"] is None + assert time_info["time_vector"] is None + assert time_info["sampling_frequency"] == rec.sampling_frequency # test 3d probe rec_3d = generate_recording(ndim=3, num_channels=30)