Exemple #1
0
    def turning_angle(self,consecutive=False):
        """ Returns collection of turning angles in the trace (in radians)
            If consecutive=True, only counts angles between consecutive flights
        """
        if self.N_flights < 2:
            return [False]
        else:
            if not consecutive:
                dp = np.array([g for g in self.iter_flights('StartEnd')]) #(pairs of points)
                angs = np.ediff1d(tuple(geom.angle_vect(g[0][:-1],g[1][:-1]) for g in dp))
            else:
                angs = []
                angs_d = []
                for f in self.iter_all():
                    if not isinstance(f,Stop):
                        angs_d.append(geom.angle_vect(f.StartEnd[0][:-1],f.StartEnd[-1][:-1]))
                    else:
                        if len(angs_d)>1:
	                        angs.extend(np.ediff1d(angs_d))
                        angs_d = []
                if len(angs_d)>1:
                    angs.extend(np.ediff1d(angs_d))
            for i,a in enumerate(angs):
                if a>np.pi:
                    angs[i] = - (2*np.pi-a)
                if a<-np.pi:
                    angs[i] = 2*np.pi+a
            return np.array(angs)
Exemple #2
0
def angularmodel(oTrace, theta_max):
    """ merges successive flights from the rectangular model if their relative angle does not exceed theta_max
    input: theta_max, Trace containing stops and flights
    output: new Trace containing merged flights and same stops
    """
    new_Trace = cls.Trace()
    # add stops
    for s in oTrace.iter_stops():
        new_Trace.add_stop(s)
    fl_group = separe_flights(oTrace)
    # and now merge if needed
    for gr in fl_group:
        if len(gr) > 1:  # if more than 1 flight
            dif_angle = []
            for f in gr:  # for each flight check delta orientation
                dif_angle.append(geom.angle_vect(f.UTM[-1][:-1],
                                                 f.UTM[0][:-1]))
            dif_angle = np.array(dif_angle)
            if len(np.where(dif_angle > np.deg2rad(theta_max))
                   [0]) != 0:  # if something to merge
                new_fl = np.split(
                    gr,
                    np.where(dif_angle > np.deg2rad(theta_max))[0] + 1)
                for fl in new_fl:
                    if len(fl) != 0: new_Trace.add_flight(np.sum(fl))
            else: new_Trace.add_flight(np.sum(gr))  #if not, merge all!
        else:
            if len(gr) != 0: new_Trace.add_flight(gr[0])
    return new_Trace
Exemple #3
0
def angularmodel(oTrace,theta_max):
    """ merges successive flights from the rectangular model if their relative angle does not exceed theta_max
    input: theta_max, Trace containing stops and flights
    output: new Trace containing merged flights and same stops
    """
    new_Trace=cls.Trace()
    # add stops
    for s in oTrace.iter_stops():
        new_Trace.add_stop(s) 
    fl_group=separe_flights(oTrace)
    # and now merge if needed
    for gr in fl_group:
        if len(gr)>1: # if more than 1 flight
            dif_angle = []
            for f in gr: # for each flight check delta orientation
                dif_angle.append(geom.angle_vect(f.UTM[-1][:-1],f.UTM[0][:-1]))
            dif_angle = np.array(dif_angle)
            if len(np.where(dif_angle>np.deg2rad(theta_max))[0])!=0: # if something to merge
                new_fl=np.split(gr,np.where(dif_angle>np.deg2rad(theta_max))[0]+1)
                for fl in new_fl: 
                    if len(fl)!=0: new_Trace.add_flight(np.sum(fl))
            else: new_Trace.add_flight(np.sum(gr)) #if not, merge all!
        else: 
            if len(gr)!=0: new_Trace.add_flight(gr[0])
    return new_Trace