danielhrisca / asammdf

Fast Python reader and editor for ASAM MDF / MF4 (Measurement Data Format) files
GNU Lesser General Public License v3.0
611 stars 216 forks source link

Provide acq_name and acq_source to append method when filtering #999

Closed Jamezo97 closed 2 months ago

Jamezo97 commented 3 months ago

The channel group acquisition properties of a filtered MDF aren't copied across for MDF versions 4.20 and greater. See the example below for a minimal reproducible example:

from asammdf import MDF, Signal

t, v = [0, 1], [2, 4]
acq_name = "ExampleTask"
signal_name = f"Task.Struct.Value"

for version in ("4.10", "4.20"):
    mdf1 = MDF(version=version)
    mdf1.append([Signal(v, t, name=signal_name)], acq_name=acq_name)

    mdf2 = mdf1.filter([signal_name])
    cg_nr, _ = mdf2.channels_db[signal_name][0]

    result_acq_name = mdf2.groups[cg_nr].channel_group.acq_name
    print(f"Version {version}: {result_acq_name}")

I would expect this to print

Version 4.10: ExampleTask
Version 4.20: ExampleTask

However instead we see

Version 4.10: ExampleTask
Version 4.20: None

This appears to be due to the call to _append_column_oriented for 4.20 version MDFs, which creates multiple groups. However the filter method only updates the acquisition properties for the first group.

A simple fix is to pass the acq_source and acq_name to the append method. However I am unsure if this is the proper solution. Perhaps the current behavior is intended? Or perhaps this change has further ramifications?