Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 549:b5525249eda1
Merged in mohamedgomaa/trafficintelligence (pull request #7)
add some functions for behaviour analysis and corrected a few bugs
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 08 Jul 2014 16:32:09 -0400 |
parents | cb213269d330 6c0923f1ce68 |
children | 5668af2ff515 |
comparison
equal
deleted
inserted
replaced
545:9816fab353f3 | 549:b5525249eda1 |
---|---|
447 def __str__(self): | 447 def __str__(self): |
448 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) | 448 return ' '.join([self.__getitem__(i).__str__() for i in xrange(self.length())]) |
449 | 449 |
450 def __repr__(self): | 450 def __repr__(self): |
451 return self.__str__() | 451 return self.__str__() |
452 | |
452 | 453 |
453 def __iter__(self): | 454 def __iter__(self): |
454 self.iterInstantNum = 0 | 455 self.iterInstantNum = 0 |
455 return self | 456 return self |
456 | 457 |
820 @staticmethod | 821 @staticmethod |
821 def minDistance(obj1, obj2, instant): | 822 def minDistance(obj1, obj2, instant): |
822 return MovingObject.distances(obj1, obj2, instant).min() | 823 return MovingObject.distances(obj1, obj2, instant).min() |
823 | 824 |
824 @staticmethod | 825 @staticmethod |
826 def distances2(obj1, obj2, instant1,instant2): | |
827 from scipy.spatial.distance import cdist | |
828 positions1 = [f.getPositionAtInstant(instant1).astuple() for f in obj1.features if f.existsAtInstant(instant1)] | |
829 positions2 = [f.getPositionAtInstant(instant2).astuple() for f in obj2.features if f.existsAtInstant(instant2)] | |
830 return cdist(positions1, positions2, metric = 'euclidean') | |
831 | |
832 @staticmethod | |
833 def minDistance2(obj1, obj2, instant1,instant2): | |
834 return MovingObject.distances2(obj1, obj2, instant1,instant2).min() | |
835 | |
836 @staticmethod | |
825 def maxDistance(obj1, obj2, instant): | 837 def maxDistance(obj1, obj2, instant): |
826 return MovingObject.distances(obj1, obj2, instant).max() | 838 return MovingObject.distances(obj1, obj2, instant).max() |
827 | 839 |
828 def maxSize(self): | 840 def maxSize(self): |
829 '''Returns the max distance between features | 841 '''Returns the max distance between features |
838 tMaxFeatures = t | 850 tMaxFeatures = t |
839 return MovingObject.maxDistance(self, self, tMaxFeatures) | 851 return MovingObject.maxDistance(self, self, tMaxFeatures) |
840 else: | 852 else: |
841 print('Load features to compute a maximum size') | 853 print('Load features to compute a maximum size') |
842 return None | 854 return None |
843 | 855 |
856 def setRoutes(self,startCode,endCode): | |
857 self.startRouteID=startCode | |
858 self.endRouteID=endCode | |
859 | |
844 def getInstantsCrossingLane(self, p1, p2): | 860 def getInstantsCrossingLane(self, p1, p2): |
845 '''Returns the instant(s) | 861 '''Returns the instant(s) |
846 at which the object passes from one side of the segment to the other | 862 at which the object passes from one side of the segment to the other |
847 empty list if there is no crossing''' | 863 empty list if there is no crossing''' |
848 indices = self.positions.getIntersections(p1, p2) | 864 indices = self.positions.getIntersections(p1, p2) |
959 if areas[userTypename][p.x, p.y] != 0: | 975 if areas[userTypename][p.x, p.y] != 0: |
960 possibleUserTypes[userType2Enum[userTypename]] += 1 | 976 possibleUserTypes[userType2Enum[userTypename]] += 1 |
961 # what to do: threshold for most common type? self.setUserType() | 977 # what to do: threshold for most common type? self.setUserType() |
962 return possibleUserTypes | 978 return possibleUserTypes |
963 | 979 |
980 | |
964 @staticmethod | 981 @staticmethod |
965 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | 982 def collisionCourseDotProduct(movingObject1, movingObject2, instant): |
966 'A positive result indicates that the road users are getting closer' | 983 'A positive result indicates that the road users are getting closer' |
967 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | 984 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) |
968 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) | 985 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) |