ratal / mdfreader

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

mf4 file index error #179

Closed pr0ximo closed 4 years ago

pr0ximo commented 4 years ago

Python version

3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

Platform information

Anaconda

Numpy version

version 1.16.5

mdfreader version

version 3.3

Description

import mdfreader a = mdfreader.Mdf('myfile.mf4')

output:

IndexError Traceback (most recent call last)

in ----> 1 a = mdfreader.Mdf('myfile.mf4', metadata=2) C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdf.py in __init__(self, file_name, channel_list, convert_after_read, filter_channel_names, no_data_loading, compression, convert_tables, metadata) 158 no_data_loading=no_data_loading, 159 compression=compression, --> 160 metadata=metadata) 161 162 def add_channel(self, channel_name, data, master_channel, master_type=1, unit='', description='', conversion=None, C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdfreader.py in read(self, file_name, multi_processed, channel_list, convert_after_read, filter_channel_names, no_data_loading, compression, metadata) 411 if not no_data_loading: 412 self.read4(self.fileName, None, multi_processed, channel_list, --> 413 convert_after_read, compression, metadata) 414 else: # populate minimum mdf structure 415 self._noDataLoading = True C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdf4reader.py in read4(self, file_name, info, multi_processed, channel_list, convert_after_read, compression, metadata) 1239 if info is None: 1240 if self.info is None: -> 1241 info = Info4(self.fileName, None, minimal=minimal) 1242 else: 1243 info = self.info C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdfinfo4.py in __init__(self, file_name, fid, minimal) 1558 (self.fid, self.fileName, self.zipfile) = _open_mdf(self.fileName) 1559 if self.fileName is not None and fid is None: -> 1560 self.read_info(self.fid, minimal) 1561 # Close the file 1562 self.fid.close() C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdfinfo4.py in read_info(self, fid, minimal) 1581 1582 # reads Header HDBlock -> 1583 self['HD'].update(HDBlock(fid)) 1584 1585 # reads File History blocks, always exists C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdfinfo4.py in __init__(self, fid) 228 def __init__(self, fid=None): 229 if fid is not None: --> 230 self.read(fid) 231 232 def read(self, fid=None): C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdfinfo4.py in read(self, fid) 254 self['Comment'] = {} 255 comment = CommentBlock() --> 256 comment.read_cm_hd(fid=fid, pointer=self['hd_md_comment']) 257 self['Comment'].update(comment) 258 C:\ProgramData\Anaconda3\lib\site-packages\mdfreader\mdfinfo4.py in read_cm_hd(self, fid, pointer) 435 tmp = xml_tree.common_properties 436 for t in range(tmp.countchildren()): --> 437 self[tmp.e[t].attrib.values()[0]] = tmp.e[t].text 438 except AttributeError: 439 pass # optional src/lxml/objectify.pyx in lxml.objectify.ObjectifiedElement.__getitem__() IndexError: 8
ratal commented 4 years ago

Hi Temporarily, you could add IndexError to the following exception to understand what is wrong or be able to read the file. Using MDFValidator (free from Vector), can you have a look and send the content of HD Block comment ? I guess it is not following the standard schema or is empty.

ratal commented 4 years ago

You coulf also try to replace by this more modern script:

for t in tmp.e:
      self[t.attrib.values()[0]] = t.text