Skip to content

Commit

Permalink
mdf4reader : added basic functionnality to read channel array. Solved…
Browse files Browse the repository at this point in the history
… bug related to formula conversion in python3
  • Loading branch information
aymeric.rateau@gmail.com committed Feb 19, 2015
1 parent 93ff26f commit 6fd6751
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mdf3reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def formulaConv(data, conv): # 10 Text Formula
formula = conv['textFormula']
formula=formula[:formula.find('\x00')] # remove trailing text after 0
formula = formula.replace('pow(', 'power(') # adapt ASAM-MCD2 syntax to sympy
expr = lambdify(X,formula , 'numpy') # formula to function for evaluation
expr = lambdify(X,formula , modules='numpy', dummify=False) # formula to function for evaluation
return expr(data)
except:
print('Please install sympy to convert channel ')
Expand Down
29 changes: 20 additions & 9 deletions mdf4reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,18 @@ def __init__(self, info, dataGroup, channelGroup, channelNumber, recordIDsize):
self.channelNumber=channelNumber
self.signalDataType = info['CNBlock'][dataGroup][channelGroup][channelNumber]['cn_data_type']
self.bitCount = info['CNBlock'][dataGroup][channelGroup][channelNumber]['cn_bit_count']
if info['CNBlock'][dataGroup][channelGroup][channelNumber]['cn_composition']: # channel array
self.dataFormat=arrayformat4( self.signalDataType, self.bitCount )
self.CABlock=info['CNBlock'][dataGroup][channelGroup][channelNumber]['CABlock']
array_desc = '('
for i in self.CABlock['ca_dim_size']:
array_desc += str(self.CABlock['ca_dim_size'][i][0])+','
array_desc = array_desc[:-1] + ')' # remove trailing comma
#self.bitCount = self.bitCount*self.CABlock['PNd']
self.dataFormat = array_desc + self.dataFormat
else:
self.dataFormat=arrayformat4( self.signalDataType, self.bitCount )
self.channelType = info['CNBlock'][dataGroup][channelGroup][channelNumber]['cn_type']
self.dataFormat=arrayformat4( self.signalDataType, self.bitCount )
if self.channelType in (1, 4, 5): # if VSLD or sync or max length channel
self.data=info['CNBlock'][dataGroup][channelGroup][channelNumber]['cn_data']
if self.channelType==1: # if VSLD
Expand All @@ -492,9 +502,9 @@ def __init__(self, info, dataGroup, channelGroup, channelNumber, recordIDsize):
self.name+=str(dataGroup)
self.RecordFormat=((self.name, convertName(self.name)), self.dataFormat)
if not self.signalDataType in (13, 14): # processed by several channels
if not self.channelType==1: # if VSLD
if not self.channelType==1: # if not VSLD
self.Format=datatypeformat4( self.signalDataType, self.bitCount )
else:
else: # VLSD
self.Format=datatypeformat4( 0, self.bitCount )
self.CFormat=Struct(self.Format)
if self.bitCount%8==0:
Expand Down Expand Up @@ -1337,14 +1347,15 @@ def processDataBlocks4( Q, buf, info, dataGroup, channelList, multiProc ):
# channel array processing
if 'CABlock' in info['CNBlock'][dataGroup][channelGroup][channel]:
if info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_ndim']==1:
Dims=info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_dim_size']
#Dims=info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_dim_size']
pass
elif info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_ndim']>1:
ca_dim_size=info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_dim_size']
Dims=[ca_dim_size[i][0] for i in ca_dim_size]
#ca_dim_size=info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_dim_size']
#Dims=[ca_dim_size[i][0] for i in ca_dim_size]
pass
if info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_type']==0: # simple array, no axis/outpout
print('resizing array', Dims, len(L[channelName]))
if info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_ndim']>1:
L[channelName]=L[channelName].reshape(Dims)
pass
elif info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_type']==1: # scaling axis, 1D
pass
elif info['CNBlock'][dataGroup][channelGroup][channel]['CABlock']['ca_type']==2: # look-up
Expand Down Expand Up @@ -1477,7 +1488,7 @@ def formulaConv(vect, formula):
except:
print('Please install sympy to convert channel ')
X=symbols('X')
expr=lambdify(X, formula, 'numpy')
expr=lambdify(X, formula, modules='numpy', dummify=False)
return expr(vect)

def valueToValueTableWOInterpConv(vect, cc_val):
Expand Down
18 changes: 9 additions & 9 deletions mdfinfo4.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,23 +522,23 @@ def __init__(self, fid, pointer):
self['ca_invalid_bit_pos_base']=self.mdfblockread(fid, UINT32, 1)
self['ca_dim_size']=self.mdfblockread(fid, UINT64, self['ca_ndim'])
try: # more than one dimension, processing dict
SNd=0
PNd=1
self['SNd']=0
self['PNd']=1
for x in self['ca_dim_size']:
SNd+=self['ca_dim_size'][x][0]
PNd*=self['ca_dim_size'][x][0]
self['SNd']+=self['ca_dim_size'][x][0]
self['PNd']*=self['ca_dim_size'][x][0]
except: # only one dimension, processing int
SNd=self['ca_dim_size']
PNd=SNd
self['SNd']=self['ca_dim_size']
self['PNd']=self['SNd']
if 1<<5 & self['ca_flags']: # bit5
self['ca_axis_value']=self.mdfblockread(fid, REAL, SNd)
self['ca_axis_value']=self.mdfblockread(fid, REAL, self['SNd'])
if self['ca_storage']>=1:
self['ca_cycle_count']=self.mdfblockread(fid, UINT64, PNd)
self['ca_cycle_count']=self.mdfblockread(fid, UINT64, self['PNd'])
# Channel Conversion block : Links
fid.seek( pointer +24 )
self['ca_composition']=self.mdfblockread(fid, LINK, 1) # point to CN for array of structures or CA for array of array
if self['ca_storage']==2:
self['ca_data']=self.mdfblockread(fid, LINK, PNd)
self['ca_data']=self.mdfblockread(fid, LINK, self['PNd'])
if 1<<0 &self['ca_flags']: # bit 0
self['ca_dynamic_size']=self.mdfblockread(fid, LINK, self['ca_ndim']*3)
if 1<<1 &self['ca_flags']: # bit 1
Expand Down

0 comments on commit 6fd6751

Please sign in to comment.