Mercurial Hosting > traffic-intelligence
changeset 1197:0475b4cd0cfb
adding simple direct acceleration calculation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 31 Jul 2022 16:49:51 +0200 |
parents | d5566af60a69 |
children | fa07a78b29f6 |
files | trafficintelligence/moving.py |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Thu Jul 14 11:29:13 2022 +0200 +++ b/trafficintelligence/moving.py Sun Jul 31 16:49:51 2022 +0200 @@ -1561,6 +1561,7 @@ return None def getSpeeds(self, nInstantsIgnoredAtEnds = 0): + '''Returns the scalar speed''' speeds = self.getVelocities().norm() if nInstantsIgnoredAtEnds > 0: n = min(nInstantsIgnoredAtEnds, int(floor(self.length()/2.))) @@ -1568,6 +1569,19 @@ else: return speeds + 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: + speeds = array(self.getSpeeds()) + accelerations = speeds[1:]-speeds[:-1] + else: + accelerations = self.getVelocities().differentiate().norm() + if nInstantsIgnoredAtEnds > 0: + n = min(nInstantsIgnoredAtEnds, int(floor(len(accelerations)/2.))) + return accelerations[n:-n] + else: + return accelerations + def getAccelerationsSG(self, window_length, polyorder, delta=1.0, axis=-1, mode='nearest', cval=0.0, nInstantsIgnoredAtEnds = 0): '''Returns the 1-D acceleration from the 1-D speeds Caution about previously filtered data'''