Mercurial > hg > nsaunier > traffic-intelligence
comparison python/events.py @ 601:e1f3b789c632
add a definition of interaction and collision course intervals
| author | Mohamed Gomaa |
|---|---|
| date | Thu, 02 May 2013 11:35:45 -0400 |
| parents | 414b2e7cd873 |
| children |
comparison
equal
deleted
inserted
replaced
| 600:414b2e7cd873 | 601:e1f3b789c632 |
|---|---|
| 45 '''Computes the collision course cosine only if the cosine is positive''' | 45 '''Computes the collision course cosine only if the cosine is positive''' |
| 46 collisionCourseDotProducts = {}#[0]*int(self.timeInterval.length()) | 46 collisionCourseDotProducts = {}#[0]*int(self.timeInterval.length()) |
| 47 collisionCourseAngles = {} | 47 collisionCourseAngles = {} |
| 48 distances = {}#[0]*int(self.timeInterval.length()) | 48 distances = {}#[0]*int(self.timeInterval.length()) |
| 49 speedDifferentials = {} | 49 speedDifferentials = {} |
| 50 velocityAngle= {} | |
| 50 for instant in self.timeInterval: | 51 for instant in self.timeInterval: |
| 51 deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant) | 52 deltap = self.movingObject1.getPositionAtInstant(instant)-self.movingObject2.getPositionAtInstant(instant) |
| 52 deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant) | 53 deltav = self.movingObject2.getVelocityAtInstant(instant)-self.movingObject1.getVelocityAtInstant(instant) |
| 53 collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav) | 54 collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav) |
| 55 velocityDotProduct= moving.Point.dot(self.movingObject1.getVelocityAtInstant(instant),self.movingObject2.getVelocityAtInstant(instant)) | |
| 56 velocityAngle[instant]= np.arccos(velocityDotProduct/ (self.movingObject1.getVelocityAtInstant(instant).norm2() * self.movingObject2.getVelocityAtInstant(instant).norm2())) | |
| 54 distances[instant] = deltap.norm2() | 57 distances[instant] = deltap.norm2() |
| 55 speedDifferentials[instant] = deltav.norm2() | 58 speedDifferentials[instant] = deltav.norm2() |
| 56 if collisionCourseDotProducts[instant] > 0: | 59 if collisionCourseDotProducts[instant] > 0: |
| 57 collisionCourseAngles[instant] = arccos(collisionCourseDotProducts[instant]/(distances[instant]*speedDifferentials[instant])) | 60 collisionCourseAngles[instant] = arccos(collisionCourseDotProducts[instant]/(distances[instant]*speedDifferentials[instant])) |
| 58 | 61 |
| 59 # todo shorten the time intervals based on the interaction definition | 62 # todo shorten the time intervals based on the interaction definition |
| 60 self.addIndicator(indicators.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProducts)) | 63 self.addIndicator(indicators.SeverityIndicator('Collision Course Dot Product', collisionCourseDotProducts)) |
| 61 self.addIndicator(indicators.SeverityIndicator('Distance', distances)) | 64 self.addIndicator(indicators.SeverityIndicator('Distance', distances)) |
| 62 self.addIndicator(indicators.SeverityIndicator('Speed Differential', speedDifferentials)) | 65 self.addIndicator(indicators.SeverityIndicator('Speed Differential', speedDifferentials)) |
| 66 self.addIndicator(indicators.SeverityIndicator('Velocity Angle', velocityAngle)) | |
| 63 self.addIndicator(indicators.SeverityIndicator('Collision Course Angle', collisionCourseAngles)) | 67 self.addIndicator(indicators.SeverityIndicator('Collision Course Angle', collisionCourseAngles)) |
| 64 | 68 |
| 65 # todo test for interaction instants and interval, compute indicators | 69 # todo test for interaction instants and interval, compute indicators |
| 66 | 70 |
| 67 # if we have features, compute other indicators | 71 # if we have features, compute other indicators |
| 80 collisionPoints,crossingZones = prediction.computeCrossingsCollisions(self.movingObject1, self.movingObject2, predictionParameters, collisionDistanceThreshold, timeHorizon,asWholeVehicle=True) | 84 collisionPoints,crossingZones = prediction.computeCrossingsCollisions(self.movingObject1, self.movingObject2, predictionParameters, collisionDistanceThreshold, timeHorizon,asWholeVehicle=True) |
| 81 self.addIndicator(indicators.SeverityIndicator('collisionPoints', collisionPoints)) | 85 self.addIndicator(indicators.SeverityIndicator('collisionPoints', collisionPoints)) |
| 82 else: | 86 else: |
| 83 print('Features not associated with objects') | 87 print('Features not associated with objects') |
| 84 | 88 |
| 89 def defineInteractionInterval(self): | |
| 90 ''' interaction defined as the first and last time that the collion course is positive''' | |
| 91 keys=sorted(self.getIndicator('Collision Course Angle').values.keys()) | |
| 92 if keys!=[]: | |
| 93 self.interactionInterval= moving.TimeInterval(keys[0],keys[-1]) | |
| 94 else: | |
| 95 print('no interaction') | |
| 96 self.interactionInterval=None | |
| 97 | |
| 98 def defineCollisionPointInterval(self): | |
| 99 ''' collision point defined as the first and last time that the collion point exist''' | |
| 100 values= self.getIndicator('TTC').values | |
| 101 keys=sorted(values.keys()) | |
| 102 #keysReverse=sorted(values.keys(),reverse=True) | |
| 103 keysWithoutinf= [key for key in keys if values[key]!=np.inf] | |
| 104 if keysWithoutinf!=[]: | |
| 105 self.collisionPointInterval= moving.TimeInterval(min(keysWithoutinf),max(keysWithoutinf)) | |
| 106 else: | |
| 107 print('no collision points') | |
| 108 self.collisionPointInterval=None | |
| 109 | |
| 110 def removeIndicatorExtraValues(self,indicatorName): | |
| 111 ''' refine the indicators value wrt interaction definition''' | |
| 112 self.defineInteractionInterval() | |
| 113 refinedIndicator = {} | |
| 114 if self.interactionInterval!= None: | |
| 115 for i in xrange(self.interactionInterval.first,self.interactionInterval.last+1): | |
| 116 if self.getIndicator(indicatorName).values.get(i)== None: | |
| 117 refinedIndicator[i]= None | |
| 118 else: | |
| 119 refinedIndicator[i]= self.getIndicator(indicatorName).values[i] | |
| 120 self.addIndicator(indicators.SeverityIndicator(str(indicatorName)+' New', refinedIndicator)) | |
| 121 | |
| 122 def removeIndicatorExtraValuesCP(self,indicatorName): | |
| 123 ''' refine the indicators value wrt interaction definition''' | |
| 124 self.defineCollisionPointInterval() | |
| 125 refinedIndicator = {} | |
| 126 if self.collisionPointInterval!= None: | |
| 127 for i in xrange(self.collisionPointInterval.first,self.collisionPointInterval.last+1): | |
| 128 if self.getIndicator(indicatorName).values.get(i)== None: | |
| 129 refinedIndicator[i]= None | |
| 130 else: | |
| 131 refinedIndicator[i]= self.getIndicator(indicatorName).values[i] | |
| 132 self.addIndicator(indicators.SeverityIndicator(str(indicatorName)+'2', refinedIndicator)) | |
| 133 | |
| 85 def addVideoFilename(self,videoFilename): | 134 def addVideoFilename(self,videoFilename): |
| 86 self.videoFilename= videoFilename | 135 self.videoFilename= videoFilename |
| 87 | 136 |
| 88 def addInteractionType(self,interactionType): | 137 def addInteractionType(self,interactionType): |
| 89 ''' interaction types: conflict or collision if they are known''' | 138 ''' interaction types: conflict or collision if they are known''' |
