examples/a121/algo/distance/post_process_distance_result.py#
1# Copyright (c) Acconeer AB, 2023
2# All rights reserved
3
4
5import h5py
6import matplotlib.pyplot as plt
7
8from acconeer.exptool.a121 import H5Record, _ReplayingClient, _StopReplay
9from acconeer.exptool.a121.algo.distance import Detector, DetectorConfig, DetectorContext
10
11
12FILEPATH = ""
13
14
15def main():
16 with h5py.File(FILEPATH, "r") as file:
17 algo_group = file["algo"]
18
19 sensor_ids = algo_group["sensor_ids"][()].tolist()
20 detector_config = DetectorConfig.from_json(algo_group["detector_config"][()])
21 context_group = algo_group["context"]
22 context = DetectorContext.from_h5(context_group)
23
24 record = H5Record(file)
25 client = _ReplayingClient(record, realtime_replay=False)
26
27 detector = Detector(
28 client=client,
29 sensor_ids=sensor_ids,
30 detector_config=detector_config,
31 context=context,
32 )
33
34 detector.start()
35
36 fig, axs = plt.subplots(ncols=2, sharex=True)
37 fig.set_figwidth(15)
38
39 while True:
40 try:
41 result = detector.get_next()
42
43 for processor_result in result[sensor_ids[0]].processor_results:
44 axs[0].plot(
45 processor_result.extra_result.distances_m,
46 processor_result.extra_result.abs_sweep,
47 "b",
48 )
49 axs[0].plot(
50 processor_result.extra_result.distances_m,
51 processor_result.extra_result.used_threshold,
52 "r",
53 )
54
55 axs[1].plot(result[sensor_ids[0]].distances, result[sensor_ids[0]].strengths, "k.")
56 except _StopReplay:
57 break
58
59 axs[0].legend(["Sweep", "Threshold"], loc="upper left")
60
61 axs[0].set_xlabel("Distance (m)")
62 axs[0].set_ylabel("Amplitude")
63 axs[0].grid()
64
65 axs[1].set_xlabel("Distance (m)")
66 axs[1].set_ylabel("Strength")
67 axs[1].grid()
68
69 plt.legend()
70 plt.suptitle(FILEPATH)
71 plt.show()
72
73
74if __name__ == "__main__":
75 main()
View this example on GitHub: acconeer/acconeer-python-exploration