comparison 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
comparison
equal deleted inserted replaced
1186:7117a31555c1 1187:25c85a7ecf09
858 axis : The axis of the array x along which the filter is to be applied. Default is -1. 858 axis : The axis of the array x along which the filter is to be applied. Default is -1.
859 mode : Must be mirror, constant, nearest, wrap or interp. This determines the type of extension to use for the padded signal to which the filter is applied. When mode is constant, the padding value is given by cval. See the Notes for more details on mirror, constant, wrap, and nearest. When the interp mode is selected (the default), no extension is used. Instead, a degree polyorder polynomial is fit to the last window_length values of the edges, and this polynomial is used to evaluate the last window_length // 2 output values. 859 mode : Must be mirror, constant, nearest, wrap or interp. This determines the type of extension to use for the padded signal to which the filter is applied. When mode is constant, the padding value is given by cval. See the Notes for more details on mirror, constant, wrap, and nearest. When the interp mode is selected (the default), no extension is used. Instead, a degree polyorder polynomial is fit to the last window_length values of the edges, and this polynomial is used to evaluate the last window_length // 2 output values.
860 cval : Value to fill past the edges of the input if mode is constant. Default is 0.0. 860 cval : Value to fill past the edges of the input if mode is constant. Default is 0.0.
861 861
862 https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter''' 862 https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.savgol_filter.html#scipy.signal.savgol_filter'''
863 if removeBothEnds >=1: 863 if nInstantsIgnoredAtEnds >=1:
864 pos = [self.positions[0][nInstantsIgnoredAtEnds:-nInstantsIgnoredAtEnds], 864 pos = [self.positions[0][nInstantsIgnoredAtEnds:-nInstantsIgnoredAtEnds],
865 self.positions[1][nInstantsIgnoredAtEnds:-nInstantsIgnoredAtEnds]] 865 self.positions[1][nInstantsIgnoredAtEnds:-nInstantsIgnoredAtEnds]]
866 else: 866 else:
867 pos = self.positions 867 pos = self.positions
868 filtered = savgol_filter(pos, window_length, polyorder, deriv, delta, axis, mode, cval) 868 filtered = savgol_filter(pos, window_length, polyorder, deriv, delta, axis, mode, cval)
1324 if num is None: 1324 if num is None:
1325 newNum = obj1.getNum() 1325 newNum = obj1.getNum()
1326 else: 1326 else:
1327 newNum = num 1327 newNum = num
1328 commonTimeInterval = obj1.commonTimeInterval(obj2) 1328 commonTimeInterval = obj1.commonTimeInterval(obj2)
1329 emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant())) 1329 if commonTimeInterval.empty(): # and emptyInterval.length() >= 2: not needed 2 to include situations successive positions, but issues with missing last velocity and reloading
1330 if commonTimeInterval.empty() and emptyInterval.length() >= 3: 1330 emptyInterval = TimeInterval(min(obj1.getLastInstant(),obj2.getLastInstant()), max(obj1.getFirstInstant(),obj2.getFirstInstant()))
1331 if newFeatureNum is None: 1331 if newFeatureNum is None:
1332 print('Not merging objects {} and {}, missing new feature number'.format(obj1.getNum(),obj2.getNum())) 1332 print('Not merging objects {} and {}, missing new feature number'.format(obj1.getNum(),obj2.getNum()))
1333 return None, None 1333 return None, None
1334 else: 1334 else:
1335 if obj1.existsAtInstant(emptyInterval.last): 1335 if obj1.existsAtInstant(emptyInterval.last):
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, window_length, 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, min(wlength-1, 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