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
|
603
|
9 from indicators import SeverityIndicator
|
311
|
10
|
|
11
|
603
|
12 def loadNewInteractions(videoFilename,interactionType,dirname, extension, indicatorsNames, roaduserNum1,roaduserNum2, selectedIndicators=[]):
|
311
|
13 '''Loads interactions from the POLY traffic event format'''
|
|
14 from events import Interaction
|
603
|
15 filename= dirname + videoFilename + extension
|
|
16 #filename= dirname + interactionType+ '-' + videoFilename + extension # case of min distance todo: change the saving format to be matched with all outputs
|
311
|
17 file = utils.openCheck(filename)
|
|
18 if (not file):
|
|
19 return []
|
603
|
20 #interactions = []
|
311
|
21 interactionNum = 0
|
|
22 data= np.loadtxt(filename)
|
|
23 indicatorFrameNums= data[:,0]
|
|
24 inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2)
|
|
25 inter.addVideoFilename(videoFilename)
|
|
26 inter.addInteractionType(interactionType)
|
|
27 for key in indicatorsNames.keys():
|
|
28 values= {}
|
|
29 for i,t in enumerate(indicatorFrameNums):
|
|
30 values[t] = data[i,key]
|
|
31 inter.addIndicator(SeverityIndicator(indicatorsNames[key], values))
|
|
32 if selectedIndicators !=[]:
|
|
33 values= {}
|
|
34 for i,t in enumerate(indicatorFrameNums):
|
|
35 values[t] = [data[i,index] for index in selectedIndicators]
|
|
36 inter.addIndicator(SeverityIndicator('selectedIndicators', values))
|
|
37
|
603
|
38 #interactions.append(inter)
|
311
|
39 file.close()
|
603
|
40 #return interactions
|
|
41 return inter
|
311
|
42
|
603
|
43
|