Repository navigation
Expand file tree
/
Copy pathplot_dat.py
More file actions
49 lines (40 loc) · 2.03 KB
/
Copy pathplot_dat.py
File metadata and controls
49 lines (40 loc) · 2.03 KB
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
import argparse
import os
import sys
import subprocess
from typing import List
import numpy as np
SCRIPT_FOLDER = os.path.dirname(os.path.realpath(__file__))
sys.path.append(SCRIPT_FOLDER) # add script folder to path to find dependent modules
import plot
ESMINI_PATH = os.path.realpath(os.path.join(SCRIPT_FOLDER, '..')) # path to esmini root folder
def get_labels_line_extended() -> List[str]:
""" Get the extended labels line """
return ['time', 'id', 'name', 'x', 'y', 'z', 'h', 'p', 'r', 'roadId', 'laneId', 'offset', 't', 's', 'speed', 'wheel_angle', 'wheel_rot']
if __name__ == "__main__":
# Create the parser
parser = argparse.ArgumentParser(description='Plot esmini log data')
# Add the arguments
parser.add_argument('--x_axis', help='x-axis parameter', default='time')
parser.add_argument('--equal_axis_aspect', help='lock aspect ratio = 1:1', action='store_true')
parser.add_argument('filename', help='dat filename')
parser.add_argument('--derive', help='derive values wrt x, i.e. dy/dx', action='store_true')
parser.add_argument('--dots', help='add dots', action='store_true')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--list_params', help='list available parameters in given file', action='store_true')
group.add_argument('--param', help='parameter(s) to plot. Multiple parameters separated by "," NOTE: no space!', action='append')
# Execute the parse_args() method
args = parser.parse_args()
esmini_args = [os.path.join(ESMINI_PATH,'bin','dat2csv'), "--file", args.filename, '--extended', '--print_csv']
process = subprocess.Popen(esmini_args, stdout=subprocess.PIPE, text=True)
csv_data = process.stdout.read().strip().splitlines()
data = np.genfromtxt(csv_data[1:], delimiter=',', names=True, dtype=None, encoding=None, autostrip=True)
plot.plot(
data, get_labels_line_extended(),
args.param,
args.x_axis,
args.derive,
args.dots,
args.equal_axis_aspect,
args.list_params
)