Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/moving.py @ 1183:38f0d0ceac3f
issue with window length for savgol
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 01 Apr 2022 15:39:04 -0400 |
parents | 0e5d37b0b9ff |
children | f9cf827a73a6 |
comparison
equal
deleted
inserted
replaced
1182:0e5d37b0b9ff | 1183:38f0d0ceac3f |
---|---|
1562 n = min(nInstantsIgnoredAtEnds, int(floor(self.length()/2.))) | 1562 n = min(nInstantsIgnoredAtEnds, int(floor(self.length()/2.))) |
1563 return speeds[n:-n] | 1563 return speeds[n:-n] |
1564 else: | 1564 else: |
1565 return speeds | 1565 return speeds |
1566 | 1566 |
1567 def getAccelerations(self, window_length, polyorder, delta=1.0, axis=-1, mode='interp', cval=0.0, speeds = None, nInstantsIgnoredAtEnds = 0): | 1567 def getAccelerations(self, window_length, polyorder, delta=1.0, axis=-1, mode='interp', cval=0.0, nInstantsIgnoredAtEnds = 0): |
1568 '''Returns the 1-D acceleration from the 1-D speeds | 1568 '''Returns the 1-D acceleration from the 1-D speeds |
1569 Caution about previously filtered data''' | 1569 Caution about previously filtered data''' |
1570 if speeds is None: | 1570 speeds = self.getSpeeds(nInstantsIgnoredAtEnds) |
1571 speeds = self.getSpeeds(nInstantsIgnoredAtEnds) | 1571 if window_length > len(speeds): |
1572 return savgol_filter(speeds, min(window_length, len(speeds)), polyorder, 1, delta, axis, mode, cval) | 1572 wlength = min(window_length, len(speeds)) |
1573 if wlength % 2 == 0: | |
1574 wlength -=1 | |
1575 else: | |
1576 wlength = window_length | |
1577 return savgol_filter(speeds, wlength, polyorder, 1, delta, axis, mode, cval) | |
1573 | 1578 |
1574 def getSpeedIndicator(self): | 1579 def getSpeedIndicator(self): |
1575 from indicators import SeverityIndicator | 1580 from indicators import SeverityIndicator |
1576 return SeverityIndicator('Speed', {t:self.getVelocityAtInstant(t).norm2() for t in self.getTimeInterval()}) | 1581 return SeverityIndicator('Speed', {t:self.getVelocityAtInstant(t).norm2() for t in self.getTimeInterval()}) |
1577 | 1582 |