Mercurial Hosting > traffic-intelligence
comparison python/storage.py @ 72:575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 14 Jan 2011 19:49:20 -0500 |
parents | 7b06d649122b |
children | 99e807c29753 |
comparison
equal
deleted
inserted
replaced
71:45e958ccd9bd | 72:575340e6fce3 |
---|---|
23 import sys | 23 import sys |
24 sys.exit() | 24 sys.exit() |
25 | 25 |
26 def createObject(numbers): | 26 def createObject(numbers): |
27 firstFrameNum = int(numbers[1]) | 27 firstFrameNum = int(numbers[1]) |
28 time = moving.TimeInterval(firstFrameNum, firstFrameNum+int(numbers[2])-1) | |
29 obj = moving.MovingObject(num = int(numbers[0]), timeInterval = time) | |
30 # do the geometry and usertype | 28 # do the geometry and usertype |
31 | 29 |
32 # firstFrameNum = int(numbers[1]) | 30 firstFrameNum = int(numbers[1]) |
33 # lastFrameNum = firstFrameNum+int(numbers[2])-1 | 31 lastFrameNum = firstFrameNum+int(numbers[2])-1 |
34 # f = Feature(sequenceNum, firstFrameNum, lastFrameNum, int(numbers[0])) | 32 #time = moving.TimeInterval(firstFrameNum, firstFrameNum+int(numbers[2])-1) |
35 # f.sizeLength = float(numbers[8]) | 33 obj = moving.MovingObject(num = int(numbers[0]), |
36 # f.sizeWidth = float(numbers[9]) | 34 timeInterval = moving.TimeInterval(firstFrameNum, lastFrameNum), |
37 # f.userType = int(numbers[10]) | 35 positions = moving.Trajectory([[float(numbers[6])],[float(numbers[7])]]), |
38 # f.positions = [[float(numbers[6])],[float(numbers[7])]] | 36 userType = int(numbers[10])) |
39 # f.speeds = [float(numbers[11])] | 37 obj.curvilinearPositions = moving.Trajectory([[float(numbers[5])],[float(numbers[4])]]) # X is the longitudinal coordinate |
38 obj.speeds = [float(numbers[11])] | |
39 obj.size = [float(numbers[8]), float(numbers[9])] # 8 lengh, 9 width # TODO: temporary, should use a geometry object | |
40 return obj | 40 return obj |
41 | 41 |
42 numbers = input.readline().strip().split() | 42 numbers = input.readline().strip().split() |
43 if (len(numbers) > 0): | 43 if (len(numbers) > 0): |
44 obj = createObject(numbers) | 44 obj = createObject(numbers) |
45 | 45 |
46 for line in input: | 46 for line in input: |
47 numbers = line.strip().split() | 47 numbers = line.strip().split() |
48 if obj.num != int(numbers[0]): | 48 if obj.num != int(numbers[0]): |
49 # check and adapt the length to deal with issues in NGSIM data | 49 # check and adapt the length to deal with issues in NGSIM data |
50 #objLength = f.length() | 50 if (obj.length() != obj.positions.length()): |
51 #if (objLength != len(f.positions[0])): | 51 print 'length pb with object %s (%d,%d)' % (obj.num,obj.length(),obj.positions.length()) |
52 # print 'length pb with object %s (%d,%d)' % (f.num,objLength,len(f.positions[0])) | 52 obj.last = obj.getFirstInstant()+obj.positions.length()-1 |
53 # f.lastFrameNum = f.getFirstFrameNum()+len(f.positions[0])-1 | 53 #obj.velocities = utils.computeVelocities(f.positions) # compare norm to speeds ? |
54 #f.velocities = utils.computeVelocities(f.positions) # compare norm to speeds ? | |
55 objects.append(obj) | 54 objects.append(obj) |
56 if (nObjects>0) and (len(objects)>=nObjects): | 55 if (nObjects>0) and (len(objects)>=nObjects): |
57 break | 56 break |
58 obj = createObject(numbers) | 57 obj = createObject(numbers) |
59 else: | 58 else: |
60 print(numbers[6]) | 59 print(numbers[6]) |
61 # f.positions[0] += [float(numbers[6])] | 60 obj.positions.addPositionXY(float(numbers[6]), float(numbers[7])) |
62 # f.positions[1] += [float(numbers[7])] | 61 obj.curvilinearPositions.addPositionXY(float(numbers[5]), float(numbers[4])) |
63 # f.speeds += [float(numbers[11])] | 62 obj.speeds.append(float(numbers[11])) |
64 | 63 |
65 # if (f.sizeWidth != float(numbers[9])): | 64 if (obj.size[0] != float(numbers[8])): |
66 # print 'changed width obj %d' % (f.num) | 65 print 'changed length obj %d' % (f.num) |
67 # if (f.sizeLength != float(numbers[8])): | 66 if (obj.size[1] != float(numbers[9])): |
68 # print 'changed length obj %d' % (f.num) | 67 print 'changed width obj %d' % (f.num) |
69 | 68 |
70 input.close() | 69 input.close() |
71 return objects | 70 return objects |
72 | 71 |
73 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0): | 72 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0): |
89 out.close() | 88 out.close() |
90 | 89 |
91 | 90 |
92 | 91 |
93 | 92 |
94 if __name__ == "__main__": | 93 # if __name__ == "__main__": |
95 import doctest | 94 # import doctest |
96 import unittest | 95 # import unittest |
97 suite = doctest.DocFileSuite('tests/ubc_utils.txt') | 96 # suite = doctest.DocFileSuite('tests/ubc_utils.txt') |
98 unittest.TextTestRunner().run(suite) | 97 # unittest.TextTestRunner().run(suite) |
99 #doctest.testmod() | 98 # #doctest.testmod() |
100 #doctest.testfile("example.txt") | 99 # #doctest.testfile("example.txt") |