Skip to content

Commit

Permalink
improve error on timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
h-mayorquin committed Oct 18, 2024
1 parent 2cf9235 commit 703b55f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/roiextractors/imagingextractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,24 @@ def set_times(self, times: ArrayType) -> None:
Parameters
----------
times: array-like
The times in seconds for each frame
The times in seconds for each frame.
Raises
------
ValueError
If the length of 'times' does not match the number of frames.
"""
assert len(times) == self.get_num_frames(), "'times' should have the same length of the number of frames!"
self._times = np.array(times).astype("float64")
num_frames = self.get_num_frames()
num_timestamps = len(times)

if num_timestamps != num_frames:
raise ValueError(
f"Mismatch between the number of frames and timestamps: "
f"{num_frames} frames, but {num_timestamps} timestamps provided. "
"Ensure the length of 'times' matches the number of frames."
)

self._times = np.array(times).astype("float64", copy=False)

def has_time_vector(self) -> bool:
"""Detect if the ImagingExtractor has a time vector set or not.
Expand Down

0 comments on commit 703b55f

Please sign in to comment.