tvaLib
Public Member Functions | Public Attributes | List of all members
lib.int.Interaction Class Reference
Inheritance diagram for lib.int.Interaction:

Public Member Functions

def __init__ (self, args, kwargs)
 
def getInstantCount (self)
 
def getInstantWIndicatorCount (self, indicatorName=None)
 
def genSafetyIndicators (self)
 
def genInteractionDescriptors (self)
 
def getInteractionDescriptors (self)
 
def constrainToZone (self, zone)
 
def dropSafetyIndicatorsByValue (self, indicatorLowerBound=0, indicatorUpperBound=sys.maxint)
 
def getPointList (self, ptype='CP', atInstant=None, alignRestrictions=None, maxIndThreshold=sys.maxint, aggregateInstants=True, max_inst_prob=1.0, verbose=0)
 
def getAggregatedPointList (self, method=0, percentile=0.15, minimumProbability=0.0, format='points', kwargs)
 
def getAggregatedInterAngle (self, percentile=0.5, minimumProbability=0.0)
 

Public Attributes

 user1Hash
 
 user2Hash
 
 interactionDescriptors
 
 collisionPoints
 

Detailed Description

This is an upgrade to TI's standard Interaction() class. 
    Synonym: userPair. 

Definition at line 70 of file int.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.int.Interaction.__init__ (   self,
  args,
  kwargs 
)

Definition at line 74 of file int.py.

74  def __init__(self, *args, **kwargs):
75  self.user1Hash = kwargs.pop('user1Hash')
76  self.user2Hash = kwargs.pop('user2Hash')
77  TrafIntEvents_Interaction.__init__(self, *args, **kwargs)
78 

Member Function Documentation

◆ constrainToZone()

def lib.int.Interaction.constrainToZone (   self,
  zone 
)
Drop any collision points outside of given zone. 

Definition at line 109 of file int.py.

109  def constrainToZone(self, zone):
110  ''' Drop any collision points outside of given zone. '''
111  if(len(zone) == 0): return 0
112  drop_list = []
113  if(self.collisionPoints):
114  for frame in self.collisionPoints:
115  for i in range(len(self.collisionPoints[frame])):
116  if(True not in [tvaLib.Geo.pip(self.collisionPoints[frame][i].x, self.collisionPoints[frame][i].y, z) for z in zone]):
117  self.collisionPoints[frame][i] = None
118  drop_list.append([frame,i])
119  self.collisionPoints[frame] = filter(None, self.collisionPoints[frame])
120  self.collisionPoints = dict((k, v) for k, v in self.collisionPoints.items() if v)
121 
122  if(drop_list):
123  self.indicators.pop(Interaction.indicatorNames[7],None)
124  self.genSafetyIndicators()
125 
126  return len(drop_list)
127 

◆ dropSafetyIndicatorsByValue()

def lib.int.Interaction.dropSafetyIndicatorsByValue (   self,
  indicatorLowerBound = 0,
  indicatorUpperBound = sys.maxint 
)
Recursively delete indicators with values below indicatorLowerBound
    and greater than indicatorUpperBound. 

Definition at line 128 of file int.py.

128  def dropSafetyIndicatorsByValue(self, indicatorLowerBound=0, indicatorUpperBound=sys.maxint):
129  ''' Recursively delete indicators with values below indicatorLowerBound
130  and greater than indicatorUpperBound. '''
131  drop_list = []
132 
133  if(self.collisionPoints):
134  for frame in self.collisionPoints:
135  for i in range(len(self.collisionPoints[frame])):
136  if(self.collisionPoints[frame][i].indicator < indicatorLowerBound or self.collisionPoints[frame][i].indicator > indicatorUpperBound):
137  self.collisionPoints[frame][i] = None
138  drop_list.append([frame,i])
139  self.collisionPoints[frame] = filter(None, self.collisionPoints[frame])
140  self.collisionPoints = dict((k, v) for k, v in self.collisionPoints.items() if v)
141 
142  if(drop_list):
143  self.indicators.pop(Interaction.indicatorNames[7],None)
144  self.genSafetyIndicators()
145 
146  return len(drop_list)
147 

◆ genInteractionDescriptors()

def lib.int.Interaction.genInteractionDescriptors (   self)

Definition at line 94 of file int.py.

94  def genInteractionDescriptors(self):
95  self.interactionDescriptors = {}
96  for t in self.getTimeInterval():
97  t1 = t - self.roadUser1.getFirstInstant()
98  t2 = t - self.roadUser2.getFirstInstant()
99  try: incidence_angle = tvaLib.Geo.vectorsToAngleDegCC(self.roadUser1.velocities.getXCoordinates()[t1], self.roadUser1.velocities.getYCoordinates()[t1], self.roadUser2.velocities.getXCoordinates()[t2], self.roadUser2.velocities.getYCoordinates()[t2])
100  except IndexError: incidence_angle = None #Ignore potential issues if the reported length of an object differs than its stored length usually a minor bug
101  self.interactionDescriptors[t] = InteractionInstantDescriptor(incidence_angle)
102 

◆ genSafetyIndicators()

def lib.int.Interaction.genSafetyIndicators (   self)
Rebuild interaction instants from list of collision points. 

Definition at line 87 of file int.py.

87  def genSafetyIndicators(self):
88  ''' Rebuild interaction instants from list of collision points. '''
89  indicators = {}
90  for i, cp in self.collisionPoints.iteritems():
91  indicators[i] = SafetyPoint.computeExpectedIndicator(cp)
92  self.addIndicator(TrafIntIndicators_TemporalIndicator(Interaction.indicatorNames[7], indicators))
93 

◆ getAggregatedInterAngle()

def lib.int.Interaction.getAggregatedInterAngle (   self,
  percentile = 0.5,
  minimumProbability = 0.0 
)
Pull list of points, sort interaction angle, and return percentile value 

Definition at line 230 of file int.py.

230  def getAggregatedInterAngle(self, percentile=0.5, minimumProbability=0.0):
231  ''' Pull list of points, sort interaction angle, and return percentile value '''
232  angles = [self.getInteractionDescriptors()[descriptor].getIncidenceAngle() for descriptor in self.getInteractionDescriptors()]
233  return tvaLib.Math.getPercentileKeyFromList(angles, percentile, sorting=True)
234 
235 
236 
237 

◆ getAggregatedPointList()

def lib.int.Interaction.getAggregatedPointList (   self,
  method = 0,
  percentile = 0.15,
  minimumProbability = 0.0,
  format = 'points',
  kwargs 
)

Definition at line 215 of file int.py.

215  def getAggregatedPointList(self, method=0, percentile=0.15, minimumProbability=0.0, format='points', **kwargs):
216  points = self.getPointList(**kwargs)
217  if(not points): return None
218 
219  if(method==1):
220  pair_indicator = tvaLib.Math.getPercentileKeyFromList(points, percentile, sorting=True, sortingColumnIx=0)
221  if(pair_indicator[3]> minimumProbability): return pair_indicator
222  elif(method==3):
223  pair_indicator = tvaLib.Math.getPercentileKeyFromList(points, percentile, sorting=True, sortingColumnIx=3)
224  if(pair_indicator[3]> minimumProbability): return pair_indicator
225  else:
226  for pair in points:
227  if(pair[3] > minimumProbability):
228  return pair
229 

◆ getInstantCount()

def lib.int.Interaction.getInstantCount (   self)

Definition at line 79 of file int.py.

79  def getInstantCount(self):
80  return self.getLastInstant()-self.getFirstInstant()+1
81 

◆ getInstantWIndicatorCount()

def lib.int.Interaction.getInstantWIndicatorCount (   self,
  indicatorName = None 
)

Definition at line 82 of file int.py.

82  def getInstantWIndicatorCount(self, indicatorName=None):
83  if(indicatorName==None): indicatorName=Interaction.indicatorNames[7]
84  if(self.getIndicator(indicatorName)): return len(self.getIndicator(indicatorName))
85  else: return 0
86 

◆ getInteractionDescriptors()

def lib.int.Interaction.getInteractionDescriptors (   self)

Definition at line 103 of file int.py.

103  def getInteractionDescriptors(self):
104  try: return self.interactionDescriptors
105  except AttributeError:
106  self.genInteractionDescriptors()
107  return self.interactionDescriptors
108 

◆ getPointList()

def lib.int.Interaction.getPointList (   self,
  ptype = 'CP',
  atInstant = None,
  alignRestrictions = None,
  maxIndThreshold = sys.maxint,
  aggregateInstants = True,
  max_inst_prob = 1.0,
  verbose = 0 
)
Input:
    ======
    ptype             -> The type of point: CP|CZ
    alignRestrictions -> [[laneIx,Smin,Smax],...] A series of sections 
                 identified by align index and bounded between
                 curvilinear distances Smin and Smax. Only 
                 indicators originating from within these
                 sections will be returned.
    maxIndThreshold   -> Indicator values above this will be ignored.
    aggregateInstants -> For interaction-instants with more than one
                 indicator if the same type, return a weighted
                 average according to probability. Defaults to
                 True.
    
    Return format:
    ==============
      0      1   2   3     4     5     6     7          8
    [[value1,px1,py1,prob1,time1,num11,num12,descriptor,exposure_list1],[value2,px2,...],...]

Definition at line 148 of file int.py.

148  def getPointList(self, ptype='CP', atInstant=None, alignRestrictions=None, maxIndThreshold=sys.maxint, aggregateInstants=True, max_inst_prob=1.0, verbose=0):
149  ''' Input:
150  ======
151  ptype -> The type of point: CP|CZ
152  alignRestrictions -> [[laneIx,Smin,Smax],...] A series of sections
153  identified by align index and bounded between
154  curvilinear distances Smin and Smax. Only
155  indicators originating from within these
156  sections will be returned.
157  maxIndThreshold -> Indicator values above this will be ignored.
158  aggregateInstants -> For interaction-instants with more than one
159  indicator if the same type, return a weighted
160  average according to probability. Defaults to
161  True.
162 
163  Return format:
164  ==============
165  0 1 2 3 4 5 6 7 8
166  [[value1,px1,py1,prob1,time1,num11,num12,descriptor,exposure_list1],[value2,px2,...],...]
167  '''
168 
169 
170  userNum1 = list(self.roadUserNumbers)[0]
171  try: userNum2 = list(self.roadUserNumbers)[1]
172  except:
173  userNum2 = None
174  if(verbose >= 2): tvaLib.printWarning('Interaction has unexpected userNum listing (only one found)', 'Warning')
175 
176 
177  if(ptype=='CZ'): pointInstants = self.crossingZones
178  else: pointInstants = self.collisionPoints
179  if(atInstant is not None):
180  if(int(atInstant) in pointInstants): pointInstants = {int(atInstant): pointInstants[int(atInstant)]}
181  else: return []
182 
183 
184  point_list = []
185  if(pointInstants):
186  for pointInstantKey in pointInstants:
187  # Verify optional restrictions along alignment sections
188  if(alignRestrictions):
189  relative_time1 = pointInstantKey-self.roadUser1.getFirstInstant()
190  relative_time2 = pointInstantKey-self.roadUser2.getFirstInstant()
191  obj1MeetsRestriction = False
192  obj2MeetsRestriction = False
193  for alignRestriction in alignRestrictions:
194  if(self.roadUser1.curvilinearPositions.getLanes()[relative_time1] == alignRestriction[0] and self.roadUser1.curvilinearPositions.getXCoordinates()[relative_time1] >= alignRestriction[1] and self.roadUser1.curvilinearPositions.getXCoordinates()[relative_time1] <= alignRestriction[2]): obj1MeetsRestriction = True
195  if(self.roadUser2.curvilinearPositions.getLanes()[relative_time2] == alignRestriction[0] and self.roadUser2.curvilinearPositions.getXCoordinates()[relative_time2] >= alignRestriction[1] and self.roadUser2.curvilinearPositions.getXCoordinates()[relative_time2] <= alignRestriction[2]): obj2MeetsRestriction = True
196  if(not obj1MeetsRestriction or not obj2MeetsRestriction): continue
197 
198 
199 
200  instantPoints = [[point.indicator, point.x, point.y, point.probability, pointInstantKey, userNum1, userNum2] for point in pointInstants[pointInstantKey] if point.indicator < maxIndThreshold]
201 
202 
203  try: descriptor = self.getInteractionDescriptors()[pointInstantKey]
204  except: descriptor = None
205 
206  try: exposure = self.exposure
207  except: exposure = None
208 
209 
211  if(aggregateInstants and instantPoints): point_list.append([sum([x[0]*x[3] for x in instantPoints])/sum([x[3] for x in instantPoints]), instantPoints[0][1], instantPoints[0][2], min(sum([x[3] for x in instantPoints]),max_inst_prob), instantPoints[0][4], instantPoints[0][5], instantPoints[0][6], descriptor, exposure])
212  else: point_list += instantPoints
213  return point_list
214 

Member Data Documentation

◆ collisionPoints

lib.int.Interaction.collisionPoints

Definition at line 120 of file int.py.

◆ interactionDescriptors

lib.int.Interaction.interactionDescriptors

Definition at line 95 of file int.py.

◆ user1Hash

lib.int.Interaction.user1Hash

Definition at line 75 of file int.py.

◆ user2Hash

lib.int.Interaction.user2Hash

Definition at line 76 of file int.py.


The documentation for this class was generated from the following file: