311
|
1 #! /usr/bin/env python
|
|
2 '''Various utilities to load data saved by the POLY new output(s)'''
|
|
3 import sys
|
|
4 import utils
|
|
5 from moving import TimeInterval
|
|
6 import numpy as np
|
|
7
|
|
8 __metaclass__ = type
|
|
9
|
|
10 # inputs variables
|
|
11 #dirname= 'G:/0-phdstart/Code/trial/indicatorsNew/'
|
|
12 #extension= '-indicatorsNew.csv'
|
|
13 #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'}
|
|
14 ''' min Distance case'''
|
|
15 dirname= 'G:/0-phdstart/Code/trial/minDistanceIndicator/'
|
|
16 extension= '-minDistanceInd.csv'
|
|
17 indicatorsNames= {1:'minDistance'}
|
|
18
|
|
19 def loadNewInteractions(videoFilename,interactionType, roaduserNum1,roaduserNum2, selectedIndicators=[]):
|
|
20 '''Loads interactions from the POLY traffic event format'''
|
|
21 from events import Interaction
|
|
22 from indicators import SeverityIndicator
|
|
23 #filename= dirname + videoFilename + extension
|
|
24 filename= dirname + interactionType+ '-' + videoFilename + extension # case of min distance todo: change the saving format to be matched with all outputs
|
|
25 file = utils.openCheck(filename)
|
|
26 if (not file):
|
|
27 return []
|
|
28 interactions = []
|
|
29 interactionNum = 0
|
|
30 data= np.loadtxt(filename)
|
|
31 indicatorFrameNums= data[:,0]
|
|
32 inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2)
|
|
33 inter.addVideoFilename(videoFilename)
|
|
34 inter.addInteractionType(interactionType)
|
|
35 for key in indicatorsNames.keys():
|
|
36 values= {}
|
|
37 for i,t in enumerate(indicatorFrameNums):
|
|
38 values[t] = data[i,key]
|
|
39 inter.addIndicator(SeverityIndicator(indicatorsNames[key], values))
|
|
40 if selectedIndicators !=[]:
|
|
41 values= {}
|
|
42 for i,t in enumerate(indicatorFrameNums):
|
|
43 values[t] = [data[i,index] for index in selectedIndicators]
|
|
44 inter.addIndicator(SeverityIndicator('selectedIndicators', values))
|
|
45
|
|
46 interactions.append(inter)
|
|
47 file.close()
|
|
48 return interactions
|
|
49
|