Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/moving.py @ 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 | ef68d4ba7dae |
children |
comparison
equal
deleted
inserted
replaced
1269:ca70a79688ae | 1270:20a5e1292321 |
---|---|
1745 n = min(nInstantsIgnoredAtEnds, int(floor(self.length()/2.))) | 1745 n = min(nInstantsIgnoredAtEnds, int(floor(self.length()/2.))) |
1746 return speeds[n:-n] | 1746 return speeds[n:-n] |
1747 else: | 1747 else: |
1748 return speeds | 1748 return speeds |
1749 | 1749 |
1750 def computeVelocities(self, halfWidth = None): | |
1751 '''compute velocities, smoothed if halfwidth is not None ''' | |
1752 if halfWidth is None: | |
1753 self.velocities = self.getPositions().differentiate(True) | |
1754 else: | |
1755 self.velocities = self.getPositions().differentiate().filterMovingWindow(halfWidth) | |
1756 self.velocities.addPosition(self.velocities[-1]) | |
1757 | |
1758 def smoothPositions(self, halfWidth, replace = False): | |
1759 'Returns the smoothed positions (or replaces them)' | |
1760 smoothed = self.getPositions().filterMovingWindow(halfWidth) | |
1761 if replace: | |
1762 self.positions = smoothed | |
1763 else: | |
1764 return smoothed | |
1765 | |
1766 def smoothVelocities(self, halfWidth, replace = False): | |
1767 'Returns the smoothed velocities (or replaces them)' | |
1768 smoothed = self.getVelocities().filterMovingWindow(halfWidth) | |
1769 if replace: | |
1770 self.velocities = smoothed | |
1771 else: | |
1772 return smoothed | |
1773 | |
1750 def getAccelerations(self, fromSpeeds = True, nInstantsIgnoredAtEnds = 0): | 1774 def getAccelerations(self, fromSpeeds = True, nInstantsIgnoredAtEnds = 0): |
1751 '''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''' | 1775 '''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''' |
1752 if fromSpeeds: | 1776 if fromSpeeds: |
1753 speeds = array(self.getSpeeds()) | 1777 speeds = array(self.getSpeeds()) |
1754 accelerations = speeds[1:]-speeds[:-1] | 1778 accelerations = speeds[1:]-speeds[:-1] |