ratal / mdfreader

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

Support for CANape specific features #112

Closed ginseil closed 6 years ago

ginseil commented 6 years ago

Hi

do you plan to add support for CANape specific features like the following one? image

danielhrisca commented 6 years ago

What you see here is partial conversion and it is a part of the MDF standard.

ratal commented 6 years ago

This is normally supported. However, converted channel might have been empty string because of bug #111 What channel do you get ?

ginseil commented 6 years ago

What I mean is that the defined macro in the default value is applied before the simple range to text mapping is done.

ratal commented 6 years ago

Let me confirm: you expect that default value becomes a linear conversion, not a text ? Similar conversion is existing in mdf4. Possible but I am wondreing how to trigger it. With keyword 'LINEAR CONV' ? Maybe more examples of it would help a bit to get how CANape is doing...

ginseil commented 6 years ago

Let me confirm: you expect that default value becomes a linear conversion, not a text ?

Yes.

Similar conversion is existing in mdf4. Possible but I am wondreing how to trigger it. With keyword 'LINEAR CONV' ?

I think a macro function is surrounded by curly braces, staring with the name of the formula: 'LINEAR_CONV'.

ratal commented 6 years ago

I am currently working on this:

        npair = len(conv)
        lower = [conv[pair]['lowerRange'] for pair in range(npair)]
        upper = [conv[pair]['upperRange'] for pair in range(npair)]
        text = {}
        for pair in range(npair):
            text[pair] = conv[pair]['Textrange']
            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 = []
        for Lindex in range(len(data)):
            value = text[0]  # default value
            for pair in range(1, npair):
                if lower[pair] <= data[Lindex] <= upper[pair]:
                    value = text[pair]
                    break
            if callable(value):
                value = value(data[Lindex])
            temp.append(value)

Can you check if it would be working for you ? unfortunately, the callable() is giving performance penalty

ginseil commented 6 years ago

Hi, I'll test it in the next few days. Thanks for your work!

ginseil commented 6 years ago

There is a bug in your code: if 'LINEAR CONV' in text[pair]: # linear conversion from CANape

I miss the underscore in LINEAR_CONV. However your solution works, once the underscore is added.

ratal commented 6 years ago

Good, I will correct and put in master

ratal commented 6 years ago

Part of last commit, you can check

ginseil commented 6 years ago

Works like a charm, Thank you! :)

danielhrisca commented 6 years ago

@ginseil

I'm trying to replicate this CANape specific feature, however MDFValidator doesn't raise this warning for my file:

image

The conversion block seems to me identical to what you had in your measurement. Is there something else that I don't see?

Edit: I'm using MDFValidator 2.4.4 and 2.3.0

danielhrisca commented 6 years ago

I missed the underscore in _LINEARCONV.