Mercurial Hosting > traffic-intelligence
annotate python/storage.py @ 645:5ed2118c959d
added function to count collisions in vissim
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 13 Apr 2015 00:11:21 +0200 |
parents | bfaa6b95dae2 |
children | 6680a69d5bf3 |
rev | line source |
---|---|
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
2 # -*- coding: utf-8 -*- |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
3 '''Various utilities to save and load data''' |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
4 |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
5 import utils, moving, events, indicators |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
6 |
417
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
7 import sqlite3, logging |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
8 |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
9 __metaclass__ = type |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
10 |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
11 |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
12 commentChar = '#' |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
13 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
14 delimiterChar = '%'; |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
15 |
50 | 16 ngsimUserTypes = {'twowheels':1, |
204
966c2cd2bd9f
added code to load object trajectories (average of features)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
203
diff
changeset
|
17 'car':2, |
966c2cd2bd9f
added code to load object trajectories (average of features)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
203
diff
changeset
|
18 'truck':3} |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
19 |
259
8ab76b95ee72
added code to save collision points and crossing zones in txt files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
246
diff
changeset
|
20 ######################### |
8ab76b95ee72
added code to save collision points and crossing zones in txt files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
246
diff
changeset
|
21 # Sqlite |
8ab76b95ee72
added code to save collision points and crossing zones in txt files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
246
diff
changeset
|
22 ######################### |
8ab76b95ee72
added code to save collision points and crossing zones in txt files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
246
diff
changeset
|
23 |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
24 # utils |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
25 def printDBError(error): |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
26 print('DB Error: {}'.format(error)) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
27 |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
28 def dropTables(connection, tableNames): |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
29 'deletes the table with names in tableNames' |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
30 try: |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
31 cursor = connection.cursor() |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
32 for tableName in tableNames: |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
33 cursor.execute('DROP TABLE IF EXISTS '+tableName) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
34 except sqlite3.OperationalError as error: |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
35 printDBError(error) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
36 |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
37 # TODO: add test if database connection is open |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
38 # IO to sqlite |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
39 def writeTrajectoriesToSqlite(objects, outputFilename, trajectoryType, objectNumbers = -1): |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
40 """ |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
41 This function writers trajectories to a specified sqlite file |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
42 @param[in] objects -> a list of trajectories |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
43 @param[in] trajectoryType - |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
44 @param[out] outputFilename -> the .sqlite file containting the written objects |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
45 @param[in] objectNumber : number of objects loaded |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
46 """ |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
47 connection = sqlite3.connect(outputFilename) |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
48 cursor = connection.cursor() |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
49 |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
50 schema = "CREATE TABLE IF NOT EXISTS \"positions\"(trajectory_id INTEGER,frame_number INTEGER, x_coordinate REAL, y_coordinate REAL, PRIMARY KEY(trajectory_id, frame_number))" |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
51 cursor.execute(schema) |
212
ce44605f888a
minor modifications
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
211
diff
changeset
|
52 |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
53 trajectory_id = 0 |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
54 frame_number = 0 |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
55 if trajectoryType == 'feature': |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
56 if type(objectNumbers) == int and objectNumbers == -1: |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
57 for trajectory in objects: |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
58 trajectory_id += 1 |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
59 frame_number = 0 |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
60 for position in trajectory.getPositions(): |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
61 frame_number += 1 |
212
ce44605f888a
minor modifications
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
211
diff
changeset
|
62 query = "insert into positions (trajectory_id, frame_number, x_coordinate, y_coordinate) values (?,?,?,?)" |
ce44605f888a
minor modifications
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
211
diff
changeset
|
63 cursor.execute(query,(trajectory_id,frame_number,position.x,position.y)) |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
64 |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
65 connection.commit() |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
66 connection.close() |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
67 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
68 def writeFeaturesToSqlite(objects, outputFilename, trajectoryType, objectNumbers = -1): |
552
ca6bded754ac
corrected more bugs from merging (caught in regression tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
549
diff
changeset
|
69 '''write features trajectories maintain trajectory ID,velocities dataset ''' |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
70 connection = sqlite3.connect(outputFilename) |
546 | 71 cursor = connection.cursor() |
72 | |
73 cursor.execute("CREATE TABLE IF NOT EXISTS \"positions\"(trajectory_id INTEGER,frame_number INTEGER, x_coordinate REAL, y_coordinate REAL, PRIMARY KEY(trajectory_id, frame_number))") | |
74 cursor.execute("CREATE TABLE IF NOT EXISTS \"velocities\"(trajectory_id INTEGER,frame_number INTEGER, x_coordinate REAL, y_coordinate REAL, PRIMARY KEY(trajectory_id, frame_number))") | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
75 |
546 | 76 if trajectoryType == 'feature': |
77 if type(objectNumbers) == int and objectNumbers == -1: | |
78 for trajectory in objects: | |
79 trajectory_id = trajectory.num | |
80 frame_number = trajectory.timeInterval.first | |
81 for position,velocity in zip(trajectory.getPositions(),trajectory.getVelocities()): | |
82 cursor.execute("insert into positions (trajectory_id, frame_number, x_coordinate, y_coordinate) values (?,?,?,?)",(trajectory_id,frame_number,position.x,position.y)) | |
83 cursor.execute("insert into velocities (trajectory_id, frame_number, x_coordinate, y_coordinate) values (?,?,?,?)",(trajectory_id,frame_number,velocity.x,velocity.y)) | |
84 frame_number += 1 | |
85 | |
86 connection.commit() | |
87 connection.close() | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
88 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
89 def writePrototypesToSqlite(prototypes,nMatching, outputFilename): |
546 | 90 """ prototype dataset is a dictionary with keys== routes, values== prototypes Ids """ |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
91 connection = sqlite3.connect(outputFilename) |
546 | 92 cursor = connection.cursor() |
93 | |
94 cursor.execute("CREATE TABLE IF NOT EXISTS \"prototypes\"(prototype_id INTEGER,routeIDstart INTEGER,routeIDend INTEGER, nMatching INTEGER, PRIMARY KEY(prototype_id))") | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
95 |
546 | 96 for route in prototypes.keys(): |
97 if prototypes[route]!=[]: | |
98 for i in prototypes[route]: | |
99 cursor.execute("insert into prototypes (prototype_id, routeIDstart,routeIDend, nMatching) values (?,?,?,?)",(i,route[0],route[1],nMatching[route][i])) | |
100 | |
101 connection.commit() | |
102 connection.close() | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
103 |
546 | 104 def loadPrototypesFromSqlite(filename): |
105 """ | |
106 This function loads the prototype file in the database | |
107 It returns a dictionary for prototypes for each route and nMatching | |
108 """ | |
109 prototypes = {} | |
110 nMatching={} | |
111 | |
112 connection = sqlite3.connect(filename) | |
113 cursor = connection.cursor() | |
114 | |
115 try: | |
116 cursor.execute('SELECT * from prototypes order by prototype_id, routeIDstart,routeIDend, nMatching') | |
117 except sqlite3.OperationalError as error: | |
118 utils.printDBError(error) | |
119 return [] | |
120 | |
121 for row in cursor: | |
122 route=(row[1],row[2]) | |
123 if route not in prototypes.keys(): | |
124 prototypes[route]=[] | |
125 prototypes[route].append(row[0]) | |
126 nMatching[row[0]]=row[3] | |
127 | |
128 connection.close() | |
129 return prototypes,nMatching | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
130 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
131 def writeLabelsToSqlite(labels, outputFilename): |
546 | 132 """ labels is a dictionary with keys: routes, values: prototypes Ids |
133 """ | |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
134 connection = sqlite3.connect(outputFilename) |
546 | 135 cursor = connection.cursor() |
136 | |
137 cursor.execute("CREATE TABLE IF NOT EXISTS \"labels\"(object_id INTEGER,routeIDstart INTEGER,routeIDend INTEGER, prototype_id INTEGER, PRIMARY KEY(object_id))") | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
138 |
546 | 139 for route in labels.keys(): |
140 if labels[route]!=[]: | |
141 for i in labels[route]: | |
142 for j in labels[route][i]: | |
143 cursor.execute("insert into labels (object_id, routeIDstart,routeIDend, prototype_id) values (?,?,?,?)",(j,route[0],route[1],i)) | |
144 | |
145 connection.commit() | |
146 connection.close() | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
147 |
546 | 148 def loadLabelsFromSqlite(filename): |
149 labels = {} | |
150 | |
151 connection = sqlite3.connect(filename) | |
152 cursor = connection.cursor() | |
153 | |
154 try: | |
155 cursor.execute('SELECT * from labels order by object_id, routeIDstart,routeIDend, prototype_id') | |
156 except sqlite3.OperationalError as error: | |
157 utils.printDBError(error) | |
158 return [] | |
159 | |
160 for row in cursor: | |
161 route=(row[1],row[2]) | |
162 p=row[3] | |
163 if route not in labels.keys(): | |
164 labels[route]={} | |
165 if p not in labels[route].keys(): | |
166 labels[route][p]=[] | |
167 labels[route][p].append(row[0]) | |
168 | |
169 connection.close() | |
170 return labels | |
607 | 171 def writeSpeedPrototypeToSqlite(prototypes,nmatching, outFilename): |
172 """ to match the format of second layer prototypes""" | |
173 connection = sqlite3.connect(outFilename) | |
174 cursor = connection.cursor() | |
175 | |
176 cursor.execute("CREATE TABLE IF NOT EXISTS \"speedprototypes\"(spdprototype_id INTEGER,prototype_id INTEGER,routeID_start INTEGER, routeID_end INTEGER, nMatching INTEGER, PRIMARY KEY(spdprototype_id))") | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
177 |
607 | 178 for route in prototypes.keys(): |
179 if prototypes[route]!={}: | |
180 for i in prototypes[route]: | |
181 if prototypes[route][i]!= []: | |
182 for j in prototypes[route][i]: | |
183 cursor.execute("insert into speedprototypes (spdprototype_id,prototype_id, routeID_start, routeID_end, nMatching) values (?,?,?,?,?)",(j,i,route[0],route[1],nmatching[j])) | |
184 | |
185 connection.commit() | |
186 connection.close() | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
187 |
607 | 188 def loadSpeedPrototypeFromSqlite(filename): |
189 """ | |
190 This function loads the prototypes table in the database of name <filename>. | |
191 """ | |
192 prototypes = {} | |
193 nMatching={} | |
194 connection = sqlite3.connect(filename) | |
195 cursor = connection.cursor() | |
196 | |
197 try: | |
198 cursor.execute('SELECT * from speedprototypes order by spdprototype_id,prototype_id, routeID_start, routeID_end, nMatching') | |
199 except sqlite3.OperationalError as error: | |
200 utils.printDBError(error) | |
201 return [] | |
202 | |
203 for row in cursor: | |
204 route=(row[2],row[3]) | |
205 if route not in prototypes.keys(): | |
206 prototypes[route]={} | |
207 if row[1] not in prototypes[route].keys(): | |
208 prototypes[route][row[1]]=[] | |
209 prototypes[route][row[1]].append(row[0]) | |
210 nMatching[row[0]]=row[4] | |
211 | |
212 connection.close() | |
213 return prototypes,nMatching | |
214 | |
546 | 215 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
216 def writeRoutesToSqlite(Routes, outputFilename): |
546 | 217 """ This function writes the activity path define by start and end IDs""" |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
218 connection = sqlite3.connect(outputFilename) |
546 | 219 cursor = connection.cursor() |
220 | |
221 cursor.execute("CREATE TABLE IF NOT EXISTS \"routes\"(object_id INTEGER,routeIDstart INTEGER,routeIDend INTEGER, PRIMARY KEY(object_id))") | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
222 |
546 | 223 for route in Routes.keys(): |
224 if Routes[route]!=[]: | |
225 for i in Routes[route]: | |
226 cursor.execute("insert into routes (object_id, routeIDstart,routeIDend) values (?,?,?)",(i,route[0],route[1])) | |
227 | |
228 connection.commit() | |
229 connection.close() | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
230 |
546 | 231 def loadRoutesFromSqlite(filename): |
232 Routes = {} | |
233 | |
234 connection = sqlite3.connect(filename) | |
235 cursor = connection.cursor() | |
236 | |
237 try: | |
238 cursor.execute('SELECT * from routes order by object_id, routeIDstart,routeIDend') | |
239 except sqlite3.OperationalError as error: | |
240 utils.printDBError(error) | |
241 return [] | |
242 | |
243 for row in cursor: | |
244 route=(row[1],row[2]) | |
245 if route not in Routes.keys(): | |
246 Routes[route]=[] | |
247 Routes[route].append(row[0]) | |
248 | |
249 connection.close() | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
250 return Routes |
546 | 251 |
252 def setRoutes(filename, objects): | |
253 connection = sqlite3.connect(filename) | |
254 cursor = connection.cursor() | |
255 for obj in objects: | |
256 cursor.execute('update objects set startRouteID = {} where object_id = {}'.format(obj.startRouteID, obj.getNum())) | |
619
dc2d0a0d7fe1
merged code from Mohamed Gomaa Mohamed for the use of points of interests in mation pattern learning and motion prediction (TRB 2015)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
diff
changeset
|
257 cursor.execute('update objects set endRouteID = {} where object_id = {}'.format(obj.endRouteID, obj.getNum())) |
546 | 258 connection.commit() |
259 connection.close() | |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
260 |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
261 def setRoadUserTypes(filename, objects): |
330
00800ebae698
corrected bug in db loading
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
329
diff
changeset
|
262 '''Saves the user types of the objects in the sqlite database stored in filename |
00800ebae698
corrected bug in db loading
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
329
diff
changeset
|
263 The objects should exist in the objects table''' |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
264 connection = sqlite3.connect(filename) |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
265 cursor = connection.cursor() |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
266 for obj in objects: |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
267 cursor.execute('update objects set road_user_type = {} where object_id = {}'.format(obj.getUserType(), obj.getNum())) |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
268 connection.commit() |
208
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
269 connection.close() |
d9855499fc88
Added functions to write trajectories through sqlite
Francois Belisle <belisle.francois@gmail.com>
parents:
204
diff
changeset
|
270 |
209
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
271 def loadPrototypeMatchIndexesFromSqlite(filename): |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
272 """ |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
273 This function loads the prototypes table in the database of name <filename>. |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
274 It returns a list of tuples representing matching ids : [(prototype_id, matched_trajectory_id),...] |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
275 """ |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
276 matched_indexes = [] |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
277 |
211 | 278 connection = sqlite3.connect(filename) |
209
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
279 cursor = connection.cursor() |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
280 |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
281 try: |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
282 cursor.execute('SELECT * from prototypes order by prototype_id, trajectory_id_matched') |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
283 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
284 printDBError(error) |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
285 return [] |
209
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
286 |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
287 for row in cursor: |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
288 matched_indexes.append((row[0],row[1])) |
211 | 289 |
290 connection.close() | |
209
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
291 return matched_indexes |
746d02cea65f
Added function to read Prototype indexes matches.
Francois Belisle <belisle.francois@gmail.com>
parents:
208
diff
changeset
|
292 |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
293 def getTrajectoryIdQuery(objectNumbers, trajectoryType): |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
294 if trajectoryType == 'feature': |
330
00800ebae698
corrected bug in db loading
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
329
diff
changeset
|
295 statementBeginning = 'where trajectory_id ' |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
296 elif trajectoryType == 'object': |
587
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
297 statementBeginning = 'and OF.object_id ' |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
298 elif trajectoryType == 'bbtop' or 'bbbottom': |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
299 statementBeginning = 'where object_id ' |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
300 else: |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
301 print('no trajectory type was chosen') |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
302 |
585
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
303 if objectNumbers is None: |
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
304 query = '' |
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
305 elif type(objectNumbers) == int: |
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
306 query = statementBeginning+'between 0 and {0} '.format(objectNumbers) |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
307 elif type(objectNumbers) == list: |
330
00800ebae698
corrected bug in db loading
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
329
diff
changeset
|
308 query = statementBeginning+'in ('+', '.join([str(n) for n in objectNumbers])+') ' |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
309 return query |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
310 |
585
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
311 def loadTrajectoriesFromTable(connection, tableName, trajectoryType, objectNumbers = None): |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
312 '''Loads trajectories (in the general sense) from the given table |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
313 can be positions or velocities |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
314 |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
315 returns a moving object''' |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
316 cursor = connection.cursor() |
204
966c2cd2bd9f
added code to load object trajectories (average of features)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
203
diff
changeset
|
317 |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
318 try: |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
319 idQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType) |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
320 if trajectoryType == 'feature': |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
321 queryStatement = 'SELECT * from '+tableName+' '+idQuery+'ORDER BY trajectory_id, frame_number' |
417
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
322 cursor.execute(queryStatement) |
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
323 logging.debug(queryStatement) |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
324 elif trajectoryType == 'object': |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
325 queryStatement = 'SELECT OF.object_id, P.frame_number, avg(P.x_coordinate), avg(P.y_coordinate) from '+tableName+' P, objects_features OF where P.trajectory_id = OF.trajectory_id '+idQuery+'group by OF.object_id, P.frame_number ORDER BY OF.object_id, P.frame_number' |
587
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
326 cursor.execute(queryStatement) |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
327 logging.debug(queryStatement) |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
328 elif trajectoryType in ['bbtop', 'bbbottom']: |
587
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
329 if trajectoryType == 'bbtop': |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
330 corner = 'top_left' |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
331 elif trajectoryType == 'bbbottom': |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
332 corner = 'bottom_right' |
589
5800a87f11ae
corrected one bug and changed attribute names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
588
diff
changeset
|
333 queryStatement = 'SELECT object_id, frame_number, x_'+corner+', y_'+corner+' FROM '+tableName+' '+idQuery+'ORDER BY object_id, frame_number' |
417
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
334 cursor.execute(queryStatement) |
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
335 logging.debug(queryStatement) |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
336 else: |
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
337 print('no trajectory type was chosen') |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
338 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
339 printDBError(error) |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
340 return [] |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
341 |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
342 objId = -1 |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
343 obj = None |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
344 objects = [] |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
345 for row in cursor: |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
346 if row[0] != objId: |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
347 objId = row[0] |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
348 if obj is not None and obj.length() == obj.positions.length(): |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
349 objects.append(obj) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
350 elif obj is not None: |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
351 print('Object {} is missing {} positions'.format(obj.getNum(), int(obj.length())-obj.positions.length())) |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
352 obj = moving.MovingObject(row[0], timeInterval = moving.TimeInterval(row[1], row[1]), positions = moving.Trajectory([[row[2]],[row[3]]])) |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
353 else: |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
354 obj.timeInterval.last = row[1] |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
355 obj.positions.addPositionXY(row[2],row[3]) |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
356 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
357 if obj is not None and obj.length() == obj.positions.length(): |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
358 objects.append(obj) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
359 elif obj is not None: |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
360 print('Object {} is missing {} positions'.format(obj.getNum(), int(obj.length())-obj.positions.length())) |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
361 |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
362 return objects |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
363 |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
364 def loadUserTypesFromTable(cursor, trajectoryType, objectNumbers): |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
365 objectIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
366 if objectIdQuery == '': |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
367 cursor.execute('SELECT object_id, road_user_type from objects') |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
368 else: |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
369 cursor.execute('SELECT object_id, road_user_type from objects where '+objectIdQuery[7:]) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
370 userTypes = {} |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
371 for row in cursor: |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
372 userTypes[row[0]] = row[1] |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
373 return userTypes |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
374 |
585
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
375 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = None): |
aab2242ea88c
minor modification of objectNumbers to None
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
584
diff
changeset
|
376 '''Loads the first objectNumbers objects or the indices in objectNumbers from the database''' |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
377 connection = sqlite3.connect(filename) |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
378 |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
379 objects = loadTrajectoriesFromTable(connection, 'positions', trajectoryType, objectNumbers) |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
380 objectVelocities = loadTrajectoriesFromTable(connection, 'velocities', trajectoryType, objectNumbers) |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
381 |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
382 if len(objectVelocities) > 0: |
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
383 for o,v in zip(objects, objectVelocities): |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
384 if o.getNum() == v.getNum(): |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
385 o.velocities = v.positions |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
386 o.velocities.duplicateLastPosition() # avoid having velocity shorter by one position than positions |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
387 else: |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
388 print('Could not match positions {0} with velocities {1}'.format(o.getNum(), v.getNum())) |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
235
diff
changeset
|
389 |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
390 if trajectoryType == 'object': |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
391 cursor = connection.cursor() |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
392 try: |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
393 # attribute feature numbers to objects |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
394 objectIdQuery = getTrajectoryIdQuery(objectNumbers, trajectoryType) |
417
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
395 queryStatement = 'SELECT P.trajectory_id, OF.object_id from positions P, objects_features OF where P.trajectory_id = OF.trajectory_id '+objectIdQuery+'group by P.trajectory_id order by OF.object_id' # order is important to group all features per object |
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
396 cursor.execute(queryStatement) |
a2ff03a52b73
added basic logging capability for debugging
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
394
diff
changeset
|
397 logging.debug(queryStatement) |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
398 |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
399 featureNumbers = {} |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
400 for row in cursor: |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
401 objId = row[1] |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
402 if objId not in featureNumbers: |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
403 featureNumbers[objId] = [row[0]] |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
404 else: |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
405 featureNumbers[objId].append(row[0]) |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
406 |
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
407 for obj in objects: |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
408 obj.featureNumbers = featureNumbers[obj.getNum()] |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
409 |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
410 # load userType |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
411 userTypes = loadUserTypesFromTable(cursor, trajectoryType, objectNumbers) |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
412 for obj in objects: |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
413 obj.userType = userTypes[obj.getNum()] |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
414 |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
415 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
416 printDBError(error) |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
417 objects = [] |
263
c71540470057
reorganized loading trajectories and objects, added loading feature numbers for objects (the set of features grouped as one moving object
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
259
diff
changeset
|
418 |
143
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
419 connection.close() |
436b87d4b992
wrote the code to load positions from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
78
diff
changeset
|
420 return objects |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
421 |
589
5800a87f11ae
corrected one bug and changed attribute names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
588
diff
changeset
|
422 def loadGroundTruthFromSqlite(filename, gtType = 'bb', gtNumbers = None): |
588
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
423 'Loads bounding box annotations (ground truth) from an SQLite ' |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
424 connection = sqlite3.connect(filename) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
425 gt = [] |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
426 |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
427 if gtType == 'bb': |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
428 topCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbtop', gtNumbers) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
429 bottomCorners = loadTrajectoriesFromTable(connection, 'bounding_boxes', 'bbbottom', gtNumbers) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
430 userTypes = loadUserTypesFromTable(connection.cursor(), 'object', gtNumbers) # string format is same as object |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
431 |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
432 for t, b in zip(topCorners, bottomCorners): |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
433 num = t.getNum() |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
434 if t.getNum() == b.getNum(): |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
435 annotation = moving.BBAnnotation(num, t.getTimeInterval(), t, b, userTypes[num]) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
436 gt.append(annotation) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
437 else: |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
438 print ('Unknown type of annotation {}'.format(gtType)) |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
439 |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
440 connection.close() |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
441 return gt |
c5406edbcf12
added loading ground truth annotations (ground truth) from polytrack format
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
587
diff
changeset
|
442 |
584
5bda87ac0a69
renames removeFromSqlite to deleteFromSqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
564
diff
changeset
|
443 def deleteFromSqlite(filename, dataType): |
5bda87ac0a69
renames removeFromSqlite to deleteFromSqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
564
diff
changeset
|
444 'Deletes (drops) some tables in the filename depending on type of data' |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
445 import os |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
446 if os.path.isfile(filename): |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
447 connection = sqlite3.connect(filename) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
448 if dataType == 'object': |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
449 dropTables(connection, ['objects', 'objects_features']) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
450 elif dataType == 'interaction': |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
451 dropTables(connection, ['interactions', 'indicators']) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
452 elif dataType == 'bb': |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
453 dropTables(connection, ['bounding_boxes']) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
454 else: |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
455 print('Unknown data type {} to delete from database'.format(dataType)) |
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
456 connection.close() |
344
14a2405f54f8
slight modification to safety analysis and generalized script to delete computed data (objects and interactions)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
343
diff
changeset
|
457 else: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
458 print('{} does not exist'.format(filename)) |
235
584613399513
added script and functions to remove object tables
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
218
diff
changeset
|
459 |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
460 def createInteractionTable(cursor): |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
461 cursor.execute('CREATE TABLE IF NOT EXISTS interactions (id INTEGER PRIMARY KEY, object_id1 INTEGER, object_id2 INTEGER, first_frame_number INTEGER, last_frame_number INTEGER, FOREIGN KEY(object_id1) REFERENCES objects(id), FOREIGN KEY(object_id2) REFERENCES objects(id))') |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
462 |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
463 def createIndicatorTables(cursor): |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
464 # cursor.execute('CREATE TABLE IF NOT EXISTS indicators (id INTEGER PRIMARY KEY, interaction_id INTEGER, indicator_type INTEGER, FOREIGN KEY(interaction_id) REFERENCES interactions(id))') |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
465 # cursor.execute('CREATE TABLE IF NOT EXISTS indicator_values (indicator_id INTEGER, frame_number INTEGER, value REAL, FOREIGN KEY(indicator_id) REFERENCES indicators(id), PRIMARY KEY(indicator_id, frame_number))') |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
466 cursor.execute('CREATE TABLE IF NOT EXISTS indicators (interaction_id INTEGER, indicator_type INTEGER, frame_number INTEGER, value REAL, FOREIGN KEY(interaction_id) REFERENCES interactions(id), PRIMARY KEY(interaction_id, indicator_type, frame_number))') |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
467 |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
468 def saveInteraction(cursor, interaction): |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
469 roadUserNumbers = list(interaction.getRoadUserNumbers()) |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
470 cursor.execute('INSERT INTO interactions VALUES({}, {}, {}, {}, {})'.format(interaction.getNum(), roadUserNumbers[0], roadUserNumbers[1], interaction.getFirstInstant(), interaction.getLastInstant())) |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
471 |
340
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
472 def saveInteractions(filename, interactions): |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
473 'Saves the interactions in the table' |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
474 connection = sqlite3.connect(filename) |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
475 cursor = connection.cursor() |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
476 try: |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
477 createInteractionTable(cursor) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
478 for inter in interactions: |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
479 saveInteraction(cursor, inter) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
480 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
481 printDBError(error) |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
482 connection.commit() |
340
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
483 connection.close() |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
484 |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
485 def saveIndicator(cursor, interactionNum, indicator): |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
486 for instant in indicator.getTimeInterval(): |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
487 if indicator[instant]: |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
488 cursor.execute('INSERT INTO indicators VALUES({}, {}, {}, {})'.format(interactionNum, events.Interaction.indicatorNameToIndices[indicator.getName()], instant, indicator[instant])) |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
489 |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
490 def saveIndicators(filename, interactions, indicatorNames = events.Interaction.indicatorNames): |
340
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
491 'Saves the indicator values in the table' |
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
492 connection = sqlite3.connect(filename) |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
493 cursor = connection.cursor() |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
494 try: |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
495 createInteractionTable(cursor) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
496 createIndicatorTables(cursor) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
497 for inter in interactions: |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
498 saveInteraction(cursor, inter) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
499 for indicatorName in indicatorNames: |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
500 indicator = inter.getIndicator(indicatorName) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
501 if indicator is not None: |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
502 saveIndicator(cursor, inter.getNum(), indicator) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
503 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
504 printDBError(error) |
341
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
505 connection.commit() |
2f39c4ed0b62
first version of indicator saving to sqlite
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
340
diff
changeset
|
506 connection.close() |
340
1046b7346886
work in progress on storing indicator values
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
335
diff
changeset
|
507 |
482
f6415f012640
adding functionalities (save images directly to display trajectories to create movies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
417
diff
changeset
|
508 def loadInteractions(filename): |
f6415f012640
adding functionalities (save images directly to display trajectories to create movies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
417
diff
changeset
|
509 '''Loads interaction and their indicators |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
510 |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
511 TODO choose the interactions to load''' |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
512 interactions = [] |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
513 connection = sqlite3.connect(filename) |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
514 cursor = connection.cursor() |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
515 try: |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
516 cursor.execute('select INT.id, INT.object_id1, INT.object_id2, INT.first_frame_number, INT.last_frame_number, IND.indicator_type, IND.frame_number, IND.value from interactions INT, indicators IND where INT.id = IND.interaction_id ORDER BY INT.id, IND.indicator_type') |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
517 interactionNum = -1 |
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
518 indicatorTypeNum = -1 |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
519 tmpIndicators = {} |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
520 for row in cursor: |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
521 if row[0] != interactionNum: |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
522 interactionNum = row[0] |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
523 interactions.append(events.Interaction(interactionNum, moving.TimeInterval(row[3],row[4]), row[1], row[2])) |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
524 interactions[-1].indicators = {} |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
525 if indicatorTypeNum != row[5]: |
628
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
526 indicatorName = events.Interaction.indicatorNames[indicatorTypeNum] |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
527 indicatorValues = {row[6]:row[7]} |
977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
619
diff
changeset
|
528 interactions[-1].indicators[indicatorName] = indicators.SeverityIndicator(indicatorName, indicatorValues) |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
529 indicatorTypeNum = row[5] |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
530 else: |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
531 indicatorValues[row[6]] = row[7] |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
532 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
533 printDBError(error) |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
534 return [] |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
535 connection.close() |
343
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
536 return interactions |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
537 # load first and last object instants |
74e437ab5f11
first version of indicator loading code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
342
diff
changeset
|
538 # CREATE TEMP TABLE IF NOT EXISTS object_instants AS SELECT OF.object_id, min(frame_number) as first_instant, max(frame_number) as last_instant from positions P, objects_features OF where P.trajectory_id = OF.trajectory_id group by OF.object_id order by OF.object_id |
342
4d69486869a5
work on loading indicators
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
341
diff
changeset
|
539 |
390
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
540 def createBoundingBoxTable(filename, invHomography = None): |
482
f6415f012640
adding functionalities (save images directly to display trajectories to create movies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
417
diff
changeset
|
541 '''Create the table to store the object bounding boxes in image space |
390
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
542 ''' |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
543 connection = sqlite3.connect(filename) |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
544 cursor = connection.cursor() |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
545 try: |
394
6567fee37c16
renamed table for bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
393
diff
changeset
|
546 cursor.execute('CREATE TABLE IF NOT EXISTS bounding_boxes (object_id INTEGER, frame_number INTEGER, x_top_left REAL, y_top_left REAL, x_bottom_right REAL, y_bottom_right REAL, PRIMARY KEY(object_id, frame_number))') |
6567fee37c16
renamed table for bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
393
diff
changeset
|
547 cursor.execute('INSERT INTO bounding_boxes SELECT object_id, frame_number, min(x), min(y), max(x), max(y) from ' |
390
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
548 '(SELECT object_id, frame_number, (x*{}+y*{}+{})/w as x, (x*{}+y*{}+{})/w as y from ' |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
549 '(SELECT OF.object_id, P.frame_number, P.x_coordinate as x, P.y_coordinate as y, P.x_coordinate*{}+P.y_coordinate*{}+{} as w from positions P, objects_features OF where P.trajectory_id = OF.trajectory_id)) '.format(invHomography[0,0], invHomography[0,1], invHomography[0,2], invHomography[1,0], invHomography[1,1], invHomography[1,2], invHomography[2,0], invHomography[2,1], invHomography[2,2])+ |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
550 'GROUP BY object_id, frame_number') |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
551 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
552 printDBError(error) |
390
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
553 connection.commit() |
12be4a0cb9aa
sql code to create bounding boxes in image space
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
382
diff
changeset
|
554 connection.close() |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
555 |
586
ff4f0ce46ca6
modified name for loading bounding boxes (only for display)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
585
diff
changeset
|
556 def loadBoundingBoxTableForDisplay(filename): |
393
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
557 connection = sqlite3.connect(filename) |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
558 cursor = connection.cursor() |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
559 boundingBoxes = {} # list of bounding boxes for each instant |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
560 try: |
394
6567fee37c16
renamed table for bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
393
diff
changeset
|
561 cursor.execute('SELECT name FROM sqlite_master WHERE type=\'table\' AND name=\'bounding_boxes\'') |
393
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
562 result = [row for row in cursor] |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
563 if len(result) > 0: |
394
6567fee37c16
renamed table for bounding boxes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
393
diff
changeset
|
564 cursor.execute('SELECT * FROM bounding_boxes') |
393
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
565 for row in cursor: |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
566 boundingBoxes.setdefault(row[1], []).append([moving.Point(row[2], row[3]), moving.Point(row[4], row[5])]) |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
567 except sqlite3.OperationalError as error: |
491
343cfd185ca6
minor changes and reaarrangements
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
482
diff
changeset
|
568 printDBError(error) |
393
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
569 return boundingBoxes |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
570 connection.close() |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
571 return boundingBoxes |
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
572 |
587
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
573 def loadBoundingBoxTable(filename): |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
574 connection = sqlite3.connect(filename) |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
575 cursor = connection.cursor() |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
576 boundingBoxes = [] |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
577 |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
578 try: |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
579 pass |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
580 except sqlite3.OperationalError as error: |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
581 printDBError(error) |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
582 return boundingBoxes |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
583 connection.close() |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
584 return boundingBoxes |
cf578ba866da
added code to load bounding box corners as trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
585 |
393
eaf7765221d9
added code to create bounding boxes and display them (inc scripts)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
390
diff
changeset
|
586 |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
587 ######################### |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
588 # txt files |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
589 ######################### |
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
590 |
525
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
591 def openCheck(filename, option = 'r', quitting = False): |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
592 '''Open file filename in read mode by default |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
593 and checks it is open''' |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
594 try: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
595 return open(filename, option) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
596 except IOError: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
597 print 'File %s could not be opened.' % filename |
525
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
598 if quitting: |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
599 from sys import exit |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
600 exit() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
601 return None |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
602 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
603 def readline(f, commentCharacters = commentChar): |
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
604 '''Modified readline function to skip comments |
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
605 Can take a list of characters or a string (in will work in both)''' |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
606 s = f.readline() |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
607 while (len(s) > 0) and s[0] in commentCharacters: |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
608 s = f.readline() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
609 return s.strip() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
610 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
611 def getLines(f, commentCharacters = commentChar): |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
612 '''Gets a complete entry (all the lines) in between delimiterChar.''' |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
613 dataStrings = [] |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
614 s = readline(f, commentCharacters) |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
615 while len(s) > 0: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
616 dataStrings += [s.strip()] |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
617 s = readline(f, commentCharacters) |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
618 return dataStrings |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
619 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
620 def writeList(filename, l): |
514
1ba618fb0f70
corrected bug from merging and argument issue in display-trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
621 f = openCheck(filename, 'w') |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
622 for x in l: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
623 f.write('{}\n'.format(x)) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
624 f.close() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
625 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
626 def loadListStrings(filename, commentCharacters = commentChar): |
514
1ba618fb0f70
corrected bug from merging and argument issue in display-trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
627 f = openCheck(filename, 'r') |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
628 result = getLines(f, commentCharacters) |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
629 f.close() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
630 return result |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
631 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
632 def getValuesFromINIFile(filename, option, delimiterChar = '=', commentCharacters = commentChar): |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
633 values = [] |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
634 for l in loadListStrings(filename, commentCharacters): |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
635 if l.startswith(option): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
636 values.append(l.split(delimiterChar)[1].strip()) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
637 return values |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
638 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
639 class FakeSecHead(object): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
640 '''Add fake section header [asection] |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
641 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
642 from http://stackoverflow.com/questions/2819696/parsing-properties-file-in-python/2819788#2819788 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
643 use read_file in Python 3.2+ |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
644 ''' |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
645 def __init__(self, fp): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
646 self.fp = fp |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
647 self.sechead = '[main]\n' |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
648 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
649 def readline(self): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
650 if self.sechead: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
651 try: return self.sechead |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
652 finally: self.sechead = None |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
653 else: return self.fp.readline() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
654 |
642
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
655 def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None, usePandas = False, nDecimals = 2): |
525
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
656 '''Reads data from VISSIM .fzp trajectory file |
527
37830a831818
loading from VISSIM trajectory data works
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
526
diff
changeset
|
657 simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM |
37830a831818
loading from VISSIM trajectory data works
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
526
diff
changeset
|
658 for example, there seems to be 5 simulation steps per simulated second in VISSIM, |
37830a831818
loading from VISSIM trajectory data works
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
526
diff
changeset
|
659 so simulationStepsPerTimeUnit should be 5, |
37830a831818
loading from VISSIM trajectory data works
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
526
diff
changeset
|
660 so that all times correspond to the number of the simulation step (and can be stored as integers) |
525
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
661 |
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
662 Assumed to be sorted over time''' |
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
663 objects = {} # dictionary of objects index by their id |
7124c7d2a663
first draft of loading from VISSIM file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
524
diff
changeset
|
664 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
665 if usePandas: |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
666 from pandas import read_csv |
642
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
667 from numpy import min, max, round |
645
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
668 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1) |
642
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
669 data['LANE'] = data['LANE\LINK\NO'].astype(str)+'_'+data['LANE\INDEX'].astype(str) |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
670 data['TIME'] = data['$VEHICLE:SIMSEC']*simulationStepsPerTimeUnit |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
671 grouped = data.loc[:,['NO','TIME']].groupby(['NO'], as_index = False) |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
672 instants = grouped['TIME'].agg({'first': min, 'last': max}) |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
673 if warmUpLastInstant is not None: |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
674 instants = instants[instants['first'] >= warmUpLastInstant] |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
675 for row_index, row in instants.iterrows(): |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
676 objNum = int(row['NO']) |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
677 tmp = data[data['NO'] == objNum] |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
678 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
679 # positions should be rounded to nDecimals decimals only |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
680 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = round(tmp['POS'].tolist(), nDecimals), Y = round(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) |
932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
681 return objects.values() |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
682 else: |
643
bfaa6b95dae2
added function to plot curvilinear position as a function of time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
642
diff
changeset
|
683 firstInstants = {} |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
684 inputfile = openCheck(filename, quitting = True) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
685 # data = pd.read_csv(filename, skiprows=15, delimiter=';') |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
686 # skip header: 15 lines + 1 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
687 line = readline(inputfile, '*$') |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
688 while len(line) > 0:#for line in inputfile: |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
689 data = line.strip().split(';') |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
690 objNum = int(data[1]) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
691 instant = int(float(data[0])*simulationStepsPerTimeUnit) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
692 s = float(data[4]) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
693 y = float(data[5]) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
694 lane = data[2]+'_'+data[3] |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
695 if objNum not in firstInstants: |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
696 firstInstants[objNum] = instant |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
697 if warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant: |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
698 if nObjects < 0 or len(objects) < nObjects: |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
699 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
700 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
701 if (warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects: |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
702 objects[objNum].timeInterval.last = instant |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
703 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) |
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
704 line = readline(inputfile, '*$') |
524
1dced8932b08
corrected bugs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
514
diff
changeset
|
705 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
706 return objects.values() |
645
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
707 |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
708 def countCollisionsVissim(filename, collisionTimeDifference = 0.2): |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
709 '''Counts the number of collisions per lane in a VISSIM trajectory file |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
710 |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
711 To distinguish between cars passing and collision, |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
712 one checks when the sign of the position difference inverts |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
713 (if the time are closer than collisionTimeDifference)''' |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
714 from pandas import read_csv, merge |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
715 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = ['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC', 'NO', 'POS']) |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
716 merged = merge(data, data, how='inner', left_on=['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC'], right_on=['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC'], sort = False) |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
717 merged = merged[merged['NO_x']>merged['NO_y']] |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
718 |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
719 nCollisions = 0 |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
720 for name, group in merged.groupby(['LANE\LINK\NO', 'LANE\INDEX', 'NO_x', 'NO_y']): |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
721 diff = group['POS_x']-group['POS_y'] |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
722 if len(diff) >= 2 and min(diff) < 0 and max(diff) > 0: |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
723 xidx = diff[diff < 0].argmax() |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
724 yidx = diff[diff > 0].argmin() |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
725 if abs(group.loc[xidx, '$VEHICLE:SIMSEC'] - group.loc[yidx, '$VEHICLE:SIMSEC']) <= collisionTimeDifference: |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
726 nCollisions += 1 |
5ed2118c959d
added function to count collisions in vissim
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
643
diff
changeset
|
727 return nCollisions |
524
1dced8932b08
corrected bugs
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
514
diff
changeset
|
728 |
173
319a04ba9033
function name change
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
143
diff
changeset
|
729 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1): |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
730 '''Reads data from the trajectory data provided by NGSIM project |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
731 and returns the list of Feature objects''' |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
732 objects = [] |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
733 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
734 inputfile = openCheck(filename, quitting = True) |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
735 |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
736 def createObject(numbers): |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
737 firstFrameNum = int(numbers[1]) |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
738 # do the geometry and usertype |
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
739 |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
740 firstFrameNum = int(numbers[1]) |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
741 lastFrameNum = firstFrameNum+int(numbers[2])-1 |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
742 #time = moving.TimeInterval(firstFrameNum, firstFrameNum+int(numbers[2])-1) |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
743 obj = moving.MovingObject(num = int(numbers[0]), |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
744 timeInterval = moving.TimeInterval(firstFrameNum, lastFrameNum), |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
745 positions = moving.Trajectory([[float(numbers[6])],[float(numbers[7])]]), |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
746 userType = int(numbers[10])) |
78
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
747 obj.userType = int(numbers[10]) |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
748 obj.laneNums = [int(numbers[13])] |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
749 obj.precedingVehicles = [int(numbers[14])] # lead vehicle (before) |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
750 obj.followingVehicles = [int(numbers[15])] # following vehicle (after) |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
751 obj.spaceHeadways = [float(numbers[16])] # feet |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
752 obj.timeHeadways = [float(numbers[17])] # seconds |
327
42f2b46ec210
added class for trajectories in curvilinear coordinates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
326
diff
changeset
|
753 obj.curvilinearPositions = moving.CurvilinearTrajectory([float(numbers[5])],[float(numbers[4])], obj.laneNums) # X is the longitudinal coordinate |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
754 obj.speeds = [float(numbers[11])] |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
755 obj.size = [float(numbers[8]), float(numbers[9])] # 8 lengh, 9 width # TODO: temporary, should use a geometry object |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
756 return obj |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
757 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
758 numbers = readline(inputfile).strip().split() |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
759 if (len(numbers) > 0): |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
760 obj = createObject(numbers) |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
761 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
762 for line in inputfile: |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
763 numbers = line.strip().split() |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
764 if obj.getNum() != int(numbers[0]): |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
765 # check and adapt the length to deal with issues in NGSIM data |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
766 if (obj.length() != obj.positions.length()): |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
767 print 'length pb with object %s (%d,%d)' % (obj.getNum(),obj.length(),obj.positions.length()) |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
768 obj.last = obj.getFirstInstant()+obj.positions.length()-1 |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
769 #obj.velocities = utils.computeVelocities(f.positions) # compare norm to speeds ? |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
770 objects.append(obj) |
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
771 if (nObjects>0) and (len(objects)>=nObjects): |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
772 break |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
773 obj = createObject(numbers) |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
774 else: |
327
42f2b46ec210
added class for trajectories in curvilinear coordinates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
326
diff
changeset
|
775 obj.laneNums.append(int(numbers[13])) |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
776 obj.positions.addPositionXY(float(numbers[6]), float(numbers[7])) |
542
a3add9f751ef
added differentiate function for curvilinear trajectories and modified the addPosition functions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
541
diff
changeset
|
777 obj.curvilinearPositions.addPositionSYL(float(numbers[5]), float(numbers[4]), obj.laneNums[-1]) |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
778 obj.speeds.append(float(numbers[11])) |
78
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
779 obj.precedingVehicles.append(int(numbers[14])) |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
780 obj.followingVehicles.append(int(numbers[15])) |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
781 obj.spaceHeadways.append(float(numbers[16])) |
99e807c29753
added loading other information from NGSIM
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
72
diff
changeset
|
782 obj.timeHeadways.append(float(numbers[17])) |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
783 |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
784 if (obj.size[0] != float(numbers[8])): |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
785 print 'changed length obj %d' % (obj.getNum()) |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
786 if (obj.size[1] != float(numbers[9])): |
329
a70c205ebdd9
added sqlite code, in particular to load and save road user type
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
327
diff
changeset
|
787 print 'changed width obj %d' % (obj.getNum()) |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
788 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
789 inputfile.close() |
7
ffddccfab7f9
loading shell objects from NGSIM works
Nicolas Saunier <nico@confins.net>
parents:
0
diff
changeset
|
790 return objects |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
791 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
792 def convertNgsimFile(inputfile, outputfile, append = False, nObjects = -1, sequenceNum = 0): |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
793 '''Reads data from the trajectory data provided by NGSIM project |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
794 and converts to our current format.''' |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
795 if append: |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
796 out = openCheck(outputfile,'a') |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
797 else: |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
798 out = openCheck(outputfile,'w') |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
799 nObjectsPerType = [0,0,0] |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
800 |
564
36605d843be5
modified bug for reading vissim files, cleaned use of readline with multiple type of characters for comments (to ignore)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
552
diff
changeset
|
801 features = loadNgsimFile(inputfile, sequenceNum) |
0
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
802 for f in features: |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
803 nObjectsPerType[f.userType-1] += 1 |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
804 f.write(out) |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
805 |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
806 print nObjectsPerType |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
807 |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
808 out.close() |
aed8eb63cdde
initial commit with non-functional python code for NGSIM
Nicolas Saunier <nico@confins.net>
parents:
diff
changeset
|
809 |
335
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
810 def writePositionsToCsv(f, obj): |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
811 timeInterval = obj.getTimeInterval() |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
812 positions = obj.getPositions() |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
813 curvilinearPositions = obj.getCurvilinearPositions() |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
814 for i in xrange(int(obj.length())): |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
815 p1 = positions[i] |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
816 s = '{},{},{},{}'.format(obj.num,timeInterval[i],p1.x,p1.y) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
817 if curvilinearPositions is not None: |
335
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
818 p2 = curvilinearPositions[i] |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
819 s += ',{},{}'.format(p2[0],p2[1]) |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
820 f.write(s+'\n') |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
821 |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
822 def writeTrajectoriesToCsv(filename, objects): |
514
1ba618fb0f70
corrected bug from merging and argument issue in display-trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
823 f = openCheck(filename, 'w') |
335
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
824 for i,obj in enumerate(objects): |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
825 writePositionsToCsv(f, obj) |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
826 f.close() |
3950bfe22768
added functions to export trajectories to csv
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
330
diff
changeset
|
827 |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
828 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
829 ######################### |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
830 # Utils to read .ini type text files for configuration, meta data... |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
831 ######################### |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
832 |
536
95276d310972
renamed TrackingParameters to ProcessParameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
527
diff
changeset
|
833 class ProcessParameters: |
537
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
834 '''Class for all parameters controlling data processing: input, |
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
835 method parameters, etc. for tracking, classification and safety |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
836 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
837 Note: framerate is already taken into account''' |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
838 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
839 def loadConfigFile(self, filename): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
840 from ConfigParser import ConfigParser |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
841 from numpy import loadtxt |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
842 from os import path |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
843 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
844 config = ConfigParser() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
845 config.readfp(FakeSecHead(openCheck(filename))) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
846 self.sectionHeader = config.sections()[0] |
537
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
847 # Tracking/display parameters |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
848 self.videoFilename = config.get(self.sectionHeader, 'video-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
849 self.databaseFilename = config.get(self.sectionHeader, 'database-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
850 self.homographyFilename = config.get(self.sectionHeader, 'homography-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
851 if (path.exists(self.homographyFilename)): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
852 self.homography = loadtxt(self.homographyFilename) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
853 else: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
854 self.homography = None |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
855 self.intrinsicCameraFilename = config.get(self.sectionHeader, 'intrinsic-camera-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
856 if (path.exists(self.intrinsicCameraFilename)): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
857 self.intrinsicCameraMatrix = loadtxt(self.intrinsicCameraFilename) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
858 else: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
859 self.intrinsicCameraMatrix = None |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
860 distortionCoefficients = getValuesFromINIFile(filename, 'distortion-coefficients', '=') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
861 self.distortionCoefficients = [float(x) for x in distortionCoefficients] |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
862 self.undistortedImageMultiplication = config.getfloat(self.sectionHeader, 'undistorted-size-multiplication') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
863 self.undistort = config.getboolean(self.sectionHeader, 'undistort') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
864 self.firstFrameNum = config.getint(self.sectionHeader, 'frame1') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
865 self.videoFrameRate = config.getfloat(self.sectionHeader, 'video-fps') |
377 | 866 |
537
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
867 # Classification parameters |
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
868 |
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
869 |
6c264b914846
work on classification parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
870 # Safety parameters |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
871 self.maxPredictedSpeed = config.getfloat(self.sectionHeader, 'max-predicted-speed')/3.6/self.videoFrameRate |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
872 self.predictionTimeHorizon = config.getfloat(self.sectionHeader, 'prediction-time-horizon')*self.videoFrameRate |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
873 self.collisionDistance = config.getfloat(self.sectionHeader, 'collision-distance') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
874 self.crossingZones = config.getboolean(self.sectionHeader, 'crossing-zones') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
875 self.predictionMethod = config.get(self.sectionHeader, 'prediction-method') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
876 self.nPredictedTrajectories = config.getint(self.sectionHeader, 'npredicted-trajectories') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
877 self.maxNormalAcceleration = config.getfloat(self.sectionHeader, 'max-normal-acceleration')/self.videoFrameRate**2 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
878 self.maxNormalSteering = config.getfloat(self.sectionHeader, 'max-normal-steering')/self.videoFrameRate |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
879 self.minExtremeAcceleration = config.getfloat(self.sectionHeader, 'min-extreme-acceleration')/self.videoFrameRate**2 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
880 self.maxExtremeAcceleration = config.getfloat(self.sectionHeader, 'max-extreme-acceleration')/self.videoFrameRate**2 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
881 self.maxExtremeSteering = config.getfloat(self.sectionHeader, 'max-extreme-steering')/self.videoFrameRate |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
882 self.useFeaturesForPrediction = config.getboolean(self.sectionHeader, 'use-features-prediction') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
883 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
884 def __init__(self, filename = None): |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
628
diff
changeset
|
885 if filename is not None: |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
886 self.loadConfigFile(filename) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
887 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
888 class SceneParameters: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
889 def __init__(self, config, sectionName): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
890 from ConfigParser import NoOptionError |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
891 from ast import literal_eval |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
892 try: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
893 self.sitename = config.get(sectionName, 'sitename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
894 self.databaseFilename = config.get(sectionName, 'data-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
895 self.homographyFilename = config.get(sectionName, 'homography-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
896 self.calibrationFilename = config.get(sectionName, 'calibration-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
897 self.videoFilename = config.get(sectionName, 'video-filename') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
898 self.frameRate = config.getfloat(sectionName, 'framerate') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
899 self.date = datetime.strptime(config.get(sectionName, 'date'), datetimeFormat) # 2011-06-22 11:00:39 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
900 self.translation = literal_eval(config.get(sectionName, 'translation')) # = [0.0, 0.0] |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
901 self.rotation = config.getfloat(sectionName, 'rotation') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
902 self.duration = config.getint(sectionName, 'duration') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
903 except NoOptionError as e: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
904 print(e) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
905 print('Not a section for scene meta-data') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
906 |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
907 @staticmethod |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
908 def loadConfigFile(filename): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
909 from ConfigParser import ConfigParser |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
910 config = ConfigParser() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
911 config.readfp(openCheck(filename)) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
912 configDict = dict() |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
913 for sectionName in config.sections(): |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
914 configDict[sectionName] = SceneParameters(config, sectionName) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
915 return configDict |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
491
diff
changeset
|
916 |
382
ba813f148ade
development for clustering
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
377
diff
changeset
|
917 |
607 | 918 |
215
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
919 if __name__ == "__main__": |
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
920 import doctest |
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
921 import unittest |
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
922 suite = doctest.DocFileSuite('tests/storage.txt') |
5e2983b05d4e
created first doctest tests for storage
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
212
diff
changeset
|
923 unittest.TextTestRunner().run(suite) |
72
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
924 # #doctest.testmod() |
575340e6fce3
corrected most of the method to load NGSIM data (adapted to the current MovingObject class
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
50
diff
changeset
|
925 # #doctest.testfile("example.txt") |