Mercurial > hg > nsaunier > traffic-intelligence
comparison python/events.py @ 661:dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 18 May 2015 13:53:25 +0200 |
| parents | 3058e00887bc |
| children | 72174e66aba5 |
comparison
equal
deleted
inserted
replaced
| 660:994dd644f6ab | 661:dc70d9e711f5 |
|---|---|
| 102 else: | 102 else: |
| 103 self.roadUserNumbers = None | 103 self.roadUserNumbers = None |
| 104 self.categoryNum = categoryNum | 104 self.categoryNum = categoryNum |
| 105 self.indicators = {} | 105 self.indicators = {} |
| 106 self.interactionInterval = None | 106 self.interactionInterval = None |
| 107 self.collisionPoints = None # distionary for collison points with different prediction methods | |
| 107 | 108 |
| 108 def getRoadUserNumbers(self): | 109 def getRoadUserNumbers(self): |
| 109 return self.roadUserNumbers | 110 return self.roadUserNumbers |
| 110 | 111 |
| 111 def setRoadUsers(self, objects): | 112 def setRoadUsers(self, objects): |
| 126 | 127 |
| 127 def getIndicator(self, indicatorName): | 128 def getIndicator(self, indicatorName): |
| 128 return self.indicators.get(indicatorName, None) | 129 return self.indicators.get(indicatorName, None) |
| 129 | 130 |
| 130 def addIndicator(self, indicator): | 131 def addIndicator(self, indicator): |
| 131 if indicator: | 132 if indicator is not None: |
| 132 self.indicators[indicator.name] = indicator | 133 self.indicators[indicator.name] = indicator |
| 133 | 134 |
| 135 def getIndicatorValueAtInstant(self, indicatorName, instant): | |
| 136 indicator = self.getIndicator(indicatorName) | |
| 137 if indicator is not None: | |
| 138 return indicator[instant] | |
| 139 else: | |
| 140 return None | |
| 141 | |
| 142 def getIndicatorValuesAtInstant(self, instant): | |
| 143 '''Returns list of indicator values at instant | |
| 144 as dict (with keys from indicators dict)''' | |
| 145 values = {} | |
| 146 for k, indicator in self.indicators.iteritems(): | |
| 147 values[k] = indicator[instant] | |
| 148 return values | |
| 149 | |
| 134 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs): | 150 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs): |
| 135 self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs) | 151 self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs) |
| 136 self.roadUser2.plot(options, withOrigin, timeStep, withFeatures, **kwargs) | 152 self.roadUser2.plot(options, withOrigin, timeStep, withFeatures, **kwargs) |
| 137 | 153 |
| 138 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): | 154 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): |
| 175 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[2], distances)) | 191 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[2], distances)) |
| 176 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[4], velocityAngles)) | 192 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[4], velocityAngles)) |
| 177 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[5], speedDifferentials)) | 193 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[5], speedDifferentials)) |
| 178 | 194 |
| 179 # if we have features, compute other indicators | 195 # if we have features, compute other indicators |
| 180 if len(self.roadUser1.features) != 0 and len(self.roadUser2.features) != 0: | 196 if self.roadUser1.hasFeatures() and self.roadUser2.hasFeatures(): |
| 181 minDistance={} | 197 minDistance={} |
| 182 for instant in self.timeInterval: | 198 for instant in self.timeInterval: |
| 183 minDistance[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) | 199 minDistance[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) |
| 184 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistance)) | 200 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistance)) |
| 185 | 201 |
| 194 | 210 |
| 195 if timeInterval is not None: | 211 if timeInterval is not None: |
| 196 commonTimeInterval = timeInterval | 212 commonTimeInterval = timeInterval |
| 197 else: | 213 else: |
| 198 commonTimeInterval = self.timeInterval | 214 commonTimeInterval = self.timeInterval |
| 199 self.collisionPoints, self.crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval, nProcesses,usePrototypes,route1,route2,prototypes,secondStepPrototypes,nMatching,objects,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched,useDestination,useSpeedPrototype,acceptPartialLength, step) | 215 self.collisionPoints[predictionParameters.name], crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval, nProcesses,usePrototypes,route1,route2,prototypes,secondStepPrototypes,nMatching,objects,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched,useDestination,useSpeedPrototype,acceptPartialLength, step) |
| 216 if computeCZ: | |
| 217 self.crossingZones[predictionParameters.name] = crossingZones | |
| 200 for i, cp in self.collisionPoints.iteritems(): | 218 for i, cp in self.collisionPoints.iteritems(): |
| 201 TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(cp) | 219 TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(cp) |
| 202 # add probability of collision, and probability of successful evasive action | 220 # add probability of collision, and probability of successful evasive action |
| 203 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs, mostSevereIsMax=False)) | 221 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs, mostSevereIsMax=False)) |
| 204 | 222 |
| 211 def computePET(self, collisionDistanceThreshold): | 229 def computePET(self, collisionDistanceThreshold): |
| 212 # TODO add crossing zone | 230 # TODO add crossing zone |
| 213 self.pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) | 231 self.pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) |
| 214 | 232 |
| 215 def addVideoFilename(self,videoFilename): | 233 def addVideoFilename(self,videoFilename): |
| 216 self.videoFilename= videoFilename | 234 self.videoFilename = videoFilename |
| 217 | 235 |
| 218 def addInteractionType(self,interactionType): | 236 def addInteractionType(self,interactionType): |
| 219 ''' interaction types: conflict or collision if they are known''' | 237 ''' interaction types: conflict or collision if they are known''' |
| 220 self.interactionType= interactionType | 238 self.interactionType = interactionType |
| 239 | |
| 240 def getCrossingZones(self, predictionMethodName): | |
| 241 if self.hasattr(self, 'crossingZones'): | |
| 242 return self.crossingZones[predictionMethodName] | |
| 243 else: | |
| 244 return None | |
| 245 | |
| 246 def getCollisionPoints(self, predictionMethodName): | |
| 247 if self.collisionPoints is not None: | |
| 248 return self.collisionPoints[predictionMethodName] | |
| 249 else: | |
| 250 return None | |
| 251 | |
| 221 | 252 |
| 222 def createInteractions(objects, _others = None): | 253 def createInteractions(objects, _others = None): |
| 223 '''Create all interactions of two co-existing road users''' | 254 '''Create all interactions of two co-existing road users''' |
| 224 if _others is not None: | 255 if _others is not None: |
| 225 others = _others | 256 others = _others |
