annotate trafficintelligence/processing.py @ 1029:c6cf75a2ed08

reorganization of imports
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 18 Jun 2018 22:50:59 -0400
parents cc5cb04b04b0
children 75a6ad604cc5
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
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4 import numpy as np
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5
1029
c6cf75a2ed08 reorganization of imports
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
6 from trafficintelligence import moving
246
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 def extractSpeeds(objects, zone):
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 speeds = {}
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 objectsNotInZone = []
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 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
12 for o in objects:
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 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
14 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
15 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
16 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
17 else:
583a2c4622f9 created new module for algorithms with function to extract speeds
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18 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
19 return speeds, objectsNotInZone