annotate trafficintelligence/tests/tutorials.py @ 1028:cc5cb04b04b0

major update using the trafficintelligence package name and install through pip
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 15 Jun 2018 11:19:10 -0400
parents python/tests/tutorials.py@da665302c88d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
648
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 import unittest
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3 class TestNGSIM(unittest.TestCase):
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4 'Tutorial example for NGSIM data'
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 def test_ex1(self):
1028
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 648
diff changeset
7 from trafficintelligence import storage
648
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8 objects = storage.loadTrajectoriesFromNgsimFile('../samples/trajectories-0400-0415.txt',100)
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 for o in objects: o.plot()
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 class TestTrajectoryLoading(unittest.TestCase):
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12 'Tutorial example for NGSIM data'
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 def test_ex1(self):
1028
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 648
diff changeset
15 from trafficintelligence import storage
648
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16 objects = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'object')
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18 speed = objects[0].getVelocityAtInstant(10).norm2()
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 timeInterval = objects[0].getTimeInterval()
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20 speeds = [objects[0].getVelocityAtInstant(t).norm2() for t in range(timeInterval.first, timeInterval.last)]
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
21 speeds = [v.norm2() for v in objects[0].getVelocities()]
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 from matplotlib.pyplot import plot, close, axis
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
24 plot(range(timeInterval.first, timeInterval.last+1), speeds)
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
25
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
26 close('all')
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
27 objects[0].plot()
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
28 axis('equal')
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
29
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
30 features = storage.loadTrajectoriesFromSqlite('../samples/laurier.sqlite', 'feature')
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
31 objects[0].setFeatures(features)
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
32
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
33 for f in objects[0].features:
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
34 f.plot()
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
35 axis('equal')
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
36
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
37
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
38 if __name__ == '__main__':
da665302c88d added some tutorial code as tests to avoid tutorial to become out of sync with code changes
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
39 unittest.main()