comparison python/processing.py @ 246:583a2c4622f9

created new module for algorithms with function to extract speeds
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 17 Jul 2012 16:28:24 -0400
parents
children 15e244d2a1b5
comparison
equal deleted inserted replaced
245:bd8ab323c198 246:583a2c4622f9
1 #! /usr/bin/env python
2 '''Algorithms to process trajectories and moving objects'''
3
4 __metaclass__ = type
5
6 import numpy as np
7
8 import moving
9
10 def extractSpeeds(objects, zone):
11 speeds = {}
12 objectsNotInZone = []
13 import matplotlib.nxutils as nx
14 for o in objects:
15 inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T)
16 if inPolygon.any():
17 objspeeds = [o.getVelocityAt(i).norm2() for i in xrange(int(o.length()-1)) if inPolygon[i]]
18 speeds[o.num] = np.mean(objspeeds) # km/h
19 else:
20 objectsNotInZone.append(o)
21 return speeds.values(), speeds, objectsNotInZone