Mercurial Hosting > traffic-intelligence
changeset 1270:20a5e1292321
added smoothing functions and velocity generation to dltrack
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 10 Jun 2024 16:44:19 -0400 |
parents | ca70a79688ae |
children | b2f90cada58f |
files | scripts/dltrack.py trafficintelligence/moving.py |
diffstat | 2 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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')
--- 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: