changeset 762:d6f0e0cab07d dev

added functionalities for Trajectory
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 28 Nov 2015 16:54:03 -0500
parents 15ddc8715236
children 277e9cdcedce
files python/moving.py
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Sat Nov 28 13:29:54 2015 -0500
+++ b/python/moving.py	Sat Nov 28 16:54:03 2015 -0500
@@ -820,6 +820,11 @@
         else:
             print('Index {} beyond trajectory length {}'.format(i, self.length()))
 
+    def getMaxDistance(self, metric):
+        'Returns the maximum distance between points in the trajectory' 
+        positions = self.getPositions().asArray().T
+        return cdist(positions, positions, metric = metric).max()
+
     def similarOrientation(self, refDirection, cosineThreshold, minProportion = 0.5):
         '''Indicates whether the minProportion (<=1.) (eg half) of the trajectory elements (vectors for velocity) 
         have a cosine with refDirection is smaller than cosineThreshold'''
@@ -831,7 +836,11 @@
         return count >= lengthThreshold
 
     def wiggliness(self):
-        return self.getCumulativeDistance(self.length()-1)/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1)))
+        straightDistance = Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))
+        if straightDistance > 0:
+            return self.getCumulativeDistance(self.length()-1)/float(straightDistance)
+        else:
+            return None
 
     def getIntersections(self, p1, p2):
         '''Returns a list of the indices at which the trajectory 
@@ -884,7 +893,12 @@
                                self.positions[1][inter.first:inter.last+1]])
         else:
             return None
-    
+
+    def subSample(self, step):
+        'Returns the positions very step'
+        return Trajectory([self.positions[0][::step],
+                           self.positions[1][::step]])
+
     if shapelyAvailable:
         def getTrajectoryInPolygon(self, polygon):
             '''Returns the trajectory built with the set of points inside the (shapely) polygon'''