From 0cf2db6c5ec645c124d2b8b5e861d43627fa4970 Mon Sep 17 00:00:00 2001 From: Jim Paris Date: Fri, 14 Feb 2014 15:55:42 -0500 Subject: [PATCH] Fix divide by zero in sinefit --- nilmtools/sinefit.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nilmtools/sinefit.py b/nilmtools/sinefit.py index 850e66c..6fd28b4 100755 --- a/nilmtools/sinefit.py +++ b/nilmtools/sinefit.py @@ -96,8 +96,11 @@ def process(data, interval, args, insert_function, final): rows = data.shape[0] # Estimate sampling frequency from timestamps - fs = (rows-1) / (timestamp_to_seconds(data[-1][0]) - - timestamp_to_seconds(data[0][0])) + ts_min = timestamp_to_seconds(data[0][0]) + ts_max = timestamp_to_seconds(data[-1][0]) + if ts_min >= ts_max: + return 0 + fs = (rows-1) / (ts_max - ts_min) # Pull out about 3.5 periods of data at once; # we'll expect to match 3 zero crossings in each window