getfastest (distance)
This commit is contained in:
@@ -364,3 +364,54 @@ def getmaxwattinterval(tt,ww,i):
|
||||
deltat = 0
|
||||
|
||||
return deltat,wmax
|
||||
|
||||
def getfastest(df,thedistance):
|
||||
tt = df['time'].copy()
|
||||
dd = df['cumdist'].copy()
|
||||
|
||||
tmax = tt.max()
|
||||
|
||||
if tmax > 500000:
|
||||
newlen=int(tmax/2000.)
|
||||
newt = np.arange(newlen)*tmax/float(newlen)
|
||||
deltat = newt[1]-newt[0]
|
||||
else:
|
||||
newt = np.arange(0,tmax,10.)
|
||||
deltat = 10.
|
||||
|
||||
dd = griddata(tt.values,
|
||||
dd.values,newt,method='linear',rescale=True)
|
||||
|
||||
tt = pd.Series(newt)
|
||||
dd = pd.Series(dd)
|
||||
|
||||
G = pd.concat([pd.Series([0]),dd])
|
||||
h = np.mgrid[0:len(tt)+1:1,0:len(tt)+1:1]
|
||||
distances = pd.DataFrame(h[1]-h[0])
|
||||
ones = 1+np.zeros(len(G))
|
||||
Ghor = np.outer(ones,G)
|
||||
Gver = np.outer(G,ones)
|
||||
Gdif = Ghor-Gver
|
||||
Gdif = np.tril(Gdif.T).T
|
||||
Gdif = pd.DataFrame(Gdif)
|
||||
F = Gdif
|
||||
|
||||
F.fillna(inplace=True,method='ffill',axis=1)
|
||||
F.fillna(inplace=True,value=0)
|
||||
|
||||
restime = []
|
||||
distance = []
|
||||
|
||||
for i in np.arange(0,len(tt)+1,1):
|
||||
restime.append(deltat*i)
|
||||
cp = np.diag(F,i).max()
|
||||
distance.append(cp)
|
||||
|
||||
distance[0] = distance[1]
|
||||
|
||||
restime = np.array(restime)
|
||||
distance = np.array(distance)
|
||||
|
||||
d2 = griddata(distance,restime,[thedistance],method='linear',rescale=True)
|
||||
|
||||
return d2[0]/1000.
|
||||
|
||||
Reference in New Issue
Block a user