changeset 316:c5518a35df5f

merged
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 12 Apr 2013 15:22:00 -0400
parents 82b9be447608 (current diff) 43e62b9cb652 (diff)
children d280b881e860
files
diffstat 3 files changed, 80 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/python/events.py	Fri Apr 12 13:16:38 2013 -0400
+++ b/python/events.py	Fri Apr 12 15:22:00 2013 -0400
@@ -64,6 +64,12 @@
 
         # todo test for interaction instants and interval, compute indicators
 
+    def addVideoFilename(self,videoFilename):
+        self.videoFilename= videoFilename	
+
+    def addInteractionType(self,interactionType):
+	''' interaction types: conflict or collision if they are known'''
+        self.interactionType= interactionType			
 
 def createInteractions(objects):
     '''Create all interactions of two co-existing road users
--- a/python/indicators.py	Fri Apr 12 13:16:38 2013 -0400
+++ b/python/indicators.py	Fri Apr 12 15:22:00 2013 -0400
@@ -93,6 +93,31 @@
         plot([x/xfactor for x in time], [self.values[i] for i in time], options+marker, **kwargs)
         if self.maxValue:
             ylim(ymax = self.maxValue)
+	
+    def valueSorted(self):
+	''' return the values after sort the keys in the indicator
+    This should probably not be used: to delete''' 
+        values=[]
+        keys = self.values.keys()
+        keys.sort()
+        for key in keys:
+            values.append(self.values[key]) 
+        return values
+
+    @staticmethod
+    def getDLCSS(indic1, indic2, threshold, delta = float('inf') , method ='min' ):
+	''' compute the distance between two indicators using LCSS
+	two common methods are used: min or mean of the indicators length'''
+        l1 = indic1.valueSorted
+        l2 = indic2.valueSorted
+        DLCSS = None
+        if method == 'min':
+            DLCSS = 1- (LCSS(l1,l2, threshold, delta, distance))/min(len(l1),len(l2))
+        if method == 'mean':
+            average = len(l1)+len(l2)/2
+            DLCSS = 1- ((LCSS(l1,l2, threshold, delta, distance))/average)
+        return DLCSS
+		
 
 def computeDLCSS(indicator1, indicator2, threshold, delta = float('inf'), method= 'min'):
     ''' compute the distance between two indicators using LCSS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/poly_utils.py	Fri Apr 12 15:22:00 2013 -0400
@@ -0,0 +1,49 @@
+#! /usr/bin/env python
+'''Various utilities to load data saved by the POLY new output(s)'''
+import sys
+import utils
+from moving import  TimeInterval
+import numpy as np
+
+__metaclass__ = type
+
+# inputs variables	
+#dirname= 'G:/0-phdstart/Code/trial/indicatorsNew/'
+#extension= '-indicatorsNew.csv'
+#indicatorsNames= {1:'Distance',2:'Cosine',3:'collision Course Angle',4:'Velocity Cosine',5:'Velocity Angle',6:'Speed Differential',7:'Collision Probability',8:'Severity Index',9:'TTC'}
+''' min Distance case'''
+dirname= 'G:/0-phdstart/Code/trial/minDistanceIndicator/'
+extension= '-minDistanceInd.csv'
+indicatorsNames= {1:'minDistance'}
+
+def loadNewInteractions(videoFilename,interactionType, roaduserNum1,roaduserNum2, selectedIndicators=[]):
+    '''Loads interactions from the POLY traffic event format'''
+    from events import Interaction 
+    from indicators import SeverityIndicator
+    #filename= dirname + videoFilename + extension
+    filename= dirname + interactionType+ '-' + videoFilename + extension # case of min distance todo: change the saving format to be matched with all outputs
+    file = utils.openCheck(filename)
+    if (not file):
+        return []
+    interactions = []
+    interactionNum = 0
+    data= np.loadtxt(filename)
+    indicatorFrameNums= data[:,0]
+    inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2) 
+    inter.addVideoFilename(videoFilename)
+    inter.addInteractionType(interactionType)
+    for key in indicatorsNames.keys():
+        values= {}
+        for i,t in enumerate(indicatorFrameNums):
+            values[t] = data[i,key]
+        inter.addIndicator(SeverityIndicator(indicatorsNames[key], values))
+    if selectedIndicators !=[]:
+        values= {}
+        for i,t in enumerate(indicatorFrameNums):
+            values[t] = [data[i,index] for index in selectedIndicators]
+        inter.addIndicator(SeverityIndicator('selectedIndicators', values))	
+		
+    interactions.append(inter)
+    file.close()
+    return interactions
+