Skip to content

Commit

Permalink
Merge pull request #3363 from alejoe91/reset-times
Browse files Browse the repository at this point in the history
Add `BaseRecording.reset_times()` function
  • Loading branch information
alejoe91 authored Sep 5, 2024
2 parents 584c2ae + 7d50fc5 commit 8aaf19c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/spikeinterface/core/baserecording.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,18 @@ def set_times(self, times, segment_index=None, with_warning=True):
"Use this carefully!"
)

def reset_times(self):
"""
Reset times 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.
"""
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

def sample_index_to_time(self, sample_ind, segment_index=None):
"""
Transform sample index into time in seconds
Expand Down
5 changes: 5 additions & 0 deletions src/spikeinterface/core/tests/test_baserecording.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ def test_BaseRecording(create_cache_folder):
rec3 = load_extractor(folder)
assert np.allclose(times1, rec3.get_times(1))

# reset times
rec.reset_times()
for segm in range(num_seg):
assert not rec.has_time_vector(segment_index=segm)

# test 3d probe
rec_3d = generate_recording(ndim=3, num_channels=30)
locations_3d = rec_3d.get_property("location")
Expand Down

0 comments on commit 8aaf19c

Please sign in to comment.