wonyoung jeong
wonyoung jeong

Reputation: 41

I want convert from MDF file to Dataframe

I use MDF file like asammdf or mdfreader. but my data files is too big. so, I want read specific data and make a dataframe.

  1. mdf data reader using asammdf from asammdf import MDF
    case in mdfreader, there are many errors because my mdf files are same name data and some trouble in resampling (wrong data come-out)

filename = test_t16.dat" ; My MDF data file

yop = MDF(filename) ; mdf reader using asammdf

whl_rr = yop.get('WHL_SPD_RR') ;I pick some datas from mdf files(yop)

whl_rr =

invalidation_bits = {NoneType} None

master_metadata = {tuple} ('TimeChannel', 1)

name = {str} 'WHL_SPD_RR'

raw = {bool} False

samples = {ndarray} [0. ... 0.]

source = {NoneType} None

stream_sync = {bool} False

timestamps = {ndarray} [ 240.4053 ... 2050.81525]

unit = {str} 'km/h' > I want to dataframe like this


from asammdf import MDF
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

filename = r"C:\Users\wonyo\PycharmProjects\test\test_t16.dat"
yop = MDF(filename)

signallist = [ "WHL_SPD_RR","WHL_SPD_FR", "WHL_SPD_RL","WHL_SPD_FL"]

df=[]
def group_len(yop, start, stop):             
    for i in range(start, stop):           
        if yop.get_group(i).empty != True:
            if i == start:
                max_len = len(yop.get_group(i).TimeChannel)
                min_time = min(yop.get_group(i).TimeChannel)

            else:
                max_len = min(max_len, len(yop.get_group(i).TimeChannel))
                min_time = max(min_time, min(yop.get_group(i).TimeChannel))

    return max_len-1000, max(242, min_time + 2) 

grlen_time = group_len(yop, 68, 140)
max_len = grlen_time[0]
min_time = grlen_time[1]
time = np.linspace(0, (max_len - 1) * 0.01, max_len)

for i in range(0,5):

    signal = yop.get(signallist[i])
    signal.timestamps = signal.timestamps - min_time
    signal = signal.interp(time)
    data_sg = signal.samples
    name_sg = signal.name
    inex_sg = signal.timestamps
    mydata = pd.DataFrame( data =data_sg , index=index_sg, columns=name_sg)
    print(df)

whl_spd_fl = signal()

I want to make like this (dataframe)

time    whl_spd_rr    whl_spd_rl   whl_spd_fl    whl_spd_fr
0         0              0            0             0
0.01      1              1            1             1
0.02      2              2            2             2
0.03      4              4            4             4
0.04      10             10           10            10
0.05      15             15           15            15
0.06      20             19           19            19
0.07      21             20           20            20
0.08      22             21           21            21
0.09      24             23           21            22
0.10      10             11           11            11
0.11      8              10           10            10

Upvotes: 4

Views: 16164

Answers (3)

Jonas
Jonas

Reputation: 1847

Since at least asammdf version 5.10.3 from API:

The pandas export option was removed. you should use the method to_dataframe instead.

from asammdf import MDF

mdf_obj = MDF('file.mf4')
df = mdf_obj.to_dataframe()

Upvotes: 3

wonyoung jeong
wonyoung jeong

Reputation: 41

yop = MDF(file_name, memory='minimum')

to_keep = ['Channl1', 'Channel2', ('CR_Bms_Soc_Pc', 102) ] # and so on
df = yop.filter(to_keep).cut(start=240, stop=2050).export('pandas', raster=0.01)

Upvotes: 0

Sarathy Velmurugan
Sarathy Velmurugan

Reputation: 133

df= mdf.filter(signallist).export(fmt='pandas')

Upvotes: 0

Related Questions