From 79b4c1032fdb6e4e35fed3892a5a26aeca51d970 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 9 Nov 2020 20:36:24 +0100 Subject: [PATCH] some error checking in getfastest --- rowers/datautils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rowers/datautils.py b/rowers/datautils.py index dda402c0..68efe7a5 100644 --- a/rowers/datautils.py +++ b/rowers/datautils.py @@ -365,11 +365,17 @@ def getmaxwattinterval(tt,ww,i): return deltat,wmax -def getfastest(df,thedistance): +def getfastest(df,thevalue,mode='distance'): tt = df['time'].copy() dd = df['cumdist'].copy() tmax = tt.max() + if mode == 'distance': + if dd.max() > thevalue: + return 0 + else: + if tt.max() > thevalue: + return 0 if tmax > 500000: newlen=int(tmax/2000.) @@ -412,6 +418,10 @@ def getfastest(df,thedistance): restime = np.array(restime) distance = np.array(distance) - d2 = griddata(distance,restime,[thedistance],method='linear',rescale=True) + d2 = 0 + if mode == 'distance': + d2 = griddata(distance,restime,[thevalue],method='linear',rescale=True) + else: + d2 = griddata(restime,distance,[thevalue],method='linear',rescale=True) return d2[0]/1000.