From 28a5d5592ba7e97202f29718042b2d8a6932ec8a Mon Sep 17 00:00:00 2001 From: "aymeric.rateau@gmail.com" Date: Fri, 9 May 2014 20:52:46 +0000 Subject: [PATCH] Correct bug if channelist is given, can now run mdfconverter --- mdf4reader.py | 36 +++++++++++++++++++----------------- mdfreader.py | 7 +++++-- mdfreaderui.py | 2 +- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/mdf4reader.py b/mdf4reader.py index 080df6d..bd2f29e 100644 --- a/mdf4reader.py +++ b/mdf4reader.py @@ -33,19 +33,19 @@ def __init__(self, fid, pointer, numpyDataRecordFormat, numberOfRecords , dataR # block header self.loadHeader(fid, pointer) if self['id'] in ('##DT', '##RD', b'##DT', b'##RD'): # normal data block - if channelList==None: # reads all blocks - self['data']=numpy.core.records.fromfile( fid, dtype = numpyDataRecordFormat, shape = numberOfRecords , names=dataRecordName) - else: # channelList defined - # reads only the channels using offset functions, channel by channel - buf={} - # order offsets and names based on offset value - channelList=OrderedDict(sorted(channelList.items(), key=lambda t: t[1])) - for record in range(numberOfRecords): - for name in dataRecordName: - if name in channelList.keys(): - fid.seek() - buf.append(numpy.core.records.fromfile( fid, dtype = numpyDataRecordFormat, shape = 1 , names=name, offset=None )) - self['data']=buf +# if channelList==None: # reads all blocks + self['data']=numpy.core.records.fromfile( fid, dtype = numpyDataRecordFormat, shape = numberOfRecords , names=dataRecordName) +# else: # channelList defined +# # reads only the channels using offset functions, channel by channel +# buf={} +# # order offsets and names based on offset value +# channelList=OrderedDict(sorted(channelList.items(), key=lambda t: t[1])) +# for record in range(numberOfRecords): +# for name in dataRecordName: +# if name in channelList.keys(): +# fid.seek() +# buf.append(numpy.core.records.fromfile( fid, dtype = numpyDataRecordFormat, shape = 1 , names=name, offset=None )) +# self['data']=buf elif self['id'] in ('##SD', b'##SD'): # Signal Data Block unpack('uint32', fid.read(4)) # length of data @@ -211,7 +211,7 @@ def read4( self, fileName=None, info = None, multiProc = False, channelList=None if info['CGBlock'][dataGroup][channelGroup]['cg_cn_first']==0 or info['CGBlock'][dataGroup][channelGroup]['cg_flags']&1: print('VLSD ChannelGroup, not really implemented yet') numberOfRecords=info['CGBlock'][dataGroup][channelGroup]['cg_cycle_count'] - channelListByte=[] + #channelListByte=[] #dataBytes=info['CGBlock'][dataGroup][channelGroup]['cg_dataBytes'] #invalidBytes=info['CGBlock'][dataGroup][channelGroup]['cg_invalid_bytes'] #invalidBit=info['CGBlock'][dataGroup][channelGroup]['cg_invalid_bit_pos'] @@ -220,13 +220,13 @@ def read4( self, fileName=None, info = None, multiProc = False, channelList=None signalDataType = info['CNBlock'][dataGroup][channelGroup][channel]['cn_data_type'] # Corresponding number of bits for this format numberOfBits = info['CNBlock'][dataGroup][channelGroup][channel]['cn_bit_count'] - channelByteOffset= info['CNBlock'][dataGroup][channelGroup][channel]['cn_byte_offset']+info['DGBlock'][dataGroup]['dg_rec_id_size'] + #channelByteOffset= info['CNBlock'][dataGroup][channelGroup][channel]['cn_byte_offset']+info['DGBlock'][dataGroup]['dg_rec_id_size'] channelName=info['CNBlock'][dataGroup][channelGroup][channel]['name'] # is it a master channel for the group if info['CNBlock'][dataGroup][channelGroup][channel]['cn_type'] in (2, 3, 4): # master channel masterDataGroup[dataGroup]=channelName - if channelList is not None: - channelListByte[channelName]=channelByteOffset + #if channelList is not None: + # channelListByte[channelName]=channelByteOffset if numberOfBits < 8: # adding bit format, ubit1 or ubit2 if precedingNumberOfBits == 8: # 8 bit make a byte @@ -273,6 +273,8 @@ def read4( self, fileName=None, info = None, multiProc = False, channelList=None self.masterChannelList[masterDataGroup[dataGroup]].append(channelName) self[channelName] = {} self[channelName]['master'] = masterDataGroup[dataGroup] + # sync_types : 0 data, 1 time (sec), 2 angle (radians), 4 index + self[channelName]['masterType'] = info['CNBlock'][dataGroup][channelGroup][channel]['cn_sync_type'] if 'unit' in list(info['CCBlock'][dataGroup][channelGroup][channel].keys()): self[channelName]['unit'] = info['CCBlock'][dataGroup][channelGroup][channel]['unit'] elif 'unit' in list(info['CNBlock'][dataGroup][channelGroup][channel].keys()): diff --git a/mdfreader.py b/mdfreader.py index e8126d9..a1d1b0b 100644 --- a/mdfreader.py +++ b/mdfreader.py @@ -254,15 +254,18 @@ def resample( self, samplingTime = 0.1, masterChannelName=None ): masterChannelName='master' self[masterChannelName] = {} unit = '' + masterType = 1 # time by default for master in list(self.masterChannelList.keys()): if master in self and len( self[master]['data'] ) > 5: # consider groups having minimum size minTime.append( self[master]['data'][0] ) maxTime.append( self[master]['data'][len( self[master]['data'] ) - 1] ) - if self[master]['unit'] != '': + if len(self[master]['unit'])>1 : unit = self[master]['unit'] + masterType = self[master]['masterType'] self[masterChannelName]['data'] = numpy.arange( min( minTime ),max( maxTime ),samplingTime ) self[masterChannelName]['unit'] = unit self[masterChannelName]['description'] = 'Unique master channel' + self[masterChannelName]['masterType'] = masterType # Interpolate channels timevect=[] @@ -283,7 +286,7 @@ def resample( self, samplingTime = 0.1, masterChannelName=None ): for ind in list(self.masterChannelList.keys()): del self[ind] self.masterChannelList = {} # empty dict - self.masterChannelList[masterChannelName] = list(self.keys()) + self.masterChannelList[masterChannelName] = list(self.keys()) else: pass diff --git a/mdfreaderui.py b/mdfreaderui.py index 2e9871e..f3edd37 100644 --- a/mdfreaderui.py +++ b/mdfreaderui.py @@ -15,7 +15,7 @@ from os import path PythonVersion=version_info PythonVersion=PythonVersion[0] -MultiProc=True # multiprocess switch, for debug purpose +MultiProc=True # multiprocess switch, for debug purpose put False class MainWindow(QMainWindow, Ui_MainWindow, QFileDialog): """