danielhrisca / asammdf

Fast Python reader and editor for ASAM MDF / MF4 (Measurement Data Format) files
GNU Lesser General Public License v3.0
633 stars 224 forks source link

Unable to add String Signal to a new MDF #439

Closed nos86 closed 3 years ago

nos86 commented 3 years ago

Python version

python=3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] os=Windows-10-10.0.19041-SP0

numpy=1.18.5 asammdf=5.22.0

Code

Code snippet


  m = mdf.MDF(version="4.20")
  sig = mdf.asammdf.Signal(samples=[b'pippo', b'pluto', b'paperino'], timestamps=[0,1,2], name="test", encoding="utf-8", raw=False)
  m.append([sig])
  m.get('test')

Traceback


AttributeError Traceback (most recent call last)

in ----> 1 w.get('test') C:\ProgramData\Anaconda3\envs\jarvis\lib\site-packages\asammdf\blocks\mdf_v4.py in get(self, name, group, index, raster, samples_only, data, raw, ignore_invalidation_bits, source, record_offset, record_count) 6052 6053 else: -> 6054 vals, timestamps, invalidation_bits, encoding = self._get_scalar( 6055 channel=channel, 6056 group=grp, C:\ProgramData\Anaconda3\envs\jarvis\lib\site-packages\asammdf\blocks\mdf_v4.py in _get_scalar(self, channel, group, group_index, channel_index, dependency_list, raster, data, ignore_invalidation_bits, record_offset, record_count, master_is_required) 6948 else: 6949 if kind_ in "ui": -> 6950 if channel.dtype_fmt.subdtype: 6951 channel_dtype = channel.dtype_fmt.subdtype[ 6952 0 AttributeError: type object 'numpy.uint64' has no attribute 'subdtype' # Description Hello Daniel, I'm again to play with your library. At this time, I'd like to do an "other way around" job: I start from a DataFrame and I want to create a MF4 file. The dataframe has some numerical channels and some other string channels: this last type makes me crazy. Initially, I had problem to append the Signal to the mdf object, but then I solved it forcing the binary string. Now I'm able to do it, but if I try to get the channel I receive the error above and if I try to save to file and open with external software (like AVL Concerto) I retrieve an empty array. How can I solve it? It's something wrong from my side? Thanks in advance, Salvo
danielhrisca commented 3 years ago

MDF version 4.20 is pretty new and I don't know another tool that has support for it. For sure there are also bugs in my implementation of the new version.

For now you should stick to using version 4.11

nos86 commented 3 years ago

I discovered it 2 minutes after the PR opening. I tried to downgrade version to 4.10 and it works. :) I have another question, is it possible to set the timestamps as strings? Is it something allowed by the MDF standard?

danielhrisca commented 3 years ago

What would be the use case for this? I think using a default X axis would be the way to do something like this but I haven't tried with other tools (CANape, ETAS). Default X axis is ignored by this library (https://github.com/danielhrisca/asammdf/blob/master/asammdf/blocks/v4_blocks.py#L554)

nos86 commented 3 years ago

I'm creating an MF4 with Raw Data as well post-processed data in two different groups. In the second group, I'd like to save a table like: INDEX | Coolant Temperature | Engine Speed | Vehicle Speed Min Max Avg Std.dev

danielhrisca commented 3 years ago

The best you can do is use separate column for the category INDEX | Category| Coolant Temperature | Engine Speed | Vehicle Speed 0 |Min 1 |Max 2 |Avg 3 |Std.dev

nos86 commented 3 years ago

yeah.. this is exactly what I'm doing now as a workaround. :) For the moment I think we can close the issue.

Thank you for your support (as always). Salvo