Mercurial > hg > nsaunier > traffic-intelligence
annotate python/tests/tutorials.py @ 893:ff92801e5c54
updated hog to scikit-image 0.13 (needed to add a block_norm attribute in classifier.cfg)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 30 May 2017 16:10:18 -0400 |
| parents | da665302c88d |
| children |
| 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): |
|
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
|
7 import storage |
|
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): |
|
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
|
15 import storage |
|
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() |
