Beispiel #1
0
    def Interpolate(self,x,y,t):
        t1_idx = bisect(self.times,t)
        t0_idx = max(0,t1_idx - 1)
        t1_idx = min(t1_idx,len(self.times)-1)


        x1_idx = bisect(self.x,x)
        y1_idx = bisect(self.y,y)
        y0_idx = max(0,y1_idx - 1)
        x0_idx = max(0,x1_idx - 1)
        x1_idx = min(x1_idx,len(self.x)-1)
        y1_idx = min(y1_idx,len(self.y)-1)

        x0 = self.x[x0_idx]
        x1 = self.x[x1_idx]
        y0 = self.y[y0_idx]
        y1 = self.y[y1_idx]

        ts = datetimeToEpoch(t,False)
        t0 = datetimeToEpoch(self.times[t0_idx],False)
        t1 = datetimeToEpoch(self.times[t1_idx],False)

        if t1 - t0 > 0:
            p = (ts - t0) / (t1 - t0)
        else:
            p = 1.0


        u00 = p*self.U[t1_idx,y0_idx,x0_idx] + (1.0 - p)*self.U[t0_idx,y0_idx,x0_idx]
        u01 = p*self.U[t1_idx,y1_idx,x0_idx] + (1.0 - p)*self.U[t0_idx,y1_idx,x0_idx]
        u10 = p*self.U[t1_idx,y0_idx,x1_idx] + (1.0 - p)*self.U[t0_idx,y0_idx,x1_idx]
        u11 = p*self.U[t1_idx,y1_idx,x1_idx] + (1.0 - p)*self.U[t0_idx,y1_idx,x1_idx]

        v00 = p*self.V[t1_idx,y0_idx,x0_idx] + (1.0 - p)*self.V[t0_idx,y0_idx,x0_idx]
        v01 = p*self.V[t1_idx,y1_idx,x0_idx] + (1.0 - p)*self.V[t0_idx,y1_idx,x0_idx]
        v10 = p*self.V[t1_idx,y0_idx,x1_idx] + (1.0 - p)*self.V[t0_idx,y0_idx,x1_idx]
        v11 = p*self.V[t1_idx,y1_idx,x1_idx] + (1.0 - p)*self.V[t0_idx,y1_idx,x1_idx]
        #print u00,u10,u01,u11,v00,v10,v01,v11
        #print x0,x1,y0,y1,x,y
        u = bilinear_interpolation(x,y,x0,x1,y0,y1,u00,u01,u10,u11)
        v = bilinear_interpolation(x,y,x0,x1,y0,y1,v00,v01,v10,v11)
        #print u,v
        #print t0,t1
        return u,v
Beispiel #2
0
 def GetStartTime(self,asfloat=True,days=False):
     if asfloat:
         return datetimeToEpoch(self.timestamp,days)
     return self.timestamp