From ea9950a003b9301a90f5c1f0a81a2628ea9ef7e8 Mon Sep 17 00:00:00 2001 From: Tom Chartrand Date: Mon, 14 Sep 2020 13:28:36 -0700 Subject: [PATCH] fix segment length rounding error --- ipfx/x_to_nwb/hr_segments.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ipfx/x_to_nwb/hr_segments.py b/ipfx/x_to_nwb/hr_segments.py index 727480e1..1668d9f7 100644 --- a/ipfx/x_to_nwb/hr_segments.py +++ b/ipfx/x_to_nwb/hr_segments.py @@ -159,7 +159,11 @@ def calculateNumberOfPoints(self, duration): """ Return the number of points of this segment. """ - return math.trunc(duration / self.sampleInterval) + num_points = duration / self.sampleInterval + num_points_int = int(np.round(num_points)) + if not math.isclose(num_points, num_points_int): + raise ValueError(f"Segment duration {duration} is not divisible by sample interval {self.sampleInterval}") + return num_points_int def getAmplitude(self, channelRec, segmentRec): """