Mercurial > hg > nsaunier > traffic-intelligence
diff trafficintelligence/moving.py @ 1187:25c85a7ecf09
merged
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Tue, 21 Jun 2022 17:06:21 -0400 |
| parents | d381a06e2d9e |
| children | d24d57e4de24 |
line wrap: on
line diff
--- a/trafficintelligence/moving.py Tue Jun 21 17:06:06 2022 -0400 +++ b/trafficintelligence/moving.py Tue Jun 21 17:06:21 2022 -0400 @@ -860,7 +860,7 @@ cval : Value to fill past the edges of the input if mode is constant. Default is 0.0. https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter''' - if removeBothEnds >=1: + if nInstantsIgnoredAtEnds >=1: pos = [self.positions[0][nInstantsIgnoredAtEnds:-nInstantsIgnoredAtEnds], self.positions[1][nInstantsIgnoredAtEnds:-nInstantsIgnoredAtEnds]] else: @@ -1326,8 +1326,8 @@ else: newNum = num commonTimeInterval = obj1.commonTimeInterval(obj2) - emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant())) - if commonTimeInterval.empty() and emptyInterval.length() >= 3: + if commonTimeInterval.empty(): # and emptyInterval.length() >= 2: not needed 2 to include situations successive positions, but issues with missing last velocity and reloading + emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant())) if newFeatureNum is None: print('Not merging objects {} and {}, missing new feature number'.format(obj1.getNum(),obj2.getNum())) return None, None @@ -1564,12 +1564,17 @@ else: return speeds - def getAccelerations(self, window_length, polyorder, delta=1.0, axis=-1, mode='interp', cval=0.0, speeds = None, nInstantsIgnoredAtEnds = 0): + def getAccelerations(self, window_length, polyorder, delta=1.0, axis=-1, mode='interp', cval=0.0, nInstantsIgnoredAtEnds = 0): '''Returns the 1-D acceleration from the 1-D speeds Caution about previously filtered data''' - if speeds is None: - speeds = self.getSpeeds(nInstantsIgnoredAtEnds) - return savgol_filter(speeds, window_length, polyorder, 1, delta, axis, mode, cval) + speeds = self.getSpeeds(nInstantsIgnoredAtEnds) + if window_length > len(speeds): + wlength = min(window_length, len(speeds)) + if wlength % 2 == 0: + wlength -=1 + else: + wlength = window_length + return savgol_filter(speeds, wlength, min(wlength-1, polyorder), 1, delta, axis, mode, cval) def getSpeedIndicator(self): from indicators import SeverityIndicator
