asam mdf reader

previously reviewed a few open source mdf readers as well as get basic concept about mdf. here is a working process with asammdf, which is step by step to understand this lib.

the basic problem here is to read a special signal data, not know its channel and group id.

first try

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
reader = MDF4(file_name)
data_dict = reader.info()
print("the total len of dict: ", len(data_dict))
print(data_dict.keys())
block_ = data_dict['group 117']
channel_metadata = reader.get_channel_metadata('t', 117)
channel117_comment = reader.get_channel_comment('t', 117)
channel117_name = reader.get_channel_name(117, 0)
pattern="channel 123"
for key in block_ :
r1 = re.search(pattern, str(block_[key]), re.M|re.I)
if r1:
print(key)
data_ = reader.get("channel 123") #doesn't work, as it reports can't find Channel
data_ = reader.get("fus_lidar_camera", "group 123") #doesn't work, as it reports can't find the Group
data_ = reader.get("fus_lidar_camera") #works

so first, “channel 123” is actually not the name. and with the right name can reading data, but no guarantee which group this channel is from, and further can’t know is there additional groups has record this type of data.

second try

as mentioned mdf4 groups have attributes, how about to access these attributes. so far, especially helpful attributes are:

  • groups:list, list of data group dicts

  • channels_db:dict, used for fast channel access by name. for each name key the value is a list of (group index, channel index) tuples

1
2
3
4
5
6
7
8
9
channels = reader.groups[2] #with the same order as found in mdf, even with index 0, 1, ...
print("type of channels: ", type(channels)) #dict
if "fus.ObjData_Qm_TC.FusObj.i17.alpPiYawAngle" in channels: print(channels["fus.ObjData_Qm_TC.FusObj.i17.alpPiYawAngle"].id) #none
print(" chanels type: " , type(channels["channels"])) #list
print(" chanels len: " , len(channels["channels"])) #577
print("chanel_group type: " , type(channels["channel_group"])) # ChannelGroup object
print("chanel_group len: " , len(channels["channel_group"])) #17
print(" data_group type: " , type(channels["data_group"])) #DataGroup object
print(" data_group len: " , len(channels["data_group"])) #10

which is far more less as expected, but give an good exploring about the reader’s attributes.

third try

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
reader = MDF4(file_name)
cdb = reader.channels_db
#print("size of c_db ", len(cdb))
#print("type of cdb ", type(cdb))
#for more sigles interested, please append to this list
sig_list = ['sensor_1', 'sensor_2', 'sensor_3']
for sig in sig_list:
if sig in cdb:
print(cdb[sig])
for item in cdb[sig]:
(gid, cid) = item
alp = reader.get(sig, gid, cid)
print("type of current sig ", type(alp))
print("size of current sig ", len(alp))
#alp is the raw sig data, here is only test print
else:
print(sig, " is not in cdb"

which gives me the right way to access the interested signals’ raw data. combing with s3 streaming body read, as mentioned in previous mdf-reader, which finally gives the powerful pipeline from reading mdf4 files from s3 storage to downside appilication

refer

pyton reg

python substring