# HG changeset patch # User Nicolas Saunier # Date 1718052259 14400 # Node ID 20a5e1292321db3c4503d5e36f8b04db2cea998e # Parent ca70a79688ae1aceb7c302c72d7dfc0e2a97b851 added smoothing functions and velocity generation to dltrack diff -r ca70a79688ae -r 20a5e1292321 scripts/dltrack.py --- a/scripts/dltrack.py Wed Jun 05 10:12:43 2024 -0400 +++ b/scripts/dltrack.py Mon Jun 10 16:44:19 2024 -0400 @@ -256,7 +256,8 @@ if smoothingHalfWidth is not None: # smoothing for num, obj in objects.items(): for f in obj.getFeatures(): - f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth) + f.smoothPositions(smoothingHalfWidth, replace = True)#f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth) + f.computeVelocities() storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object') diff -r ca70a79688ae -r 20a5e1292321 trafficintelligence/moving.py --- a/trafficintelligence/moving.py Wed Jun 05 10:12:43 2024 -0400 +++ b/trafficintelligence/moving.py Mon Jun 10 16:44:19 2024 -0400 @@ -1747,6 +1747,30 @@ else: return speeds + def computeVelocities(self, halfWidth = None): + '''compute velocities, smoothed if halfwidth is not None ''' + if halfWidth is None: + self.velocities = self.getPositions().differentiate(True) + else: + self.velocities = self.getPositions().differentiate().filterMovingWindow(halfWidth) + self.velocities.addPosition(self.velocities[-1]) + + def smoothPositions(self, halfWidth, replace = False): + 'Returns the smoothed positions (or replaces them)' + smoothed = self.getPositions().filterMovingWindow(halfWidth) + if replace: + self.positions = smoothed + else: + return smoothed + + def smoothVelocities(self, halfWidth, replace = False): + 'Returns the smoothed velocities (or replaces them)' + smoothed = self.getVelocities().filterMovingWindow(halfWidth) + if replace: + self.velocities = smoothed + else: + return smoothed + def getAccelerations(self, fromSpeeds = True, nInstantsIgnoredAtEnds = 0): '''Returns the scalar acceleration by differentiating the speeds (fromSpeeds = True) or by differentiating the velocity (vector) and taking the norm (frompSpeeds = False. In the second case, speed is always positive''' if fromSpeeds: