annotate python/poly_utils.py @ 597:484cc1d6cfd1

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