annotate python/processing.py @ 998:933670761a57

updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sun, 27 May 2018 23:22:48 -0400
parents 15e244d2a1b5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
246
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 #! /usr/bin/env python
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2 '''Algorithms to process trajectories and moving objects'''
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3
665
15e244d2a1b5 corrected bug with circular import for VideoFilenameAddable, moved to base module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 246
diff changeset
4 import moving
246
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 import numpy as np
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 def extractSpeeds(objects, zone):
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 speeds = {}
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 objectsNotInZone = []
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12 import matplotlib.nxutils as nx
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 for o in objects:
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14 inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T)
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15 if inPolygon.any():
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 665
diff changeset
16 objspeeds = [o.getVelocityAt(i).norm2() for i in range(int(o.length()-1)) if inPolygon[i]]
246
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17 speeds[o.num] = np.mean(objspeeds) # km/h
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18 else:
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 objectsNotInZone.append(o)
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 665
diff changeset
20 return speeds, objectsNotInZone