Mercurial Hosting > traffic-intelligence
changeset 1187:25c85a7ecf09
merged
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 21 Jun 2022 17:06:21 -0400 |
parents | 7117a31555c1 (current diff) d381a06e2d9e (diff) |
children | 82fc21f6dfdf |
files | |
diffstat | 4 files changed, 18 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/trafficintelligence/events.py Tue Jun 21 17:06:06 2022 -0400 +++ b/trafficintelligence/events.py Tue Jun 21 17:06:21 2022 -0400 @@ -92,7 +92,7 @@ 's', 's'] - timeIndicators = ['Time to Collision', 'predicted Post Encroachment Time'] + mostSevereIsMinIndicators = ['Distance', 'Time to Collision', 'predicted Post Encroachment Time'] def __init__(self, num = None, timeInterval = None, roaduserNum1 = None, roaduserNum2 = None, roadUser1 = None, roadUser2 = None): moving.STObject.__init__(self, num, timeInterval)
--- 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
--- a/trafficintelligence/storage.py Tue Jun 21 17:06:06 2022 -0400 +++ b/trafficintelligence/storage.py Tue Jun 21 17:06:21 2022 -0400 @@ -326,6 +326,8 @@ except sqlite3.OperationalError as error: printDBError(error) + else: + print('Impossible to load from non-existing file '+filename) return objects def loadObjectFeatureFrameNumbers(filename, objectNumbers = None): @@ -540,7 +542,7 @@ indicatorTypeNum = row[5] indicatorName = events.Interaction.indicatorNames[indicatorTypeNum] indicatorValues = {row[6]:row[7]} - interactions[-1].indicators[indicatorName] = indicators.SeverityIndicator(indicatorName, indicatorValues, mostSevereIsMax = not indicatorName in events.Interaction.timeIndicators) + interactions[-1].indicators[indicatorName] = indicators.SeverityIndicator(indicatorName, indicatorValues, mostSevereIsMax = not indicatorName in events.Interaction.mostSevereIsMinIndicators) else: indicatorValues[row[6]] = row[7] interactions[-1].indicators[indicatorName].timeInterval.last = row[6]
--- a/trafficintelligence/tests/moving.txt Tue Jun 21 17:06:06 2022 -0400 +++ b/trafficintelligence/tests/moving.txt Tue Jun 21 17:06:21 2022 -0400 @@ -335,9 +335,9 @@ >>> f12.getVelocities().length() 5 ->>> o14, f14 = MovingObject.concatenate(o1, o4, 16) +>>> o14, f14 = MovingObject.concatenate(o1, o4, 16, 16) >>> len(o14.getFeatures()) -2 +3 >>> o14.getPositionAtInstant(10) == o1.getPositionAtInstant(10) True >>> o14.getPositionAtInstant(11) == o4.getPositionAtInstant(11)