annotate python/poly_utils.py @ 603:c7ece0f0ced9

refine
author Mohamed Gomaa
date Sat, 04 May 2013 18:01:43 -0400
parents 273c200ec32e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
1 #! /usr/bin/env python
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
2 '''Various utilities to load data saved by the POLY new output(s)'''
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
3 import sys
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
4 import utils
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
5 from moving import TimeInterval
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
6 import numpy as np
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
7
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
8 __metaclass__ = type
603
Mohamed Gomaa
parents: 311
diff changeset
9 from indicators import SeverityIndicator
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
10
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
11
603
Mohamed Gomaa
parents: 311
diff changeset
12 def loadNewInteractions(videoFilename,interactionType,dirname, extension, indicatorsNames, roaduserNum1,roaduserNum2, selectedIndicators=[]):
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
13 '''Loads interactions from the POLY traffic event format'''
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
14 from events import Interaction
603
Mohamed Gomaa
parents: 311
diff changeset
15 filename= dirname + videoFilename + extension
Mohamed Gomaa
parents: 311
diff changeset
16 #filename= dirname + interactionType+ '-' + videoFilename + extension # case of min distance todo: change the saving format to be matched with all outputs
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
17 file = utils.openCheck(filename)
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
18 if (not file):
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
19 return []
603
Mohamed Gomaa
parents: 311
diff changeset
20 #interactions = []
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
21 interactionNum = 0
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
22 data= np.loadtxt(filename)
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
23 indicatorFrameNums= data[:,0]
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
24 inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2)
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
25 inter.addVideoFilename(videoFilename)
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
26 inter.addInteractionType(interactionType)
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
27 for key in indicatorsNames.keys():
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
28 values= {}
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
29 for i,t in enumerate(indicatorFrameNums):
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
30 values[t] = data[i,key]
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
31 inter.addIndicator(SeverityIndicator(indicatorsNames[key], values))
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
32 if selectedIndicators !=[]:
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
33 values= {}
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
34 for i,t in enumerate(indicatorFrameNums):
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
35 values[t] = [data[i,index] for index in selectedIndicators]
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
36 inter.addIndicator(SeverityIndicator('selectedIndicators', values))
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
37
603
Mohamed Gomaa
parents: 311
diff changeset
38 #interactions.append(inter)
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
39 file.close()
603
Mohamed Gomaa
parents: 311
diff changeset
40 #return interactions
Mohamed Gomaa
parents: 311
diff changeset
41 return inter
311
273c200ec32e load data saved by the POLY new output
Mohamed Gomaa
parents:
diff changeset
42
603
Mohamed Gomaa
parents: 311
diff changeset
43