danielhrisca / asammdf

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

Merge/concatenate/extend MDF files #967

Open Hamzapyt opened 9 months ago

Hamzapyt commented 9 months ago

Python version

('python=3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) '
 '[MSC v.1916 64 bit (AMD64)]')
'os=Windows-10-10.0.19045-SP0'
'numpy=1.26.2'
'asammdf=7.3.18'

Code

MDF version

4.10 and 3.00

Code snippet

import os
from asammdf import MDF
import pandas as pd
import numpy as np
import warnings
from tkinter import filedialog

files = filedialog.askopenfilenames(title="Please select your acquisitions", filetypes=[("MDF", "*.dat;*.mf4")])

mdf=MDF()
mdf.extend(files[0])
Channels_ref = set(canal for canal in mdf.channels_db)

for file in files[1:]:
    mdf_temp = MDF(file)
    missing_canals = Channels_ref - set(canal for canal in mdf_temp.channels_db)
    for missing_canal in missing_canals:
        mdf.remove(missing_canal)
        mdf_temp.remove (missing_canal)
    mdf.extend(mdf_temp)

Traceback

Cell In[26], line 1
mdf = MDF.extend(chemin_fichiers)
AttributeError: type object 'MDF' has no attribute 'extend'

Description

It seems that the extend dosn't work with MDF module, i have tried the MDF.concatenate but i have some missing channel on some files regarding the first file (I take the first file as refenrece in terms of channel) my first question is there is any other option to concatenate the MDF files with drop missing channel? my second question is MDF v3 and MDF v4.10 wil havve the same treatment with my privious code?

Thank you, Best regards

danielhrisca commented 8 months ago

It seems that the extend dosn't work with MDF module, i have tried the MDF.concatenate but i have some missing channel on some files regarding the first file (I take the first file as refenrece in terms of channel)

Have a look at the extened method documentation in the MF4 class (https://asammdf.readthedocs.io/en/latest/api.html#mdf4)

my first question is there is any other option to concatenate the MDF files with drop missing channel?

This is not possible, you need to handle this yourself

my second question is MDF v3 and MDF v4.10 wil havve the same treatment with my privious code?

You must use the MDF class. Depending on the measurement file format version you will have access to the additional methods provided by the MF4 or MF3 classes