Skip to content

Commit 289aab5

Browse files
committed
Renamed Filter(s) to Owt(s) in python code
1 parent e85b4d8 commit 289aab5

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
lines changed

cuckoo_time_translator_python/python/cuckoo_time_translator/device_time_bags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def __init__(self, bagFile, topic, invalidate=False):
3434

3535
bag = rosbag.Bag(bagFile)
3636

37-
self.filtered_hw_times = TimestampSeries()
37+
self.translated_hw_times = TimestampSeries()
3838
self.receive_times = TimestampSeries()
3939
self.raw_hw_times = TimestampSeries()
4040
for topic, msg, t in bag.read_messages(topics=[topic]):
41-
self.filtered_hw_times.append(msg.header.stamp.to_sec())
41+
self.translated_hw_times.append(msg.header.stamp.to_sec())
4242
self.receive_times.append(msg.receive_time.to_sec())
4343
self.raw_hw_times.append(float(msg.event_stamp))
4444

cuckoo_time_translator_python/python/cuckoo_time_translator/timestamp_filters.py renamed to cuckoo_time_translator_python/python/cuckoo_time_translator/timestamp_owts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from cuckoo_time_translator.algorithms import LocalTime, RemoteTime
55

66

7-
class TimestampFilter:
7+
class TimestampOwt:
88

99
def __init__(self, owt, batch=False, switchTime=None):
1010
if switchTime:
@@ -49,13 +49,13 @@ def getConfigAndStateString(self):
4949
return self.owt.getNameAndConfigString() + ": " + self.owt.getStateString()
5050

5151

52-
class ConvexHullFilter (TimestampFilter):
52+
class ConvexHullOwt (TimestampOwt):
5353

5454
def __init__(self, *args, **kwargs):
55-
TimestampFilter.__init__(self, algorithms.ConvexHullOwt(), *args, **kwargs)
55+
TimestampOwt.__init__(self, algorithms.ConvexHullOwt(), *args, **kwargs)
5656

5757

58-
class KalmanFilter(TimestampFilter):
58+
class KalmanOwt(TimestampOwt):
5959

6060
def __init__(self, outlierThreshold=None, sigmaSkew=None, *args, **kwargs):
6161
k = algorithms.KalmanOwt()
@@ -72,15 +72,15 @@ def __init__(self, outlierThreshold=None, sigmaSkew=None, *args, **kwargs):
7272
self.sigmaSkew = c.sigmaSkew
7373

7474
k.setConfig(c)
75-
TimestampFilter.__init__(self, k, *args, **kwargs)
75+
TimestampOwt.__init__(self, k, *args, **kwargs)
7676

7777
self._addParamNames(extra_params)
7878

7979

80-
class LeastSquaresFilter(TimestampFilter):
80+
class LeastSquaresOwt(TimestampOwt):
8181

8282
def __init__(self):
83-
TimestampFilter.__init__(self, None, batch=True)
83+
TimestampOwt.__init__(self, None, batch=True)
8484

8585
def apply(self, hwTimes, receiveTimes):
8686
assert(len(hwTimes) > 2)
@@ -93,7 +93,7 @@ def apply(self, hwTimes, receiveTimes):
9393
return correctedhwTimes
9494

9595
def getConfigString(self, showDefaults=False):
96-
return "LeastSquaresFilter()"
96+
return "LeastSquaresOwt()"
9797

9898
def getConfigAndStateString(self):
9999
return self.getConfigString() + ": offset=%f, skew=%f" % (self.offset, self.skew)

cuckoo_time_translator_python/scripts/ctt_introspect.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44

55
from cuckoo_time_translator import *
66
from cuckoo_time_translator.device_time_bags import *
7-
from cuckoo_time_translator.timestamp_filters import *
7+
from cuckoo_time_translator.timestamp_owts import *
88
from cuckoo_time_translator.batch_algo import printDelayStat
99

1010
from cuckoo_time_translator.tools import *
1111

12-
FiltersDefault = 'ConvexHullFilter(switchTime = 10), KalmanFilter(), ConvexHullFilter(switchTime = 100)'
12+
OwtsDefault = 'ConvexHullOwt(switchTime = 10), KalmanOwt(), ConvexHullOwt(switchTime = 100)'
1313

1414
if __name__ == '__main__':
1515
import argparse
16-
16+
1717
parser = argparse.ArgumentParser(description='Analyze DeviceTimestamp message streams.')
18-
parser.add_argument('bag', nargs = 1, help='The path to the bag file containing the DeviceTimestamp messages')
18+
parser.add_argument('bag', nargs=1, help='The path to the bag file containing the DeviceTimestamp messages')
1919
parser.add_argument('-t,--topic', dest='topic', nargs='+', help='The path to the bag file containing the DeviceTimestamp messages')
2020
parser.add_argument('-v,--verbose', dest='verbose', action='count', help='Increase verbosity (counted)')
2121
parser.add_argument('-o,--output', dest='output', help='Output file to plot to (PDF)')
2222
parser.add_argument('-b,--baseLine', dest='baseLine', default="LeastSquares", help='Use this batch-method as base line; LeastSquare, ConvexHull, Index')
23-
parser.add_argument('-f,--filters', dest='filters', default=FiltersDefault, help='Additional filters to compare with. Default: ' + FiltersDefault)
23+
parser.add_argument('-f,--owts', dest='owts', default=OwtsDefault, help='Additional owts to compare with. Default: ' + OwtsDefault)
2424
parser.add_argument('--dontPlotReceiveTimes', action='store_true', help='don\'t plot receive timestamps')
25-
parser.add_argument('--dontPlotPreFiltered', action='store_true', help='don\'t plot pre-filtered timestamps')
25+
parser.add_argument('--dontPlotPreTranslated', action='store_true', help='don\'t plot pre-translated timestamps, i.e., translated in the device driver')
2626
parser.add_argument('--invalidate', action='store_true', help='invalidate any possibly existing cache')
2727
parser.add_argument('--showDefaults', action='store_true', help='Show all parameters in the legend even if they are at their default value')
2828
parser.add_argument('--force', action='store_true', help='Force overwriting')
@@ -36,66 +36,65 @@
3636
sys.exit(-1)
3737

3838
realPathBagFile = os.path.realpath(bagFile)
39-
39+
4040
if args.topic:
4141
topics = args.topic
4242
else:
4343
topics = guessTopics(bagFile)
4444

45-
4645
if not topics:
4746
error("Could not find any topic ending with " + DefaultTopic + "!")
4847
sys.exit(-1)
4948

5049
verbose("Going to analyze these topics: " + str(topics))
51-
52-
hwFilters = eval("[%s]" % args.filters)
53-
50+
51+
hwOwts = eval("[%s]" % args.owts)
52+
5453
for topic in topics:
5554
info("Analyzing topic :" + topic)
5655

57-
ds = DeviceTimeStream(realPathBagFile, topic, invalidate = args.invalidate)
58-
59-
baselineFilter = None
56+
ds = DeviceTimeStream(realPathBagFile, topic, invalidate=args.invalidate)
57+
58+
baselineOwt = None
6059
if args.baseLine == "Index":
6160
base_times = np.linspace(ds.receive_times[0], ds.receive_times[-1], len(ds.receive_times))
6261
elif args.baseLine == "LeastSquares":
63-
baselineFilter = LeastSquaresFilter()
62+
baselineOwt = LeastSquaresOwt()
6463
elif args.baseLine == "ConvexHull":
65-
baselineFilter = ConvexHullFilter(True)
64+
baselineOwt = ConvexHullOwt(True)
6665
else:
6766
error("Unknown base line method : " + str(args.baseLine))
6867
sys.exit(1)
6968

70-
if baselineFilter:
71-
base_times = np.array(baselineFilter.apply(ds.raw_hw_times, ds.receive_times))
72-
info("Baseline filter after filtering: " + baselineFilter.getConfigAndStateString())
73-
69+
if baselineOwt:
70+
base_times = np.array(baselineOwt.apply(ds.raw_hw_times, ds.receive_times))
71+
info("Baseline owt after translation: " + baselineOwt.getConfigAndStateString())
72+
7473
delaysToPlot = []
7574
labels = []
7675
colors = []
77-
76+
7877
def addToPlot(times, label, color):
7978
delaysToPlot.append(times - base_times)
8079
labels.append(label)
8180
colors.append(color)
8281

8382
if not args.dontPlotReceiveTimes:
8483
addToPlot(ds.receive_times, "receive times", "r")
85-
if not args.dontPlotPreFiltered:
86-
addToPlot(ds.filtered_hw_times, "pre-filtered", "g")
87-
88-
filterColors = ['m', 'grey', 'cyan', 'k', 'orange']
89-
for i, filter in enumerate(hwFilters):
90-
addToPlot(filter.apply(ds.raw_hw_times, ds.receive_times), filter.getConfigString(args.showDefaults), filterColors[i])
91-
info("After filtering: " + filter.getConfigAndStateString())
92-
84+
if not args.dontPlotPreTranslated:
85+
addToPlot(ds.translated_hw_times, "pre-translated", "g")
86+
87+
owtColors = ['m', 'grey', 'cyan', 'k', 'orange']
88+
for i, owt in enumerate(hwOwts):
89+
addToPlot(owt.apply(ds.raw_hw_times, ds.receive_times), owt.getConfigString(args.showDefaults), owtColors[i])
90+
info("After translating: " + owt.getConfigAndStateString())
91+
9392
print("Deviation from base line:")
9493
for d, lab in zip(delaysToPlot, labels):
9594
printDelayStat(d, lab)
96-
95+
9796
from cuckoo_time_translator.plotting import plotMultiDelays, show
98-
plotMultiDelays(base_times, delaysToPlot, "time [sec]", labels, markersize = 4, colors = colors, fileName = args.output, overwrite = args.force, show = False)
97+
plotMultiDelays(base_times, delaysToPlot, "time [sec]", labels, markersize=4, colors=colors, fileName=args.output, overwrite=args.force, show=False)
9998

10099
if not args.output:
101100
from cuckoo_time_translator.plotting import show

cuckoo_time_translator_python/test/Test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def testConversions(self):
1313
l = LocalTime(3)
1414
self.assertEqual(3, float(l))
1515

16-
def _testFilter(self, c):
16+
def _testOwt(self, c):
1717
self.assertFalse(c.isReady())
1818
l = c.updateAndTranslateToLocalTimestamp(RemoteTime(5), LocalTime(4))
1919
self.assertEqual(LocalTime, type(l))
@@ -25,10 +25,10 @@ def _testFilter(self, c):
2525
self.assertEqual(LocalTime(5), c.translateToLocalTimestamp(RemoteTime(6)))
2626

2727
def testConvexHull(self):
28-
self._testFilter(ConvexHullOwt())
28+
self._testOwt(ConvexHullOwt())
2929

3030
def testKalman(self):
31-
self._testFilter(KalmanOwt())
31+
self._testOwt(KalmanOwt())
3232

3333

3434
if __name__ == '__main__':

0 commit comments

Comments
 (0)