How to keep the same structure when copy the old MDF to a new MDF

183 Views Asked by At

I’m using python module asammdf.

I need to edit the data in a datalist from an md4 file and repack the result. I use mdf.append to copy the old channel and add new_channel, but in the end, the new MDF file has a different structure from the old MDF file. How to keep the same structure?

The old structure looks like this: Image of the old structure

The new structure like this wasn't what I want, I need it keeps the same structure as the old md4 file: enter image description here

Here is my code:

origin_mdf_path = 'c:/files/data/origin.mf4'
new_mdf_path = 'c:/files/data/new_mdf.mf4'

mdf = MDF(origin_mdf_path)
new_mdf = MDF()

for m in mdf.iter_channels():
    if m.name != 'VideoRawdata_VC0':
        new_mdf.append(m)
    else:
        new_samples = rebuild_samples(m.samples)
        new_signal = Signal(
            samples=new_samples,
            timestamps=m.timestamps,
            unit=m.unit,
            name=m.name,
            conversion=m.conversion,
            raw=m.raw,
            master_metadata=m.master_metadata,
            display_names=m.display_names,
            attachment=m.attachment,
            stream_sync=m.stream_sync,
            invalidation_bits=m.invalidation_bits,
            source=m.source,
            encoding=m.encoding,
            group_index=m.group_index,
            channel_index=m.channel_index)
        new_mdf.append(new_signal)

new_mdf.save(new_mdf_path)
1

There are 1 best solutions below

0
On

It seems impossible to keep the same structure:
how to keep the same structure when copy the old mdf to a new mdf #786