Mercurial Hosting > traffic-intelligence
comparison python/poly_utils.py @ 603:c7ece0f0ced9
refine
author | Mohamed Gomaa |
---|---|
date | Sat, 04 May 2013 18:01:43 -0400 |
parents | 273c200ec32e |
children |
comparison
equal
deleted
inserted
replaced
602:480c8edf177e | 603:c7ece0f0ced9 |
---|---|
4 import utils | 4 import utils |
5 from moving import TimeInterval | 5 from moving import TimeInterval |
6 import numpy as np | 6 import numpy as np |
7 | 7 |
8 __metaclass__ = type | 8 __metaclass__ = type |
9 from indicators import SeverityIndicator | |
9 | 10 |
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 | 11 |
19 def loadNewInteractions(videoFilename,interactionType, roaduserNum1,roaduserNum2, selectedIndicators=[]): | 12 def loadNewInteractions(videoFilename,interactionType,dirname, extension, indicatorsNames, roaduserNum1,roaduserNum2, selectedIndicators=[]): |
20 '''Loads interactions from the POLY traffic event format''' | 13 '''Loads interactions from the POLY traffic event format''' |
21 from events import Interaction | 14 from events import Interaction |
22 from indicators import SeverityIndicator | 15 filename= dirname + videoFilename + extension |
23 #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 |
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) | 17 file = utils.openCheck(filename) |
26 if (not file): | 18 if (not file): |
27 return [] | 19 return [] |
28 interactions = [] | 20 #interactions = [] |
29 interactionNum = 0 | 21 interactionNum = 0 |
30 data= np.loadtxt(filename) | 22 data= np.loadtxt(filename) |
31 indicatorFrameNums= data[:,0] | 23 indicatorFrameNums= data[:,0] |
32 inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2) | 24 inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2) |
33 inter.addVideoFilename(videoFilename) | 25 inter.addVideoFilename(videoFilename) |
41 values= {} | 33 values= {} |
42 for i,t in enumerate(indicatorFrameNums): | 34 for i,t in enumerate(indicatorFrameNums): |
43 values[t] = [data[i,index] for index in selectedIndicators] | 35 values[t] = [data[i,index] for index in selectedIndicators] |
44 inter.addIndicator(SeverityIndicator('selectedIndicators', values)) | 36 inter.addIndicator(SeverityIndicator('selectedIndicators', values)) |
45 | 37 |
46 interactions.append(inter) | 38 #interactions.append(inter) |
47 file.close() | 39 file.close() |
48 return interactions | 40 #return interactions |
41 return inter | |
49 | 42 |
43 |