Closed loucik closed 5 years ago
For scalar conversions you get the physical values when you call get with raw=False (this is default):
m = MDF(filename)
ch = m.get(channelname)
# ch has the physical values for scalar channel and raw to value to text conversions
for value to string conversions the samples are the raw values and you can use the physical method of Signal objects
f = MDF(f)
ch = f.get('Signal_Value2TextConversion')
print(ch.samples)
print(ch.physical().samples)
[0 0 1 1 0]
[b'off' b'off' b'on' b'on' b'off']
This is done using the conversion attribute (the referencedblocks will hold the text values associated with the raw values
print(ch.conversion)
<ChannelConversion (name: Verbal Table Scaling, unit: , comment: <CCcomment xmlns="http://www.asam.net/mdf/v4"><TX></TX><common_properties><e name="format" type="string">%g</e></common_properties></CCcomment>, formula: ,
referenced blocks:
{'text_0': {'id': b'##TX', 'reserved0': 0, 'block_len': 32, 'links_nr': 0, 'text': b'off\x00'},
'text_1': {'id': b'##TX', 'reserved0': 0, 'block_len': 32, 'links_nr': 0, 'text': b'on\x00'},
'default_addr': None},
address: 0x2d8, fields: {'id': b'##CC', 'reserved0': 0, 'block_len': 120, 'links_nr': 7, 'name_addr': 416, 'unit_addr': 464, 'comment_addr': 496, 'inv_conv_addr': 0, 'text_0': 664, 'text_1': 696, 'default_addr': 0, 'conversion_type': 7, 'precision': 0, 'flags': 0, 'ref_param_nr': 3, 'val_param_nr': 2, 'min_phy_value': 0.0, 'max_phy_value': 0.0, 'val_0': 0.0, 'val_1': 1.0})>
I am not sure why, but I am getting float64 values when I put following code
print(signal_data.samples)
print(signal_data.physical().samples)
[3 3 3 ... 0 0 0]
[ 3. 3. 3. ... nan nan nan]
But when I used conversion request, I can see following values...so it seems, it should work.
referenced blocks:
{'text_0': {'id': b'##TX', 'reserved0': 0, 'block_len': 32, 'links_nr': 0, 'text': b'Inaktiv\x00'}, 'text_1': {'id': b'##TX', 'reserved0': 0, 'block_len': 32, 'links_nr': 0, 'text': b'Aktiv\x00'}, 'text_2': {'id': b'##TX', 'reserved0': 0, 'block_len': 40, 'links_nr': 0, 'text': b'Not qualified\x00'}
Do you have any idea, what I missed? Thanks
Your channel has partial conversion. This means that for some raw values you will get a numeric physical value and for other you would get a string as physical value.
Since numpy does not allow mixed dtypes there are 2 options
Python version
('python=3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit ' '(AMD64)]') 'os=Windows-10-10.0.16299-SP0' 'numpy=1.14.6' 'asammdf=4.7.7' 'pyqtgraph=0.10.0'
MDF version
4.00
Questions
I have exported *.mf4 file. 1. How can I import physical values of signal to numpy array. I only know how to import raw values as
RawSamples = Signal.samples
Is there any function how to import pyhs. values in same way?2. If I get physical values on y-axis, how can I change number values to name values e.g. value 0 to value "Inactive", value 1 to "Active" etc.... Note: I use Fibex database (*.xml format)
Thanks