From 97846ac6b1f11345280d004a656f04cd7a8e5cdd Mon Sep 17 00:00:00 2001 From: Ruben Verweij Date: Sat, 5 Jan 2019 12:48:48 +0100 Subject: [PATCH] Fix fps calculation --- nd2reader/reader.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nd2reader/reader.py b/nd2reader/reader.py index c2ffcc5..4f3acf2 100644 --- a/nd2reader/reader.py +++ b/nd2reader/reader.py @@ -114,7 +114,15 @@ class ND2Reader(FramesSequenceND): Returns: float: the (average) frame rate in frames per second """ - return 1000. / np.mean(np.diff(self.timesteps)) + total_duration = 0.0 + + for loop in self.metadata['experiment']['loops']: + total_duration += loop['duration'] + + if total_duration == 0: + raise ValueError('Total measurement duration could not be determined from loops') + + return self.metadata['num_frames'] / (total_duration/1000.0) def _get_metadata_property(self, key, default=None): if self.metadata is None: