# HG changeset patch # User Nicolas Saunier # Date 1557173788 14400 # Node ID 6bbcd94337326ab894a43c94a7648f3198d1eeda # Parent 6e8ab471ebd437838e3a607ad8afd84bc15f34ec formatting and addition of one method to CurvilinearTrajectory diff -r 6e8ab471ebd4 -r 6bbcd9433732 trafficintelligence/moving.py --- a/trafficintelligence/moving.py Tue Apr 16 11:58:23 2019 -0400 +++ b/trafficintelligence/moving.py Mon May 06 16:16:28 2019 -0400 @@ -273,7 +273,7 @@ def angle(self): return atan2(self.y, self.x) - + def norm2Squared(self): '''2-norm distance (Euclidean distance)''' return self.x**2+self.y**2 @@ -284,7 +284,7 @@ def norm1(self): return abs(self.x)+abs(self.y) - + def normMax(self): return max(abs(self.x),abs(self.y)) @@ -346,7 +346,7 @@ @staticmethod def parallel(p1, p2): return Point.cross(p1, p2) == 0. - + @staticmethod def cosine(p1, p2): return Point.dot(p1,p2)/(p1.norm2()*p2.norm2()) @@ -465,8 +465,9 @@ except ZeroDivisionError: print('Error: Division by zero in ppldb2p. Please report this error with the full traceback:') print('qx={0}, qy={1}, p0x={2}, p0y={3}, p1x={4}, p1y={5}...'.format(qx, qy, p0x, p0y, p1x, p1y)) - import pdb; pdb.set_trace() - return Point(X,Y) + import pdb; + pdb.set_trace() + return Point(X, Y) def getSYfromXY(p, alignments, goodEnoughAlignmentDistance = 0.5): ''' Snap a point p to its nearest subsegment of it's nearest alignment (from the list alignments). @@ -541,14 +542,14 @@ print('Curvilinear point {} is past the end of the alignement'.format((s, y, alignmentNum))) return None - + class NormAngle(object): '''Alternate encoding of a point, by its norm and orientation''' def __init__(self, norm, angle): self.norm = norm self.angle = angle - + @staticmethod def fromPoint(p): norm = p.norm2() @@ -598,7 +599,7 @@ def plot(self, options = '', **kwargs): plot([self.position.x, self.position.x+self.velocity.x], [self.position.y, self.position.y+self.velocity.y], options, **kwargs) self.position.plot(options+'x', **kwargs) - + @staticmethod def similar(f1, f2, maxDistance2, maxDeltavelocity2): return (f1.position-f2.position).norm2Squared() pedestrians fast: motorized -> cars - + aggregationFunc can be any function that can be applied to a vector of speeds, including percentile: aggregationFunc = lambda x: percentile(x, percentileFactor) # where percentileFactor is 85 for 85th percentile''' speeds = self.getSpeeds(nInstantsIgnoredAtEnds) @@ -1970,7 +1975,7 @@ return self.filename == p2.filename and self.num == p2.num and self.trajectoryType == p2.trajectoryType def __hash__(self): return hash((self.filename, self.num, self.trajectoryType)) - + ################## # Annotations ################## @@ -2100,7 +2105,7 @@ for a,o in matches.items(): gtMatches[a.getNum()][t] = o.getNum() toMatches[o.getNum()][t] = a.getNum() - + # compute metrics elements ct += len(matches) mt += nGTs-len(matches) @@ -2123,7 +2128,7 @@ print('{} {}'.format(type(mm), mm.getNum())) # some object mismatches may appear twice mme += len(set(mismatches)) - + if ct > 0: motp = dist/ct else: diff -r 6e8ab471ebd4 -r 6bbcd9433732 trafficintelligence/tests/moving.txt --- a/trafficintelligence/tests/moving.txt Tue Apr 16 11:58:23 2019 -0400 +++ b/trafficintelligence/tests/moving.txt Mon May 06 16:16:28 2019 -0400 @@ -232,6 +232,11 @@ >>> o.interpolateCurvilinearPositions(10.7) # doctest:+ELLIPSIS [14.09999..., 0.69999..., 'a'] +>>> t1 = CurvilinearTrajectory.generate(3, 1., 10, 'b') +>>> t1.duplicateLastPosition() +>>> t1[-1] == t1[-2] +True + >>> a = Trajectory.generate(Point(0.,0.), Point(10.,0.), 4) >>> t = Trajectory.generate(Point(0.1,-1.), Point(1.,0.), 22) >>> prepareAlignments([a])