Mercurial Hosting > traffic-intelligence
changeset 311:273c200ec32e
load data saved by the POLY new output
author | Mohamed Gomaa |
---|---|
date | Wed, 03 Apr 2013 22:46:39 -0400 |
parents | f7ca78a11ea6 |
children | 6c068047edbf |
files | python/poly_utils.py |
diffstat | 1 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/poly_utils.py Wed Apr 03 22:46:39 2013 -0400 @@ -0,0 +1,49 @@ +#! /usr/bin/env python +'''Various utilities to load data saved by the POLY new output(s)''' +import sys +import utils +from moving import TimeInterval +import numpy as np + +__metaclass__ = type + +# inputs variables +#dirname= 'G:/0-phdstart/Code/trial/indicatorsNew/' +#extension= '-indicatorsNew.csv' +#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'} +''' min Distance case''' +dirname= 'G:/0-phdstart/Code/trial/minDistanceIndicator/' +extension= '-minDistanceInd.csv' +indicatorsNames= {1:'minDistance'} + +def loadNewInteractions(videoFilename,interactionType, roaduserNum1,roaduserNum2, selectedIndicators=[]): + '''Loads interactions from the POLY traffic event format''' + from events import Interaction + from indicators import SeverityIndicator + #filename= dirname + videoFilename + extension + filename= dirname + interactionType+ '-' + videoFilename + extension # case of min distance todo: change the saving format to be matched with all outputs + file = utils.openCheck(filename) + if (not file): + return [] + interactions = [] + interactionNum = 0 + data= np.loadtxt(filename) + indicatorFrameNums= data[:,0] + inter = Interaction(interactionNum, TimeInterval(indicatorFrameNums[0],indicatorFrameNums[-1]), roaduserNum1, roaduserNum2) + inter.addVideoFilename(videoFilename) + inter.addInteractionType(interactionType) + for key in indicatorsNames.keys(): + values= {} + for i,t in enumerate(indicatorFrameNums): + values[t] = data[i,key] + inter.addIndicator(SeverityIndicator(indicatorsNames[key], values)) + if selectedIndicators !=[]: + values= {} + for i,t in enumerate(indicatorFrameNums): + values[t] = [data[i,index] for index in selectedIndicators] + inter.addIndicator(SeverityIndicator('selectedIndicators', values)) + + interactions.append(inter) + file.close() + return interactions +