comparison trafficintelligence/processing.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/processing.py@933670761a57
children c6cf75a2ed08
comparison
equal deleted inserted replaced
1027:6129296848d3 1028:cc5cb04b04b0
1 #! /usr/bin/env python
2 '''Algorithms to process trajectories and moving objects'''
3
4 import moving
5
6 import numpy as np
7
8
9 def extractSpeeds(objects, zone):
10 speeds = {}
11 objectsNotInZone = []
12 import matplotlib.nxutils as nx
13 for o in objects:
14 inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T)
15 if inPolygon.any():
16 objspeeds = [o.getVelocityAt(i).norm2() for i in range(int(o.length()-1)) if inPolygon[i]]
17 speeds[o.num] = np.mean(objspeeds) # km/h
18 else:
19 objectsNotInZone.append(o)
20 return speeds, objectsNotInZone