Closed fizcris closed 6 years ago
Hello Cristian,
this info is stored as XML in the header's comment. Please try the latest development code and see if it works. You should access the author, department, project and subject attributes of the header object.
I am testing it with a file stacked from a v3.0 and v4.1 with output v4.10 and it is not working. I cannont access the set of atributes of the header object, neither they are being represented in the header dictionary.
Kind regards.
This works for me
from asammdf import MDF, Signal
s = Signal(
samples=[],
timestamps=[],
name='s1',
)
mdf = MDF(version='4.10')
mdf.append([s])
mdf.header.author = 'me'
mdf.header.project = 'asammdf'
mdf.header.department = 'python'
mdf.save('test_header.mf4', overwrite=True)
For me it works partially, as you can see the metadata it is not shown on the CANApe side window but it appears when you try to delete the file. The metadata is in the file, so probably extra fields needs to be modified.
As a suggestion, it also would be benefitial to appear in the header dictionary as individual properties.
I can see the proper info in CANape (right clcik the loaded files on the left side and select properties)
I would like the key-value pairs to be exactly the block fields, and have related things as attibutes.
Now I am experiencing that the comment is not being stored into the measurement:
outputFile.file_comment = ' This is my comment
Hello Cristian,
there were some problems indeed. I've fixed them and it appear to work correctly now.
The proper way to change the comment is
outfile.header.comment = 'my new comment'
Sorry but after using the line posted above I am getting the following error:
outputFile.header.comment = ' my comment'
outputFile.save(dst='test.mf4', overwrite=True,compression=2)
AttributeError Traceback (most recent call last)
in () ----> 1 outputFile.save(dst=fileOutFullName, overwrite=True,compression=2) C:\ProgramData\Anaconda3\lib\site-packages\asammdf-3.5.1.dev0-py3.6.egg\asammdf\mdf_v4.py in save(self, dst, overwrite, compression) 5538 dst, 5539 overwrite, -> 5540 compression, 5541 ) 5542
C:\ProgramData\Anaconda3\lib\site-packages\asammdf-3.5.1.dev0-py3.6.egg\asammdf\mdf_v4.py in _save_with_metadata(self, dst, overwrite, compression) 5625 5626 write(bytes(self.identification)) -> 5627 self.header.tostream(dst) 5628 5629 dst_.flush()
C:\ProgramData\Anaconda3\lib\site-packages\asammdf-3.5.1.dev0-py3.6.egg\asammdf\v4_blocks.py in to_stream(self, stream) 3920 def to_stream(self, stream): 3921 address = stream.tell() -> 3922 if self.comment.startswith('<HDcomment'): 3923 comment = self.comment.replace(' xmlns="http://www.asam.net/mdf/v4"', '') 3924 comment = ET.fromstring(comment)
AttributeError: 'dict' object has no attribute 'startswith'
Are you sure you are assigning a string to the comment attribute? It looks like it had been assigned with a dict or possibly a TextBlock object.
Sorry my bad. I forgot to stringify a JSON doc object.
Python version
Please run the following snippet and write the output here
Code
MDF version
'asammdf=4.0.0.dev'
Description
Cannot find a way to modify the header properties (Author, Organisation, Project, Subject) of MDF V4.1 files (picture attached). Because target properties are not in the header as in MDF V3 files.
Extract from v3 file header:
Extract from v4.1 file header: