|
4 | 4 |
|
5 | 5 | from cuckoo_time_translator import * |
6 | 6 | from cuckoo_time_translator.device_time_bags import * |
7 | | -from cuckoo_time_translator.timestamp_filters import * |
| 7 | +from cuckoo_time_translator.timestamp_owts import * |
8 | 8 | from cuckoo_time_translator.batch_algo import printDelayStat |
9 | 9 |
|
10 | 10 | from cuckoo_time_translator.tools import * |
11 | 11 |
|
12 | | -FiltersDefault = 'ConvexHullFilter(switchTime = 10), KalmanFilter(), ConvexHullFilter(switchTime = 100)' |
| 12 | +OwtsDefault = 'ConvexHullOwt(switchTime = 10), KalmanOwt(), ConvexHullOwt(switchTime = 100)' |
13 | 13 |
|
14 | 14 | if __name__ == '__main__': |
15 | 15 | import argparse |
16 | | - |
| 16 | + |
17 | 17 | 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') |
19 | 19 | parser.add_argument('-t,--topic', dest='topic', nargs='+', help='The path to the bag file containing the DeviceTimestamp messages') |
20 | 20 | parser.add_argument('-v,--verbose', dest='verbose', action='count', help='Increase verbosity (counted)') |
21 | 21 | parser.add_argument('-o,--output', dest='output', help='Output file to plot to (PDF)') |
22 | 22 | 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) |
24 | 24 | 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') |
26 | 26 | parser.add_argument('--invalidate', action='store_true', help='invalidate any possibly existing cache') |
27 | 27 | parser.add_argument('--showDefaults', action='store_true', help='Show all parameters in the legend even if they are at their default value') |
28 | 28 | parser.add_argument('--force', action='store_true', help='Force overwriting') |
|
36 | 36 | sys.exit(-1) |
37 | 37 |
|
38 | 38 | realPathBagFile = os.path.realpath(bagFile) |
39 | | - |
| 39 | + |
40 | 40 | if args.topic: |
41 | 41 | topics = args.topic |
42 | 42 | else: |
43 | 43 | topics = guessTopics(bagFile) |
44 | 44 |
|
45 | | - |
46 | 45 | if not topics: |
47 | 46 | error("Could not find any topic ending with " + DefaultTopic + "!") |
48 | 47 | sys.exit(-1) |
49 | 48 |
|
50 | 49 | verbose("Going to analyze these topics: " + str(topics)) |
51 | | - |
52 | | - hwFilters = eval("[%s]" % args.filters) |
53 | | - |
| 50 | + |
| 51 | + hwOwts = eval("[%s]" % args.owts) |
| 52 | + |
54 | 53 | for topic in topics: |
55 | 54 | info("Analyzing topic :" + topic) |
56 | 55 |
|
57 | | - ds = DeviceTimeStream(realPathBagFile, topic, invalidate = args.invalidate) |
58 | | - |
59 | | - baselineFilter = None |
| 56 | + ds = DeviceTimeStream(realPathBagFile, topic, invalidate=args.invalidate) |
| 57 | + |
| 58 | + baselineOwt = None |
60 | 59 | if args.baseLine == "Index": |
61 | 60 | base_times = np.linspace(ds.receive_times[0], ds.receive_times[-1], len(ds.receive_times)) |
62 | 61 | elif args.baseLine == "LeastSquares": |
63 | | - baselineFilter = LeastSquaresFilter() |
| 62 | + baselineOwt = LeastSquaresOwt() |
64 | 63 | elif args.baseLine == "ConvexHull": |
65 | | - baselineFilter = ConvexHullFilter(True) |
| 64 | + baselineOwt = ConvexHullOwt(True) |
66 | 65 | else: |
67 | 66 | error("Unknown base line method : " + str(args.baseLine)) |
68 | 67 | sys.exit(1) |
69 | 68 |
|
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 | + |
74 | 73 | delaysToPlot = [] |
75 | 74 | labels = [] |
76 | 75 | colors = [] |
77 | | - |
| 76 | + |
78 | 77 | def addToPlot(times, label, color): |
79 | 78 | delaysToPlot.append(times - base_times) |
80 | 79 | labels.append(label) |
81 | 80 | colors.append(color) |
82 | 81 |
|
83 | 82 | if not args.dontPlotReceiveTimes: |
84 | 83 | 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 | + |
93 | 92 | print("Deviation from base line:") |
94 | 93 | for d, lab in zip(delaysToPlot, labels): |
95 | 94 | printDelayStat(d, lab) |
96 | | - |
| 95 | + |
97 | 96 | 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) |
99 | 98 |
|
100 | 99 | if not args.output: |
101 | 100 | from cuckoo_time_translator.plotting import show |
|
0 commit comments