Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Int or float value instead of string in conversion? #176

Closed
rolfub opened this issue Nov 19, 2019 · 10 comments
Closed

Int or float value instead of string in conversion? #176

rolfub opened this issue Nov 19, 2019 · 10 comments

Comments

@rolfub
Copy link

rolfub commented Nov 19, 2019

Screenshot

Hello Aymeric,
I have a question. Is it possible to get a float or integer value instead of "Error_ORH" when using conversion? (see also Screenshot.png)
Yours sincerely,
Rolf

@ratal
Copy link
Owner

ratal commented Nov 22, 2019

Hi,
Your channel is unicode, not integer, even the u'3902.0'.
I guess you could use convert_after_read=False to get raw data by looking at the 'data' key value and change the channel conversion to your needs.

@rolfub
Copy link
Author

rolfub commented Nov 25, 2019

Hello Aymeric,
thank you for your answer. Now I see that I haven't wrote it correctly. :-(
I meant that "Error_ORH" is a problem for plotting the values. u"3902.0" for example is not that critical. You can convert it to a float value before plotting but that is not possible with "ERROR_ORH". So, is it possible to get a value instead of a name?
Yours sincerely,
Rolf

@ratal
Copy link
Owner

ratal commented Nov 25, 2019

Hi,
These unicode are most probably not recorded in the mdf but numbers instead that are later converted based on conversion channel type and content.
If you read the file with convert_after_read=False argument, each channel's ['data'] will be kept not converted along with its conversion channel to convert the data 'on demand', basically if get_channel_data() is called. It is more memory efficient and conversion generally requires lot of computation. For instance, if you consider time, it is probably an unsigned integer 32 that is then converted by multiplying to a floating (sampling time), giving a float64, occupying twice memory.
In your case, you could read the file without conversion, look at the conversion channel and replace the Error_ORH by what you want, like zero. If it is value to text conversion, it is most probably inside the cc_ref list.
This might ask too much knowledge of mdf so an an alternative is to use MaskedArray by creating your own mask, then you should have no issue while plotting. It could be like this (not tested):
data = data.view(MaskedArray)
data = masked_equal(u'Error_ORH', data)

@rolfub
Copy link
Author

rolfub commented Dec 12, 2019

Hello Aymeric,
my colleagues means that I haven't explained it correctly to you, so he creates some screenshots to show his problem.

He not only wants to plot the values but to use the values for calculations. So he needs all values in integer or float format (-> screenshot):

grafik

To get this values he does some modifications to your code (-> screenshot).

grafik
grafik

He wants me to ask you if there is a possibility to create a solution for him because he does not want to modificate your code.

Yours sincerely,

Rolf

@ratal
Copy link
Owner

ratal commented Dec 12, 2019

Same as my previous comment, use convert_after_read parameter :
yop=mdfreader.Mdf('yourfilename', convert_after_read=False)
_value_to_text_conversion() will not be called and you will be able to access "raw" data with yop['channelName]['data'] (not .get_channel_data() )
To keep it as is, you could simply remove the conversion class below yop['channelName'].pop('conversion') to use .get_channel_data() later without conversion

@danielhrisca
Copy link
Contributor

@ratal I think you mean get_channel_data

@ratal
Copy link
Owner

ratal commented Dec 12, 2019

thanks Daniel :)

@rolfub
Copy link
Author

rolfub commented Dec 13, 2019

Hello Aymeric,

you are wright, I will get then the raw data without conversion.
But my colleagues needs the conversion with the data from cc_ref to get the scaled values of bus signals.

Yours sincerely,

Rolf

@ratal
Copy link
Owner

ratal commented Dec 15, 2019

Hi,
You can modify the CCBlock conversion block class contained in yop['channelName']['conversion'] the way you want.
It contains the cc_ref, you can modify it. You could even change type of conversion if you wish.

@ratal
Copy link
Owner

ratal commented Feb 11, 2020

I guess you could succeed, closing

@ratal ratal closed this as completed Feb 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants