ratal / mdfreader

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

Error in mdf3reader TextConversion (textRangeTableConv) #124

Closed DocBO closed 6 years ago

DocBO commented 6 years ago

For my mdf files of version 3 I had problems in the general reader. I figured out, that it had to do with the text converter which happens to fail in the general try--except block (which is not good!). In my mdf3 file the Textrange item happens to be None, several times, so the line if 'LINEAR_CONV' in text[pair] failed obviously.

I would suggest to fix that with an explicit None - exclude.

    for pair in range(npair):
        text[pair] = conv[pair]['Textrange']
        if text[pair] is None:
            continue
        if 'LINEAR_CONV' in text[pair]:  # linear conversion from CANape
            from sympy import lambdify, symbols
            X = symbols('X')  # variable is X
            left = text[pair].find('"')
            right = text[pair].rfind('"')
            text[pair] = text[pair][left + 1: right].replace('{', '').replace('}', '')
            text[pair] = lambdify(X, text[pair], modules='numpy', dummify=False)
    temp = []
DocBO commented 6 years ago

Another point: the textConversion is awfully slow. But if you read in an unknown data file it would be nice to have a flag something like skipTextConversion. My read-in time (for all channels) goes from 3 sec down to 0.15 sec if I skip that conversion.

ratal commented 6 years ago

Thanks for reporting, I will put your modification in the code but trying to find out why it gets None could help improving its robustness, maybe by analysing with mdfvalidator ? I know it is slow conversion, I could not find any other way to make it more efficient so far, tried several approaches but except by coding it in cython, I do not see any other way. Putting a flag for all corner cases will also become awful. However, you could try to use the argument convertAfterRead=False: this conversion will not be done until you need to access the data with .getChannelData(channelName).

ratal commented 6 years ago

Looking at your issue a bit deeper, I realised you are not the only one to have this comment and attribute "convert_tables" was already implemented for mdf version 4.x but not 3.x for this purpose. In last commit, I implemented it also for mdf3.x If you want to activate it, you can modify its value in mdf.py from True to False.

DocBO commented 6 years ago

Thanks, you have a nice and active project going on here!

ratal commented 6 years ago

I guess you could try it successfully, closing. Repoen if you still have issues.