ratal / mdfreader

Read Measurement Data Format (MDF) versions 3.x and 4.x file formats in python
Other
170 stars 75 forks source link

'convertAfterRead' does not work #90

Closed gr1nk0 closed 6 years ago

gr1nk0 commented 7 years ago

Hello, I have a problem with the mdfreader. I want to read in a mdf-file, resample it and then export it into a mat-file. All steps are working, but I receive only raw values for my data.

If I have a look at the mdf-file with CANape all the files are shown in a correct way. But if I have a look at the exported mat-file, I get all the data in raw format. Normally there should be values with an included calculated factor and offset. But this part doesn't work even if I use the 'convertAfterRead'-flag...

An example for the used code: yop = mdfreader.mdf(mdf_path1, convertAfterRead=True)

I tried a lot of different things and read through the documentation for the mdfreader, but I wasn't successful.

I hope you can help me with this problem. Thank you in advance!

PS: I work with mdf-files of version 4.10 (compressed), Python 3 and mdfreader version 0.2.2

ratal commented 7 years ago

Hi, Version 0.2.2 is rather old so I would strongly advise you to test it with latest version. Anyway, I will try to investigate with 0.2.2 but in the mean time, when doing .getChannelData(channel), does it returns raw data or converted data ?

gr1nk0 commented 7 years ago

Anyway I got another issue: Can I do a resampling for the data with an interpolation which sticks to the last value until a new value is recognized for that signal?

So if I have signals which are represented by integers I would only that int-values. For example if I have a signal with values as 0, 1 and 2, I only want those values. Not 0.5 or 0.75 to a time point between the raising from 0 to 1.

Is this kind of interpolation available?

danielhrisca commented 7 years ago

You could use something similar with the interp method from the Signal class here:

https://github.com/danielhrisca/asammdf/blob/master/asammdf/signal.py

ratal commented 7 years ago

Another simple way could be to replace numpy.interp by scipy.interpolate.interp1d in resample method of mdfreader and specify kind='nearest' (many others are also available). Can be an improvement. Daniel's implementation will give another result (step between the points compared to at points) What is your preference, I guess depends of your data ?

danielhrisca commented 7 years ago

My rational was that most of the times integer channel are some flags, codes or states, and that when interpolating you should take the previous value.

ratal commented 7 years ago

If the signal represents something physical, you cannot know when is the transition or step between 2 points so stepping at left, right or middle point does not matter. But I agree with you, most channels recording in mdf are representing logic variables so your approach makes sense --> I Will add your approach as default option in resample when I have some spare time.

danielhrisca commented 7 years ago

Obviously this approach does not fit all cases, but in this context of automotive oriented measurement files I think it's the better/safer way.

ratal commented 7 years ago

In the mean time gr1nk0, did you solve your issue with raw data and .getChannelData() ? Or should we change title into somehting related to interpolation ?

ratal commented 7 years ago

New interpolation code from Daniel was implemented in last commit, can you check it ?

ratal commented 6 years ago

No feedback since a while, I guess issue solved.