-
Notifications
You must be signed in to change notification settings - Fork 0
/
infer_parameters_visualization.py
77 lines (72 loc) · 2.82 KB
/
infer_parameters_visualization.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# SPDX-FileCopyrightText: 2023 German Aerospace Center (DLR)
# SPDX-License-Identifier: Apache-2.0
import os
import re
import sys
import subprocess
def build_call(filename):
with open(filename, 'r') as f:
read_result = False
skip = True
all_segments = []
segments = []
skipped_entries = 0
for line in f:
if skip:
skip = False
continue
if read_result:
if line.startswith('lower:'):
pattern = r"lower:(\s+)(\d+)(\s+)upper:(\s+)(\d+)(.*)"
match = re.search(pattern, line)
if match:
lower_value = int(match.group(2))
upper_value = int(match.group(5))
segments.append((lower_value, upper_value))
else:
print(f"Something is of, expected {pattern} but was: {line}")
exit()
else:
if segments != []:
all_segments.append(segments)
segments = []
else:
if line.strip().startswith('Approximations:'):
pattern = r'Approximations:.*?delta: (\d+)'
match = re.search(pattern, line)
if match:
skipped_entries = int(match.group(1))
if line.startswith('Get segmentation after'):
read_result = True
skip = True
behavior = None
if 'Lateral' in filename:
behavior = 'Lateral'
elif '45Deg' in filename:
behavior = '45Deg'
elif 'Oblique' in filename:
behavior = 'Oblique'
elif 'Straight' in filename:
behavior = 'Straight'
else:
print(f"Unexpected logfile, expected one of the bahviors in the filename but wasnt: {filename}")
calls = []
for i, segments in enumerate(all_segments):
output_location = filename[:-4] + "_best"
if i != 0:
output_location = filename[:-4] + "_a" + str(i)
directory = os.path.dirname(filename)
call = ["python3", "visualize_ship_landing.py", f'-l' ,directory, '-b' ,f'{behavior}', '-s']
segment_str = []
for i, (_, upper) in enumerate(segments):
if i != len(segments)-1:
segment_str.append(str(upper))
for segment in segment_str:
call.append(segment)
call = call + ['-p', output_location, '-e', str(skipped_entries), 'plot']
calls.append(call)
return calls
if __name__ == "__main__":
calls = build_call(sys.argv[1])
for call in calls:
subprocess.run(call)