MoxTools 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of MoxTools might be problematic. Click here for more details.
- MoxTools-0.1.dist-info/METADATA +6 -0
- MoxTools-0.1.dist-info/RECORD +14 -0
- MoxTools-0.1.dist-info/WHEEL +5 -0
- MoxTools-0.1.dist-info/top_level.txt +1 -0
- MxTools/__init__.py +16 -0
- MxTools/asmt_tool.py +114 -0
- MxTools/chart.py +560 -0
- MxTools/dataIO.py +152 -0
- MxTools/dataProc.py +92 -0
- MxTools/fileMg.py +119 -0
- MxTools/lsf.py +183 -0
- MxTools/radarIO.py +395 -0
- MxTools/radarSP.py +702 -0
- MxTools/testImage.py +59 -0
MxTools/radarIO.py
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import numpy as np
|
|
3
|
+
import logging
|
|
4
|
+
from MxTools import radarSP
|
|
5
|
+
# from itertools import zip_longest
|
|
6
|
+
import csv
|
|
7
|
+
import pandas as pd
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# def read_rs60g_csv(fpath):
|
|
11
|
+
# """
|
|
12
|
+
# Reads an RS60G radar CSV file and parses raw and clustered data.
|
|
13
|
+
|
|
14
|
+
# Parameters:
|
|
15
|
+
# fpath (str): Path to the CSV file.
|
|
16
|
+
|
|
17
|
+
# Returns:
|
|
18
|
+
# dict: Parsed radar data including raw and clustered information + additional anlge information.
|
|
19
|
+
# """
|
|
20
|
+
|
|
21
|
+
# # Define CSV field indexes
|
|
22
|
+
# RAW_OFFSET = 3 # Start index for raw data
|
|
23
|
+
# CLST_OFFSET = 99 # Start index for clustered data
|
|
24
|
+
# RAW_FIELDS = 6 # Number of fields per raw entry (x, y, z, r, pow_r, pow_a)
|
|
25
|
+
# CLST_FIELDS = 4 # Number of fields per cluster entry (x, y, z, r)
|
|
26
|
+
|
|
27
|
+
# # Initialize lists to store extracted data
|
|
28
|
+
# ts, counter, num_raw, raw_data, num_clst, clst_data = [], [], [], [], [], []
|
|
29
|
+
|
|
30
|
+
# with open(fpath, newline="") as csv_file:
|
|
31
|
+
# rows = csv.reader(csv_file, delimiter=",")
|
|
32
|
+
# next(rows) # Skip header row
|
|
33
|
+
|
|
34
|
+
# for row in rows:
|
|
35
|
+
# # Extract metadata
|
|
36
|
+
# timeStamp, cnt, rawN = int(row[0]), int(row[1]), int(row[2])
|
|
37
|
+
|
|
38
|
+
# ts.append(timeStamp)
|
|
39
|
+
# counter.append(cnt)
|
|
40
|
+
# num_raw.append(rawN)
|
|
41
|
+
|
|
42
|
+
# # Parse raw data
|
|
43
|
+
# raw_entry = []
|
|
44
|
+
# if rawN > 0:
|
|
45
|
+
# for i in range(rawN):
|
|
46
|
+
# # Extract raw data fields
|
|
47
|
+
# x, y, z = map(int, row[RAW_OFFSET + i * RAW_FIELDS:RAW_OFFSET + i * RAW_FIELDS + 3])
|
|
48
|
+
# r, pow_r, pow_a = map(int, row[RAW_OFFSET + i * RAW_FIELDS + 3:RAW_OFFSET + i * RAW_FIELDS + 6])
|
|
49
|
+
|
|
50
|
+
# # [additional angle infom] Compute angle and store raw data
|
|
51
|
+
# raw_entry.extend([x, y, z, r, pow_r, pow_a, int(radarSP.convert_xz2Angle(x, z))])
|
|
52
|
+
# raw_data.append(raw_entry)
|
|
53
|
+
# else:
|
|
54
|
+
# raw_data.append([0] * 7) # Maintain consistent structure
|
|
55
|
+
|
|
56
|
+
# # Parse clustered data
|
|
57
|
+
# clstN = int(row[CLST_OFFSET])
|
|
58
|
+
# num_clst.append(clstN)
|
|
59
|
+
|
|
60
|
+
# clst_entry = []
|
|
61
|
+
# if clstN > 0:
|
|
62
|
+
# for i in range(clstN):
|
|
63
|
+
# # Extract clustered data fields
|
|
64
|
+
# x, y, z, r = map(int, row[CLST_OFFSET + 1 + i * CLST_FIELDS:CLST_OFFSET + 1 + (i + 1) * CLST_FIELDS])
|
|
65
|
+
|
|
66
|
+
# # [additional angle infom] Compute angle and store clustered data
|
|
67
|
+
# clst_entry.extend([x, y, z, r, int(radarSP.convert_xz2Angle(x, z))])
|
|
68
|
+
# clst_data.append(clst_entry)
|
|
69
|
+
# else:
|
|
70
|
+
# clst_data.append([0] * 5) # Maintain consistent structure
|
|
71
|
+
|
|
72
|
+
# return {
|
|
73
|
+
# "ts": ts,
|
|
74
|
+
# "counter": counter,
|
|
75
|
+
# "num_raw": num_raw,
|
|
76
|
+
# "raw_data": raw_data,
|
|
77
|
+
# "num_clst": num_clst,
|
|
78
|
+
# "clst_data": clst_data
|
|
79
|
+
# }
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def read_rs60g_csv(fpath):
|
|
83
|
+
"""
|
|
84
|
+
Reads an RS60G radar CSV file and parses raw and clustered data.
|
|
85
|
+
Only stores effective data while keeping the header order consistent.
|
|
86
|
+
Also dynamically determines MAX_RAW and MAX_CLST.
|
|
87
|
+
|
|
88
|
+
Parameters:
|
|
89
|
+
fpath (str): Path to the CSV file.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
pd.DataFrame: Parsed radar data in a structured format with ordered headers.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
# Define CSV field indexes
|
|
96
|
+
RAW_OFFSET = 3 # Start index for raw data
|
|
97
|
+
CLST_OFFSET = 99 # Start index for clustered data
|
|
98
|
+
RAW_FIELDS = 6 # Number of fields per raw entry (x, y, z, r, pow_r, pow_a)
|
|
99
|
+
CLST_FIELDS = 4 # Number of fields per cluster entry (x, y, z, r)
|
|
100
|
+
|
|
101
|
+
parsed_data = []
|
|
102
|
+
max_raw_dynamic = 0 # Track maximum num_raw across all frames
|
|
103
|
+
max_clst_dynamic = 0 # Track maximum num_clst across all frames
|
|
104
|
+
|
|
105
|
+
with open(fpath, newline="") as csv_file:
|
|
106
|
+
rows = csv.reader(csv_file, delimiter=",")
|
|
107
|
+
next(rows) # Skip header row
|
|
108
|
+
|
|
109
|
+
for row in rows:
|
|
110
|
+
# Extract metadata
|
|
111
|
+
timeStamp, counter, num_raw = int(row[0]), int(row[1]), int(row[2])
|
|
112
|
+
max_raw_dynamic = max(max_raw_dynamic, num_raw) # Update max raw length
|
|
113
|
+
|
|
114
|
+
# Initialize row_data dictionary
|
|
115
|
+
row_data = {
|
|
116
|
+
"timestamp": timeStamp,
|
|
117
|
+
"counter": counter,
|
|
118
|
+
"num_raw": num_raw,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
# Parse raw data dynamically
|
|
122
|
+
for i in range(num_raw):
|
|
123
|
+
x, y, z = map(int, row[RAW_OFFSET + i * RAW_FIELDS:RAW_OFFSET + i * RAW_FIELDS + 3])
|
|
124
|
+
r, pow_r, pow_a = map(int, row[RAW_OFFSET + i * RAW_FIELDS + 3:RAW_OFFSET + i * RAW_FIELDS + 6])
|
|
125
|
+
|
|
126
|
+
row_data[f"raw_x{i}"] = x
|
|
127
|
+
row_data[f"raw_y{i}"] = y
|
|
128
|
+
row_data[f"raw_z{i}"] = z
|
|
129
|
+
row_data[f"raw_r{i}"] = r
|
|
130
|
+
row_data[f"raw_a{i}"] = int(radarSP.convert_xz2Angle(x, z)) # Add angle information
|
|
131
|
+
row_data[f"raw_pow_r{i}"] = pow_r
|
|
132
|
+
row_data[f"raw_pow_a{i}"] = pow_a
|
|
133
|
+
|
|
134
|
+
# Parse clustered data dynamically
|
|
135
|
+
num_clst = int(row[CLST_OFFSET])
|
|
136
|
+
max_clst_dynamic = max(max_clst_dynamic, num_clst) # Update max cluster length
|
|
137
|
+
row_data["num_clst"] = num_clst
|
|
138
|
+
|
|
139
|
+
for i in range(num_clst):
|
|
140
|
+
x, y, z, r = map(int, row[CLST_OFFSET + 1 + i * CLST_FIELDS:CLST_OFFSET + 1 + (i + 1) * CLST_FIELDS])
|
|
141
|
+
|
|
142
|
+
row_data[f"clst_x{i}"] = x
|
|
143
|
+
row_data[f"clst_y{i}"] = y
|
|
144
|
+
row_data[f"clst_z{i}"] = z
|
|
145
|
+
row_data[f"clst_r{i}"] = r
|
|
146
|
+
row_data[f"clst_a{i}"] = int(radarSP.convert_xz2Angle(x, z)) # Add angle information
|
|
147
|
+
|
|
148
|
+
# Append parsed row data
|
|
149
|
+
parsed_data.append(row_data)
|
|
150
|
+
|
|
151
|
+
# Convert parsed data to DataFrame
|
|
152
|
+
df = pd.DataFrame(parsed_data)
|
|
153
|
+
|
|
154
|
+
# Define ordered columns dynamically
|
|
155
|
+
ordered_columns = ["timestamp", "counter", "num_raw"]
|
|
156
|
+
|
|
157
|
+
# Add raw data columns in order based on `max_raw_dynamic`
|
|
158
|
+
for i in range(max_raw_dynamic):
|
|
159
|
+
ordered_columns.extend([f"raw_x{i}", f"raw_y{i}", f"raw_z{i}", f"raw_r{i}", f"raw_a{i}", f"raw_pow_r{i}", f"raw_pow_a{i}"])
|
|
160
|
+
|
|
161
|
+
# Add cluster data columns in order based on `max_clst_dynamic`
|
|
162
|
+
ordered_columns.append("num_clst") # Insert num_clst before cluster data
|
|
163
|
+
for i in range(max_clst_dynamic):
|
|
164
|
+
ordered_columns.extend([f"clst_x{i}", f"clst_y{i}", f"clst_z{i}", f"clst_r{i}", f"clst_a{i}"])
|
|
165
|
+
|
|
166
|
+
# Ensure DataFrame columns are in the correct order
|
|
167
|
+
df = df.reindex(columns=ordered_columns, fill_value=None)
|
|
168
|
+
|
|
169
|
+
return df
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# read clst log data from sim_command_line tool
|
|
176
|
+
def read_clst_log(fpath, uint_div):
|
|
177
|
+
frameNo = []
|
|
178
|
+
NumDetObj = []
|
|
179
|
+
clst_x = []
|
|
180
|
+
clst_y = []
|
|
181
|
+
clst_z = []
|
|
182
|
+
clst_r = []
|
|
183
|
+
with open(fpath, newline="") as tsv:
|
|
184
|
+
rows = csv.reader(tsv, dialect="excel-tab")
|
|
185
|
+
for row in rows:
|
|
186
|
+
fno = int(row[1])
|
|
187
|
+
N = int(row[3])
|
|
188
|
+
x = np.divide(int(row[5]), uint_div)
|
|
189
|
+
y = np.divide(int(row[7]), uint_div)
|
|
190
|
+
z = np.divide(int(row[9]), uint_div)
|
|
191
|
+
r = math.sqrt(x * x + z * z)
|
|
192
|
+
|
|
193
|
+
frameNo.append(fno)
|
|
194
|
+
NumDetObj.append(N)
|
|
195
|
+
clst_x.append(x)
|
|
196
|
+
clst_y.append(y)
|
|
197
|
+
clst_z.append(z)
|
|
198
|
+
clst_r.append(r)
|
|
199
|
+
out_dict = {
|
|
200
|
+
"frameNo": frameNo,
|
|
201
|
+
"NumDetObj": NumDetObj,
|
|
202
|
+
"clst_x": clst_x,
|
|
203
|
+
"clst_y": clst_y,
|
|
204
|
+
"clst_z": clst_z,
|
|
205
|
+
"clst_r": clst_r,
|
|
206
|
+
}
|
|
207
|
+
return out_dict
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
# read clst log data from approach detection v1.1 tool
|
|
212
|
+
# please use rename.sh first
|
|
213
|
+
def read_clst_log_ap(fpath, uint_div):
|
|
214
|
+
frameNo = []
|
|
215
|
+
NumDetObj = []
|
|
216
|
+
clst_x = []
|
|
217
|
+
clst_y = []
|
|
218
|
+
clst_z = []
|
|
219
|
+
clst_r = []
|
|
220
|
+
with open(fpath, newline="") as tsv:
|
|
221
|
+
rows = csv.reader(tsv, dialect="excel-tab")
|
|
222
|
+
for row in rows:
|
|
223
|
+
if row[0] != "apn":
|
|
224
|
+
continue
|
|
225
|
+
fno = int(row[3])
|
|
226
|
+
N = int(row[5])
|
|
227
|
+
x = np.divide(int(row[6]), uint_div)
|
|
228
|
+
y = np.divide(int(row[7]), uint_div)
|
|
229
|
+
z = np.divide(int(row[8]), uint_div)
|
|
230
|
+
r = np.divide(int(row[9]), uint_div)
|
|
231
|
+
|
|
232
|
+
frameNo.append(fno)
|
|
233
|
+
NumDetObj.append(N)
|
|
234
|
+
clst_x.append(x)
|
|
235
|
+
clst_y.append(y)
|
|
236
|
+
clst_z.append(z)
|
|
237
|
+
clst_r.append(r)
|
|
238
|
+
out_dict = {
|
|
239
|
+
"frameNo": frameNo,
|
|
240
|
+
"NumDetObj": NumDetObj,
|
|
241
|
+
"clst_x": clst_x,
|
|
242
|
+
"clst_y": clst_y,
|
|
243
|
+
"clst_z": clst_z,
|
|
244
|
+
"clst_r": clst_r,
|
|
245
|
+
}
|
|
246
|
+
return out_dict
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def read_detout_log_ap(fpath, level):
|
|
250
|
+
frameNo = []
|
|
251
|
+
detout = []
|
|
252
|
+
det_fno = []
|
|
253
|
+
with open(fpath, newline="") as tsv:
|
|
254
|
+
rows = csv.reader(tsv, dialect="excel-tab")
|
|
255
|
+
for row in rows:
|
|
256
|
+
if row[0] != "fno":
|
|
257
|
+
continue
|
|
258
|
+
fno = int(row[1])
|
|
259
|
+
do = int(row[3]) * level
|
|
260
|
+
if do != 0:
|
|
261
|
+
det_fno.append(fno)
|
|
262
|
+
frameNo.append(fno)
|
|
263
|
+
detout.append(do)
|
|
264
|
+
if not det_fno:
|
|
265
|
+
det_fno = [0, 0]
|
|
266
|
+
out_dict = {
|
|
267
|
+
"frameNo": frameNo,
|
|
268
|
+
"detout": detout,
|
|
269
|
+
"det_min_max_fno": [min(det_fno), max(det_fno)],
|
|
270
|
+
}
|
|
271
|
+
return out_dict
|
|
272
|
+
|
|
273
|
+
def read_conf_param(conf_path, param: str):
|
|
274
|
+
|
|
275
|
+
with open(conf_path, newline="") as txt:
|
|
276
|
+
rows = csv.reader(txt, delimiter=" ")
|
|
277
|
+
for row in rows:
|
|
278
|
+
if param == row[0]:
|
|
279
|
+
value = row[1 : len(row)]
|
|
280
|
+
|
|
281
|
+
return value
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
# Reads and parses FIFO data from a file.
|
|
285
|
+
# The function processes a text file containing structured FIFO data, including sections
|
|
286
|
+
# like [number], [time], [frame:size], [frame:counter], and [frame:data]. It extracts
|
|
287
|
+
# relevant information into categorized lists.
|
|
288
|
+
|
|
289
|
+
# Parameters:
|
|
290
|
+
# path (str): Path to the FIFO data file.
|
|
291
|
+
|
|
292
|
+
# Returns:
|
|
293
|
+
# dict: A dictionary containing:
|
|
294
|
+
# - "number" (list[int]): List of numbers from the [number] section.
|
|
295
|
+
# - "timeStamp" (list[int]): List of timestamps from the [time] section.
|
|
296
|
+
# - "frameSize" (list[int]): Frame sizes from the [frame:size] section.
|
|
297
|
+
# - "frameCnt" (list[int]): Frame counters from the [frame:counter] section.
|
|
298
|
+
# - "frameData" (list[list[str]]): Nested list of frame data from the [frame:data] section.
|
|
299
|
+
# - "ReadDataSize" (list[int]): List of data sizes for each frame.
|
|
300
|
+
def read_FIFO_dat(path):
|
|
301
|
+
|
|
302
|
+
# 初始化結果數據結構
|
|
303
|
+
out_dict = {
|
|
304
|
+
"number": [],
|
|
305
|
+
"timeStamp": [],
|
|
306
|
+
"frameSize": [],
|
|
307
|
+
"frameCnt": [],
|
|
308
|
+
"frameData": [],
|
|
309
|
+
"ReadDataSize": [],
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
# 初始化中間變數
|
|
313
|
+
current_frame_data = []
|
|
314
|
+
read_data_cnt = 0
|
|
315
|
+
|
|
316
|
+
# 定義標誌字典
|
|
317
|
+
flags = {
|
|
318
|
+
"number_fg": False,
|
|
319
|
+
"time_fg": False,
|
|
320
|
+
"size_fg": False,
|
|
321
|
+
"counter_fg": False,
|
|
322
|
+
"data_fg": False,
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
try:
|
|
326
|
+
with open(path, "r") as f:
|
|
327
|
+
for line in f: # 遍歷文件行
|
|
328
|
+
s = line.strip() # 去除空白與換行符
|
|
329
|
+
|
|
330
|
+
# 處理數據依據標誌
|
|
331
|
+
if flags["number_fg"]:
|
|
332
|
+
out_dict["number"].append(int(s, 16))
|
|
333
|
+
flags["number_fg"] = False
|
|
334
|
+
elif flags["time_fg"]:
|
|
335
|
+
out_dict["timeStamp"].append(int(s, 16))
|
|
336
|
+
flags["time_fg"] = False
|
|
337
|
+
elif flags["size_fg"]:
|
|
338
|
+
out_dict["frameSize"].append(int(s, 16))
|
|
339
|
+
flags["size_fg"] = False
|
|
340
|
+
elif flags["counter_fg"]:
|
|
341
|
+
out_dict["frameCnt"].append(int(s, 16))
|
|
342
|
+
flags["counter_fg"] = False
|
|
343
|
+
elif flags["data_fg"]:
|
|
344
|
+
if s != "[number]" and len(s) == 8:
|
|
345
|
+
current_frame_data.append(s)
|
|
346
|
+
read_data_cnt += 1
|
|
347
|
+
|
|
348
|
+
# 更新標誌位
|
|
349
|
+
if s == "[number]":
|
|
350
|
+
flags.update({"number_fg": True, "data_fg": False})
|
|
351
|
+
elif s == "[time]":
|
|
352
|
+
flags["time_fg"] = True
|
|
353
|
+
elif s == "[frame:size]":
|
|
354
|
+
flags["size_fg"] = True
|
|
355
|
+
elif s == "[frame:counter]":
|
|
356
|
+
flags["counter_fg"] = True
|
|
357
|
+
elif s == "[frame:data]":
|
|
358
|
+
flags["data_fg"] = True
|
|
359
|
+
read_data_cnt = 0 # 重置計數
|
|
360
|
+
|
|
361
|
+
# 處理結束當前 frame
|
|
362
|
+
if not flags["data_fg"] and read_data_cnt > 0:
|
|
363
|
+
out_dict["ReadDataSize"].append(read_data_cnt)
|
|
364
|
+
out_dict["frameData"].append(current_frame_data)
|
|
365
|
+
current_frame_data = []
|
|
366
|
+
read_data_cnt = 0
|
|
367
|
+
|
|
368
|
+
# 最後一個 frame 的數據處理
|
|
369
|
+
if flags["data_fg"] and read_data_cnt > 0:
|
|
370
|
+
out_dict["ReadDataSize"].append(read_data_cnt)
|
|
371
|
+
out_dict["frameData"].append(current_frame_data)
|
|
372
|
+
|
|
373
|
+
except FileNotFoundError as error:
|
|
374
|
+
print(f"Error: {error}")
|
|
375
|
+
exit()
|
|
376
|
+
|
|
377
|
+
return out_dict
|
|
378
|
+
|
|
379
|
+
# save vaild data into new .dat file
|
|
380
|
+
# format is same as SNI format
|
|
381
|
+
def save_vaild_data(path, data: dict):
|
|
382
|
+
total_frame = len(data["number"])
|
|
383
|
+
with open(path, "w") as f:
|
|
384
|
+
for i in range(total_frame):
|
|
385
|
+
f.write("[number]\n")
|
|
386
|
+
f.write("{:08x}\n".format(data["number"][i]))
|
|
387
|
+
f.write("[time]\n")
|
|
388
|
+
f.write("{:08x}\n".format(data["timeStamp"][i]))
|
|
389
|
+
f.write("[frame:size]\n")
|
|
390
|
+
f.write("{:04x}\n".format(data["frameSize"][i]))
|
|
391
|
+
f.write("[frame:counter]\n")
|
|
392
|
+
f.write("{:02x}\n".format(data["frameCnt"][i]))
|
|
393
|
+
f.write("[frame:data]\n")
|
|
394
|
+
for j in range(data["frameSize"][i]):
|
|
395
|
+
f.write(data["frameData"][i][j] + "\n")
|