Mercurial Hosting > traffic-intelligence
annotate python/events.py @ 665:15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 20 May 2015 13:57:47 +0200 |
parents | 455f9b93819c |
children | fa9aa5f08210 |
rev | line source |
---|---|
56
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 '''Libraries for events |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 Interactions, pedestrian crossing...''' |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 |
665
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
664
diff
changeset
|
5 import moving, prediction, indicators, utils, cvutils |
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
664
diff
changeset
|
6 from base import VideoFilenameAddable |
15e244d2a1b5
corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
664
diff
changeset
|
7 |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
8 import numpy as np |
306
93d851d0d21e
bug correction, minor work on indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
299
diff
changeset
|
9 from numpy import arccos |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
10 |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
11 import multiprocessing |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
12 import itertools |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
13 |
56
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 |
613 | 15 def findRoute(prototypes,objects,i,j,noiseEntryNums,noiseExitNums,minSimilarity= 0.3, spatialThreshold=1.0, delta=180): |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
16 if i[0] not in noiseEntryNums: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
17 prototypesRoutes= [ x for x in sorted(prototypes.keys()) if i[0]==x[0]] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
18 elif i[1] not in noiseExitNums: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
19 prototypesRoutes=[ x for x in sorted(prototypes.keys()) if i[1]==x[1]] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
20 else: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
21 prototypesRoutes=[x for x in sorted(prototypes.keys())] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
22 routeSim={} |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
23 lcss = utils.LCSS(similarityFunc=lambda x,y: (distanceForLCSS(x,y) <= spatialThreshold),delta=delta) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
24 for y in prototypesRoutes: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
25 if y in prototypes.keys(): |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
26 prototypesIDs=prototypes[y] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
27 similarity=[] |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
28 for x in prototypesIDs: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
29 s=lcss.computeNormalized(objects[j].positions, objects[x].positions) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
30 similarity.append(s) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
31 routeSim[y]=max(similarity) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
32 route=max(routeSim, key=routeSim.get) |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
33 if routeSim[route]>=minSimilarity: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
34 return route |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
35 else: |
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
36 return i |
613 | 37 |
610
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
38 def getRoute(obj,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination=True): |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
39 route=(obj.startRouteID,obj.endRouteID) |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
40 if useDestination: |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
41 if route not in prototypes.keys(): |
613 | 42 route= findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) |
610
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
43 return route |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
44 |
664
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
45 class Interaction(moving.STObject, VideoFilenameAddable): |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
46 '''Class for an interaction between two road users |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
47 or a road user and an obstacle |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
48 |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
49 link to the moving objects |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
50 contains the indicators in a dictionary with the names as keys |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
51 ''' |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
52 |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
53 categories = {'Head On': 0, |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
54 'rearend': 1, |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
55 'side': 2, |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
56 'parallel': 3} |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
57 |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
58 indicatorNames = ['Collision Course Dot Product', |
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
59 'Collision Course Angle', |
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
60 'Distance', |
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
61 'Minimum Distance', |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
62 'Velocity Angle', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
63 'Speed Differential', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
64 'Collision Probability', |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
65 'Time to Collision', # 7 |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
66 'Probability of Successful Evasive Action', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
67 'predicted Post Encroachment Time'] |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
68 |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
69 indicatorNameToIndices = utils.inverseEnumeration(indicatorNames) |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
70 |
388
6e0dedd34920
minor name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
387
diff
changeset
|
71 indicatorShortNames = ['CCDP', |
408
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
72 'CCA', |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
73 'Dist', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
74 'MinDist', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
75 'VA', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
76 'SD', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
77 'PoC', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
78 'TTC', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
79 'P(SEA)', |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
80 'pPET'] |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
81 |
408
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
82 indicatorUnits = ['', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
83 'rad', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
84 'm', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
85 'm', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
86 'rad', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
87 'm/s', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
88 '', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
89 's', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
90 '', |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
91 ''] |
365d8dee44f3
last changes for TRB14
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
388
diff
changeset
|
92 |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
93 def __init__(self, num = None, timeInterval = None, roaduserNum1 = None, roaduserNum2 = None, roadUser1 = None, roadUser2 = None, categoryNum = None): |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
94 moving.STObject.__init__(self, num, timeInterval) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
95 if timeInterval is None and roadUser1 is not None and roadUser2 is not None: |
566
07b1bd0785cd
simplifications to interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
559
diff
changeset
|
96 self.timeInterval = roadUser1.commonTimeInterval(roadUser2) |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
97 self.roadUser1 = roadUser1 |
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
98 self.roadUser2 = roadUser2 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
99 if roaduserNum1 is not None and roaduserNum2 is not None: |
566
07b1bd0785cd
simplifications to interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
559
diff
changeset
|
100 self.roadUserNumbers = set([roaduserNum1, roaduserNum2]) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
101 elif roadUser1 is not None and roadUser2 is not None: |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
102 self.roadUserNumbers = set([roadUser1.getNum(), roadUser2.getNum()]) |
566
07b1bd0785cd
simplifications to interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
559
diff
changeset
|
103 else: |
07b1bd0785cd
simplifications to interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
559
diff
changeset
|
104 self.roadUserNumbers = None |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
105 self.categoryNum = categoryNum |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
106 self.indicators = {} |
451
cd342a774806
Point/CurvilinearTrajectory/Interaction utiles
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
436
diff
changeset
|
107 self.interactionInterval = None |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
108 # list for collison points and crossing zones |
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
109 self.collisionPoints = None |
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
110 self.crossingZones = None |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
111 |
340
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
339
diff
changeset
|
112 def getRoadUserNumbers(self): |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
339
diff
changeset
|
113 return self.roadUserNumbers |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
339
diff
changeset
|
114 |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
115 def setRoadUsers(self, objects): |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
116 nums = list(self.getRoadUserNumbers()) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
117 if objects[nums[0]].getNum() == nums[0]: |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
118 self.roadUser1 = objects[nums[0]] |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
119 if objects[nums[1]].getNum() == nums[1]: |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
120 self.roadUser2 = objects[nums[1]] |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
121 |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
122 i = 0 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
123 while i < len(objects) and self.roadUser2 is None: |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
124 if objects[i].getNum() in nums: |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
125 if self.roadUser1 is None: |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
126 self.roadUser1 = objects[i] |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
127 else: |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
128 self.roadUser2 = objects[i] |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
129 i += 1 |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
130 |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
131 def getIndicator(self, indicatorName): |
321
a5e40bd04cf4
rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
320
diff
changeset
|
132 return self.indicators.get(indicatorName, None) |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
133 |
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
134 def addIndicator(self, indicator): |
661
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
135 if indicator is not None: |
321
a5e40bd04cf4
rearranged LCSS indicator functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
320
diff
changeset
|
136 self.indicators[indicator.name] = indicator |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
137 |
661
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
138 def getIndicatorValueAtInstant(self, indicatorName, instant): |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
139 indicator = self.getIndicator(indicatorName) |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
140 if indicator is not None: |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
141 return indicator[instant] |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
142 else: |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
143 return None |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
144 |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
145 def getIndicatorValuesAtInstant(self, instant): |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
146 '''Returns list of indicator values at instant |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
147 as dict (with keys from indicators dict)''' |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
148 values = {} |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
149 for k, indicator in self.indicators.iteritems(): |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
150 values[k] = indicator[instant] |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
151 return values |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
152 |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
153 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs): |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
154 self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
155 self.roadUser2.plot(options, withOrigin, timeStep, withFeatures, **kwargs) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
156 |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
157 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
158 self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
159 self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
160 |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
161 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
162 if self.roadUser1 is not None and self.roadUser2 is not None: |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
163 cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
164 else: |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
165 print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers') |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
166 |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
167 def computeIndicators(self): |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
168 '''Computes the collision course cosine only if the cosine is positive''' |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
169 collisionCourseDotProducts = {}#[0]*int(self.timeInterval.length()) |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
170 collisionCourseAngles = {} |
325
6c9c7c956926
added velocity angle in indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
321
diff
changeset
|
171 velocityAngles = {} |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
172 distances = {}#[0]*int(self.timeInterval.length()) |
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
173 speedDifferentials = {} |
452
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
174 interactionInstants = [] |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
175 for instant in self.timeInterval: |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
176 deltap = self.roadUser1.getPositionAtInstant(instant)-self.roadUser2.getPositionAtInstant(instant) |
325
6c9c7c956926
added velocity angle in indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
321
diff
changeset
|
177 v1 = self.roadUser1.getVelocityAtInstant(instant) |
6c9c7c956926
added velocity angle in indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
321
diff
changeset
|
178 v2 = self.roadUser2.getVelocityAtInstant(instant) |
6c9c7c956926
added velocity angle in indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
321
diff
changeset
|
179 deltav = v2-v1 |
6c9c7c956926
added velocity angle in indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
321
diff
changeset
|
180 velocityAngles[instant] = arccos(moving.Point.dot(v1, v2)/(v1.norm2()*v2.norm2())) |
299
7e5fb4abd070
renaming event to events and correcting errors in indicator computation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
294
diff
changeset
|
181 collisionCourseDotProducts[instant] = moving.Point.dot(deltap, deltav) |
317
d280b881e860
added indicator min distance
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
310
diff
changeset
|
182 distances[instant] = deltap.norm2() |
294
1f253f218b9f
evolution of indicators and their computation in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
293
diff
changeset
|
183 speedDifferentials[instant] = deltav.norm2() |
452
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
184 if collisionCourseDotProducts[instant] > 0: |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
185 interactionInstants.append(instant) |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
186 if distances[instant] != 0 and speedDifferentials[instant] != 0: |
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
187 collisionCourseAngles[instant] = arccos(collisionCourseDotProducts[instant]/(distances[instant]*speedDifferentials[instant])) |
306
93d851d0d21e
bug correction, minor work on indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
299
diff
changeset
|
188 |
452
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
189 if len(interactionInstants) >= 2: |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
190 self.interactionInterval = moving.TimeInterval(interactionInstants[0], interactionInstants[-1]) |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
191 else: |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
192 self.interactionInterval = moving.TimeInterval() |
387
91679eb2ff2c
cleaning up safety analysis and the new traditional constant velocity method
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
193 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[0], collisionCourseDotProducts)) |
91679eb2ff2c
cleaning up safety analysis and the new traditional constant velocity method
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
194 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[1], collisionCourseAngles)) |
91679eb2ff2c
cleaning up safety analysis and the new traditional constant velocity method
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
195 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[2], distances)) |
91679eb2ff2c
cleaning up safety analysis and the new traditional constant velocity method
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
196 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[4], velocityAngles)) |
91679eb2ff2c
cleaning up safety analysis and the new traditional constant velocity method
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
197 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[5], speedDifferentials)) |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
198 |
317
d280b881e860
added indicator min distance
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
310
diff
changeset
|
199 # if we have features, compute other indicators |
661
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
200 if self.roadUser1.hasFeatures() and self.roadUser2.hasFeatures(): |
317
d280b881e860
added indicator min distance
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
310
diff
changeset
|
201 minDistance={} |
d280b881e860
added indicator min distance
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
310
diff
changeset
|
202 for instant in self.timeInterval: |
382
ba813f148ade
development for clustering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
378
diff
changeset
|
203 minDistance[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) |
387
91679eb2ff2c
cleaning up safety analysis and the new traditional constant velocity method
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
204 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistance)) |
317
d280b881e860
added indicator min distance
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
310
diff
changeset
|
205 |
627
82e9f78a4714
added test for location for trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
206 def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None, nProcesses = 1, usePrototypes=False, route1= (-1,-1), route2=(-1,-1), prototypes={}, secondStepPrototypes={}, nMatching={}, objects=[], noiseEntryNums=[], noiseExitNums=[], minSimilarity=0.1, mostMatched=None, useDestination=True, useSpeedPrototype=True, acceptPartialLength=30, step=1): |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
207 '''Computes all crossing and collision points at each common instant for two road users. ''' |
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
208 TTCs = {} |
610
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
209 if usePrototypes: |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
210 route1= getRoute(self.roadUser1,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination) |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
211 route2= getRoute(self.roadUser2,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination) |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
212 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
213 if timeInterval is not None: |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
214 commonTimeInterval = timeInterval |
317
d280b881e860
added indicator min distance
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
310
diff
changeset
|
215 else: |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
216 commonTimeInterval = self.timeInterval |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
217 self.collisionPoints, 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) |
558
a80ef6931fd8
updated safety-analysis to test multiprocessing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
526
diff
changeset
|
218 for i, cp in self.collisionPoints.iteritems(): |
a80ef6931fd8
updated safety-analysis to test multiprocessing
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
526
diff
changeset
|
219 TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(cp) |
631
2d1d33ae1c69
major work on pPET and pet, issues remain for pPET computed with predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
630
diff
changeset
|
220 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs, mostSevereIsMax=False)) |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
221 |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
222 # crossing zones and pPET |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
223 if computeCZ: |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
224 self.crossingZones[predictionParameters.name] = crossingZones |
338
f3aceea2afbb
first safety analysis script
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
325
diff
changeset
|
225 pPETs = {} |
610
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
226 for i, cz in self.crossingZones.iteritems(): |
0dc36203973d
remove dublicated code for collision/crossing computations
MohamedGomaa
parents:
607
diff
changeset
|
227 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(cz) |
631
2d1d33ae1c69
major work on pPET and pet, issues remain for pPET computed with predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
630
diff
changeset
|
228 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs, mostSevereIsMax=False)) |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
229 # TODO add probability of collision, and probability of successful evasive action |
631
2d1d33ae1c69
major work on pPET and pet, issues remain for pPET computed with predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
630
diff
changeset
|
230 |
2d1d33ae1c69
major work on pPET and pet, issues remain for pPET computed with predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
630
diff
changeset
|
231 def computePET(self, collisionDistanceThreshold): |
2d1d33ae1c69
major work on pPET and pet, issues remain for pPET computed with predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
630
diff
changeset
|
232 # TODO add crossing zone |
2d1d33ae1c69
major work on pPET and pet, issues remain for pPET computed with predicted trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
630
diff
changeset
|
233 self.pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
613
diff
changeset
|
234 |
664
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
235 def setCollision(self, collision): |
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
236 '''indicates if it is a collision: argument should be boolean''' |
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
237 self.collision = collision |
310
f7ca78a11ea6
add functions to add videofilename and interaction type in Interaction class
Mohamed Gomaa
parents:
306
diff
changeset
|
238 |
664
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
239 def isCollision(self): |
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
240 if hasattr(self, 'collision'): |
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
241 return self.collision |
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
242 else: |
455f9b93819c
added capability to set a videofilename to movingobject and interaction, renames interactiontype to collision in interaction
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
662
diff
changeset
|
243 return None |
661
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
244 |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
245 def getCrossingZones(self, predictionMethodName): |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
246 if self.crossingZones is not None: |
661
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
247 return self.crossingZones[predictionMethodName] |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
248 else: |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
249 return None |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
250 |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
251 def getCollisionPoints(self, predictionMethodName): |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
252 if self.collisionPoints is not None: |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
253 return self.collisionPoints[predictionMethodName] |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
254 else: |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
255 return None |
dc70d9e711f5
some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
256 |
451
cd342a774806
Point/CurvilinearTrajectory/Interaction utiles
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
436
diff
changeset
|
257 |
487
e04b22ce2fcd
generalized createInteractions to 2 lists of objects (for cars and pedestrians for example)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
454
diff
changeset
|
258 def createInteractions(objects, _others = None): |
e04b22ce2fcd
generalized createInteractions to 2 lists of objects (for cars and pedestrians for example)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
454
diff
changeset
|
259 '''Create all interactions of two co-existing road users''' |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
260 if _others is not None: |
487
e04b22ce2fcd
generalized createInteractions to 2 lists of objects (for cars and pedestrians for example)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
454
diff
changeset
|
261 others = _others |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
262 |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
263 interactions = [] |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
264 num = 0 |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
265 for i in xrange(len(objects)): |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
632
diff
changeset
|
266 if _others is None: |
487
e04b22ce2fcd
generalized createInteractions to 2 lists of objects (for cars and pedestrians for example)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
454
diff
changeset
|
267 others = objects[:i] |
e04b22ce2fcd
generalized createInteractions to 2 lists of objects (for cars and pedestrians for example)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
454
diff
changeset
|
268 for j in xrange(len(others)): |
489
000bddf84ad0
corrected bugs in safety analysis
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
487
diff
changeset
|
269 commonTimeInterval = objects[i].commonTimeInterval(others[j]) |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
270 if not commonTimeInterval.empty(): |
489
000bddf84ad0
corrected bugs in safety analysis
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
487
diff
changeset
|
271 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
272 num += 1 |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
273 return interactions |
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
274 |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
275 def findInteraction(interactions, roadUserNum1, roadUserNum2): |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
276 'Returns the right interaction in the set' |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
277 i=0 |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
278 while i<len(interactions) and set([roadUserNum1, roadUserNum2]) != interactions[i].getRoadUserNumbers(): |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
279 i+=1 |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
280 if i<len(interactions): |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
281 return interactions[i] |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
282 else: |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
283 return None |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
627
diff
changeset
|
284 |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
285 def aggregateSafetyPoints(interactions, predictionMethodName = None, pointType = 'collision'): |
632
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
286 '''Put all collision points or crossing zones in a list for display''' |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
287 if predictionMethodName is None and len(interactions)>0: |
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
288 predictionMethodName = interactions[0].collisionPoints.keys()[0] |
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
289 |
632
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
290 allPoints = [] |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
291 if pointType == 'collision': |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
292 for i in interactions: |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
293 for points in i.collisionPoints[predictionMethodName].values(): |
632
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
294 allPoints += points |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
295 elif pointType == 'crossing': |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
296 for i in interactions: |
662
72174e66aba5
corrected bug that increased TTC by 1 frame and structure to store collision points and crossing zones
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
661
diff
changeset
|
297 for points in i.crossingZones[predictionMethodName].values(): |
632
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
298 allPoints += points |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
299 else: |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
300 print('unknown type of point '+pointType) |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
301 return allPoints |
2f1a583bfd20
added utility for safety points
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
631
diff
changeset
|
302 |
430
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
303 def prototypeCluster(interactions, similarityMatrix, alignmentMatrix, indicatorName, minSimilarity): |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
304 '''Finds exemplar indicator time series for all interactions |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
305 Returns the prototype indices (in the interaction list) and the label of each indicator (interaction) |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
306 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
307 if an indicator profile (time series) is different enough (<minSimilarity), |
452
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
308 it will become a new prototype. |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
309 Non-prototype interactions will be assigned to an existing prototype''' |
430
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
310 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
311 # sort indicators based on length |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
312 indices = range(similarityMatrix.shape[0]) |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
313 def compare(i, j): |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
314 if len(interactions[i].getIndicator(indicatorName)) > len(interactions[j].getIndicator(indicatorName)): |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
315 return -1 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
316 elif len(interactions[i].getIndicator(indicatorName)) == len(interactions[j].getIndicator(indicatorName)): |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
317 return 0 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
318 else: |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
319 return 1 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
320 indices.sort(compare) |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
321 # go through all indicators |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
322 prototypeIndices = [indices[0]] |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
323 for i in indices[1:]: |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
324 if similarityMatrix[i][prototypeIndices].max() < minSimilarity: |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
325 prototypeIndices.append(i) |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
326 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
327 # assignment |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
328 labels = [-1]*similarityMatrix.shape[0] |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
329 indices = [i for i in range(similarityMatrix.shape[0]) if i not in prototypeIndices] |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
330 for i in prototypeIndices: |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
331 labels[i] = i |
436
b64ff7fe7b45
corrected clustering bug (in indicator assignment)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
430
diff
changeset
|
332 for i in indices: |
430
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
333 prototypeIndex = similarityMatrix[i][prototypeIndices].argmax() |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
334 labels[i] = prototypeIndices[prototypeIndex] |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
335 |
fb3654a9127d
integrating indicator clustering code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
408
diff
changeset
|
336 return prototypeIndices, labels |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
337 |
452
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
338 def prototypeMultivariateCluster(interactions, similarityMatrics, indicatorNames, minSimilarities, minClusterSize): |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
339 '''Finds exmaple indicator time series (several indicators) for all interactions |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
340 |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
341 if any interaction indicator time series is different enough (<minSimilarity), |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
342 it will become a new prototype. |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
343 Non-prototype interactions will be assigned to an existing prototype if all indicators are similar enough''' |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
344 pass |
c59a47ce0209
reorganized interactioninterval (in compute indicators) and comments
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
451
diff
changeset
|
345 |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
346 # TODO: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
347 #http://stackoverflow.com/questions/3288595/multiprocessing-using-pool-map-on-a-function-defined-in-a-class |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
348 #http://www.rueckstiess.net/research/snippets/show/ca1d7d90 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
349 def calculateIndicatorPipe(pairs, predParam, timeHorizon=75,collisionDistanceThreshold=1.8): |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
350 collisionPoints, crossingZones = prediction.computeCrossingsCollisions(pairs.roadUser1, pairs.roadUser2, predParam, collisionDistanceThreshold, timeHorizon) |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
351 #print pairs.num |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
352 # Ignore empty collision points |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
353 empty = 1 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
354 for i in collisionPoints: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
355 if(collisionPoints[i] != []): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
356 empty = 0 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
357 if(empty == 1): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
358 pairs.hasCP = 0 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
359 else: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
360 pairs.hasCP = 1 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
361 pairs.CP = collisionPoints |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
362 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
363 # Ignore empty crossing zones |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
364 empty = 1 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
365 for i in crossingZones: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
366 if(crossingZones[i] != []): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
367 empty = 0 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
368 if(empty == 1): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
369 pairs.hasCZ = 0 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
370 else: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
371 pairs.hasCZ = 1 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
372 pairs.CZ = crossingZones |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
373 return pairs |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
374 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
375 def calculateIndicatorPipe_star(a_b): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
376 """Convert `f([1,2])` to `f(1,2)` call.""" |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
377 return calculateIndicatorPipe(*a_b) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
378 |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
379 class VehPairs(): |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
380 '''Create a veh-pairs object from objects list''' |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
381 def __init__(self,objects): |
293
ee3302528cdc
rearranged new code by Paul (works now)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
292
diff
changeset
|
382 self.pairs = createInteractions(objects) |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
383 self.interactionCount = 0 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
384 self.CPcount = 0 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
385 self.CZcount = 0 |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
386 |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
387 # Process indicator calculation with support for multi-threading |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
388 def calculateIndicators(self,predParam,threads=1,timeHorizon=75,collisionDistanceThreshold=1.8): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
389 if(threads > 1): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
390 pool = multiprocessing.Pool(threads) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
391 self.pairs = pool.map(calculateIndicatorPipe_star, itertools.izip(self.pairs, itertools.repeat(predParam))) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
392 pool.close() |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
393 else: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
394 #prog = Tools.ProgressBar(0, len(self.pairs), 77) #Removed in traffic-intelligenc port |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
395 for j in xrange(len(self.pairs)): |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
396 #prog.updateAmount(j) #Removed in traffic-intelligenc port |
320
419f30491a4b
renamed fields movingObject to roadUser, etc
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
317
diff
changeset
|
397 collisionPoints, crossingZones = prediction.computeCrossingsCollisions(self.pairs[j].roadUser1, self.pairs[j].roadUser2, predParam, collisionDistanceThreshold, timeHorizon) |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
398 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
399 # Ignore empty collision points |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
400 empty = 1 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
401 for i in collisionPoints: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
402 if(collisionPoints[i] != []): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
403 empty = 0 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
404 if(empty == 1): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
405 self.pairs[j].hasCP = 0 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
406 else: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
407 self.pairs[j].hasCP = 1 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
408 self.pairs[j].CP = collisionPoints |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
409 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
410 # Ignore empty crossing zones |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
411 empty = 1 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
412 for i in crossingZones: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
413 if(crossingZones[i] != []): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
414 empty = 0 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
415 if(empty == 1): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
416 self.pairs[j].hasCZ = 0 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
417 else: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
418 self.pairs[j].hasCZ = 1 |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
419 self.pairs[j].CZ = crossingZones |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
420 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
421 for j in self.pairs: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
422 self.interactionCount = self.interactionCount + len(j.CP) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
423 self.CPcount = len(self.getCPlist()) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
424 self.Czcount = len(self.getCZlist()) |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
425 |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
426 |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
427 def getPairsWCP(self): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
428 lists = [] |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
429 for j in self.pairs: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
430 if(j.hasCP): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
431 lists.append(j.num) |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
432 return lists |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
433 |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
434 def getPairsWCZ(self): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
435 lists = [] |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
436 for j in self.pairs: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
437 if(j.hasCZ): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
438 lists.append(j.num) |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
439 return lists |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
440 |
526
21bdeb29f855
corrected bug in initialization of lists and loading trajectories from vissim files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
489
diff
changeset
|
441 def getCPlist(self,indicatorThreshold=float('Inf')): |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
442 lists = [] |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
443 for j in self.pairs: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
444 if(j.hasCP): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
445 for k in j.CP: |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
446 if(j.CP[k] != [] and j.CP[k][0].indicator < indicatorThreshold): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
447 lists.append([k,j.CP[k][0]]) |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
448 return lists |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
449 |
526
21bdeb29f855
corrected bug in initialization of lists and loading trajectories from vissim files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
489
diff
changeset
|
450 def getCZlist(self,indicatorThreshold=float('Inf')): |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
451 lists = [] |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
452 for j in self.pairs: |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
453 if(j.hasCZ): |
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
454 for k in j.CZ: |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
455 if(j.CZ[k] != [] and j.CZ[k][0].indicator < indicatorThreshold): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
456 lists.append([k,j.CZ[k][0]]) |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
457 return lists |
292
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
458 |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
459 def genIndicatorHistogram(self, CPlist=False, bins=range(0,100,1)): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
460 if(not CPlist): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
461 CPlist = self.getCPlist() |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
462 if(not CPlist): |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
463 return False |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
464 TTC_list = [] |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
465 for i in CPlist: |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
466 TTC_list.append(i[1].indicator) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
467 histo = np.histogram(TTC_list,bins=bins) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
468 histo += (histo[0].astype(float)/np.sum(histo[0]),) |
8b2c8a4015f1
class VehPairs updated. Now supports primitive multithreading.
Paul@BEAST-III
parents:
291
diff
changeset
|
469 return histo |
291
9f81218e497a
class VehPairs subsumes createInteractions(objects); legacy code remains
Paul@BEAST-III
parents:
283
diff
changeset
|
470 |
59
f955e83da499
developed indicators in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
56
diff
changeset
|
471 class Crossing(moving.STObject): |
56
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
472 '''Class for the event of a street crossing |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
473 |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
474 TODO: detecter passage sur la chaussee |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
475 identifier origines et destination (ou uniquement chaussee dans FOV) |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
476 carac traversee |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
477 detecter proximite veh (retirer si trop similaire simultanement |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
478 carac interaction''' |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
479 |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
480 def __init__(self, roaduserNum = None, num = None, timeInterval = None): |
59
f955e83da499
developed indicators in interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
56
diff
changeset
|
481 moving.STObject.__init__(self, num, timeInterval) |
56
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
482 self.roaduserNum = roaduserNum |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
483 |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
484 |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
485 |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
486 if __name__ == "__main__": |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
487 import doctest |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
488 import unittest |
489
000bddf84ad0
corrected bugs in safety analysis
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
487
diff
changeset
|
489 suite = doctest.DocFileSuite('tests/events.txt') |
000bddf84ad0
corrected bugs in safety analysis
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
487
diff
changeset
|
490 #suite = doctest.DocTestSuite() |
56
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
491 unittest.TextTestRunner().run(suite) |
61fe73df2d36
created new package, moved Interaction class and created Crossing class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
492 |