ratal / mdfreader

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

AttributeError when overwriting (read/write) with write3 #138

Closed skidzo closed 6 years ago

skidzo commented 6 years ago

Pyhton version

'3.6.3 |Anaconda custom (64-bit)| (default, Nov 3 2017, 19:19:16) \n[GCC 7.2.0]'

Platform information

'Linux-4.13.0-37-generic-x86_64-with-debian-stretch-sid'

Numpy version

'1.14.1'

mdfreader version

'2.7.4'

Description

trying to overwrite the file read

MDFVersionNumber

320

File "/home/user/anaconda3/lib/python3.6/site-packages/mdfreader/mdfreader.py", line 430, in write self.write3(fileName=fileName) File "/home/user/anaconda3/lib/python3.6/site-packages/mdfreader/mdf3reader.py", line 1215, in write3 temp = ncode(temp, encoding='latin1', errors='replace') File "/home/user/anaconda3/lib/python3.6/site-packages/numpy/core/defchararray.py", line 540, in encode _vecstring(a, object, 'encode', _clean_args(encoding, errors))) AttributeError: type object 'bytes' has no attribute 'encode'

ratal commented 6 years ago

Hi, thanks for reporting, maybe you can try directly the line just before data.dtype.kind == 'U' 'S' might not make sense for python 3.x, means byte.

skidzo commented 6 years ago

Hi Aymeric,

your suggestion: if data.dtype.kind == 'U'

instead of if data.dtype.kind in ['U','S']

removed the encoding error, but left me with an Exception: Not recognized dtype I found that somewhere in my file i have the data type '>f4'. I added it in two lines where 'float32' was looked up, for deciding the values of 'numberOfBits' and 'dataType'

Then it basically worked, still i am not satisfied because of two reasons: inflating data and the possible risk of corrupting the whole file just for changing or writing one metadata to it.

I don't know if you want to fix this, we considered not to use write3, so there is no demand from us for you to fix it in mdfreader for this might be a too special case...

skidzo commented 6 years ago

and interesting, the file i read contains additionally in file_metadata the keys: 'comment', 'time' and 'date', If I read the write3 function it only writes 'author', 'organisation', 'project' and 'subject' from file_metadata, is that correct?

ratal commented 6 years ago

Probably the following is more correct:

if PythonVersion >= 3:
          if data.dtype.kind == 'S':
temp = ncode(temp, encoding='latin1', errors='replace')
         elif data.dtype.kind == 'U':
temp = ncode(temp, encoding='utf-8', errors='replace')

This is all about text coding, so I do not this the relation with floating type.

Regarding the organisation, project subject, etc. these are by default values put in general comments by Inca. I guess your 'comment', 'time' and 'date' are also specific to your data logger, which is ? You can modify for your own needs the method add_metadata that is in mdf.py

By the way, any modification you do can be proposed by a pull request if you want it in mdfreader

skidzo commented 6 years ago

i made a quick test and can confirm that this is more correct. I am aware of the add_metadata method. Our file was produced with CANape I checked with MDF Versions 3.2 and 3.3

ratal commented 6 years ago

Date, Time, Author, Organization, Project, Subject are fields of HDBlock in mdf3.x. It contains also a link to a TXBlock containing comment. For Inca, Project, Organization, etc. are actually not in the HD Fields (fixed size) but in the TXBlock Comment text (variable size). Is your issue solved ? If yes close, otherwise please explain what you expect at this point.