Asammdf: Rename Channel Group

574 views Asked by At

i am working with asammdf to plot signals and now i have a problem, how can i rename the channel groups with the signal names?

here is my code:

mdf = MDF()
sigs = []
for equipment in table_list:
    print("Table name:", equipment[0])
    df = pd.read_sql_query('select * from ' + equipment[0], con)
    df = df.replace(np.nan, 0)
    if equipment[0] == 'state':
        df_time = (df['id']-df.iloc[0]['id'])
    else:
        df_time = (df['ts']-df.iloc[0]['ts']) * 1e-6
        df.pop('ts')
    sigs = []
    for signal in df.columns.to_list():
        df[signal]
        test_signal = Signal(samples=df[signal],  timestamps=df_time,
                    name=signal,
                    unit='')
        sigs.append(test_signal)
    mdf.append(sigs)
mdf.save('..\\Output\\test_complete.mf4', overwrite=True)

enter image description here

1

There are 1 answers

0
danielhrisca On

You should change the channel group comment

mdf = MDF()
sigs = []
for equipment in table_list:
    print("Table name:", equipment[0])
    df = pd.read_sql_query('select * from ' + equipment[0], con)
    df = df.replace(np.nan, 0)
    if equipment[0] == 'state':
        df_time = (df['id']-df.iloc[0]['id'])
    else:
        df_time = (df['ts']-df.iloc[0]['ts']) * 1e-6
        df.pop('ts')
    sigs = []
    for signal in df.columns.to_list():
        df[signal]
        test_signal = Signal(samples=df[signal],  timestamps=df_time,
                    name=signal,
                    unit='')
        sigs.append(test_signal)
    mdf.append(sigs)
    channel_group = mdf.groups[-1].channel_group
    channel_group.comment = "fancy name"
mdf.save('..\\Output\\test_complete.mf4', overwrite=True)