Skip to content

Commit

Permalink
Some more styling improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
ratal committed Apr 9, 2015
1 parent 985ea89 commit 3da3936
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 200 deletions.
5 changes: 3 additions & 2 deletions Ui_mdfreaderui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
except AttributeError:
_fromUtf8 = lambda s: s


class Ui_MainWindow(object):

def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 653)
Expand Down Expand Up @@ -146,7 +148,7 @@ def setupUi(self, MainWindow):
self.Resample.addWidget(self.resample)
self.resampleValue = QtGui.QLineEdit(self.horizontalLayoutWidget)
self.resampleValue.setEnabled(True)
self.resampleValue.setInputMethodHints(QtCore.Qt.ImhFormattedNumbersOnly|QtCore.Qt.ImhPreferNumbers)
self.resampleValue.setInputMethodHints(QtCore.Qt.ImhFormattedNumbersOnly | QtCore.Qt.ImhPreferNumbers)
self.resampleValue.setObjectName(_fromUtf8("resampleValue"))
self.Resample.addWidget(self.resampleValue)
self.layoutWidget = QtGui.QWidget(self.splitter)
Expand Down Expand Up @@ -223,4 +225,3 @@ def retranslateUi(self, MainWindow):
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

6 changes: 3 additions & 3 deletions mdf3reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,12 +1121,12 @@ def writePointer(f, pointer, value):
else:
raise Exception('Not recognized dtype')
return data.dtype
if not data.dtype.kind in ['S', 'U']:
if data.dtype.kind not in ['S', 'U']:
dataTypeList += data.dtype.char
else:
dataTypeList += str(data.dtype.itemsize) + 's'
fid.write(pack(UINT16, dataType)) # Signal data type
if not data.dtype.kind in ['S', 'U']:
if data.dtype.kind not in ['S', 'U']:
fid.write(pack(BOOL, 1)) # Value range valid
if len(data) > 0:
maximum = max(data)
Expand Down Expand Up @@ -1156,7 +1156,7 @@ def writePointer(f, pointer, value):
writePointer(fid, pointers['CN'][dataGroup][channel]['CC'], fid.tell())
writeChar(fid, 'CC')
fid.write(pack(UINT16, 46)) # CC block size
if not data.dtype.kind in ['S', 'U']:
if data.dtype.kind not in ['S', 'U']:
fid.write(pack(BOOL, 1)) # Value range valid
fid.write(pack(REAL, minimum)) # Min value
fid.write(pack(REAL, maximum)) # Max value
Expand Down
48 changes: 25 additions & 23 deletions mdfForVeuszPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import os
import os.path
sys.path.append(os.getcwdu())
print( os.path.join( os.getcwdu(), 'plugins' ) )
print(os.path.join(os.getcwdu(), 'plugins'))
from mdfreader import mdf
from mdfreader import mdfinfo


class ImportPlugin( mdfinfo ):
class ImportPlugin(mdfinfo):

"""Define a plugin to read data in a particular format.
Expand All @@ -47,40 +47,40 @@ class ImportPlugin( mdfinfo ):
promote_tab = 'MDF'
file_extensions = set(['.dat', '.mf4', '.mdf'])

def __init__( self ):
def __init__(self):
"""Override this to declare a list of input fields if required."""
# a list of ImportField objects to display
self.fields = []

def getPreview( self, params ):
def getPreview(self, params):
"""Get data to show in a text box to show a preview.
params is a ImportPluginParams object.
Returns (text, okaytoimport)
"""
info = mdfinfo( fileName=params.filename )

info = mdfinfo(fileName=params.filename)

if info.mdfversion < 400:
f = ''
f += 'Time: ' + info['HDBlock']['Date'] + ' '
f += info['HDBlock']['Time'] + '\n'
f += 'Author: ' + info['HDBlock']['Author'] + '\n'
f += 'Organisation: ' + info['HDBlock']['Organization' ] + '\n'
f += 'Organisation: ' + info['HDBlock']['Organization'] + '\n'
f += 'Project Name: ' + info['HDBlock']['ProjectName'] + '\n'
f += 'Subject: ' + info['HDBlock']['Subject'] + '\n' + 'Channel List:\n'
else:
from time import gmtime, strftime
fileDateTime = gmtime(info['HDBlock']['hd_start_time_ns']/1000000000)
date=strftime('%Y-%m-%d', fileDateTime)
time=strftime('%H:%M:%S', fileDateTime)
fileDateTime = gmtime(info['HDBlock']['hd_start_time_ns'] / 1000000000)
date = strftime('%Y-%m-%d', fileDateTime)
time = strftime('%H:%M:%S', fileDateTime)
f = ''
f += 'Date Time: ' + date + ' ' + time + '\n'
if 'Comment' in info['HDBlock']:
Comment = info['HDBlock']['Comment']
if 'author' in Comment:
f += 'Author: ' + Comment['author'] + '\n'
if 'department' in Comment:
f += 'Organisation: ' + Comment['department' ] + '\n'
f += 'Organisation: ' + Comment['department'] + '\n'
if 'project' in Comment:
f += 'Project Name: ' + Comment['project'] + '\n'
if 'subject' in Comment:
Expand All @@ -89,37 +89,39 @@ def getPreview( self, params ):
f += ' ' + channelName + '\n'
return f, True

def doImport( self, params ):
def doImport(self, params):
"""Actually import data
params is a ImportPluginParams object.
Return a list of ImportDataset1D, ImportDataset2D objects
"""
return []

class MdfImportPlugin( ImportPlugin, mdf ):

class MdfImportPlugin(ImportPlugin, mdf):

"""Plugin to import mdf (Mostly ETAS INCA or CANape files)"""

name = "MDFImport plugin"
author = "Aymeric Rateau"
description = "Reads MDF files from INCA or CANAPE"

def __init__( self ):
ImportPlugin.__init__( self )
self.fields = [ImportFieldFloat( "mult", descr="Sampling", default=0.1 )]
def __init__(self):
ImportPlugin.__init__(self)
self.fields = [ImportFieldFloat("mult", descr="Sampling", default=0.1)]

def doImport( self, params ):
def doImport(self, params):
"""Actually import data
params is a ImportPluginParams object.
Return a list of ImportDataset1D, ImportDataset2D objects
"""

data = mdf( params.filename )
data.resample( samplingTime=params.field_results['mult'] )
data = mdf(params.filename)
data.resample(samplingTime=params.field_results['mult'])
List = []
for channelName in list(data.keys()):
if len( data[channelName]['data'] ) > 0 and not data[channelName]['data'].dtype.kind in ['S', 'U']:
if len(data[channelName]['data']) > 0 and not data[channelName]['data'].dtype.kind in ['S', 'U']:
# print( data[channelName]['data'].dtype )
List.append( ImportDataset1D( channelName, data[channelName]['data'] ) )
List.append(ImportDataset1D(channelName, data[channelName]['data']))
return List

importpluginregistry.append( MdfImportPlugin() )
importpluginregistry.append(MdfImportPlugin())
4 changes: 2 additions & 2 deletions mdfinfo3.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def listChannels3(self, fileName=None):
list of channel names
"""
# Read MDF file and extract its complete structure
if not fileName is None:
if fileName is not None:
self.fileName = fileName
# Open file
fid = open(self.fileName, 'rb')
Expand Down Expand Up @@ -592,7 +592,7 @@ def mdfblockread3(blockFormat, fid, pointer, removeTrailing0=True):
Block content in a dict
"""
Block = {}
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
# Extract parameters
for field in range(len(blockFormat)):
Expand Down
22 changes: 11 additions & 11 deletions mdfinfo4.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ class CCBlock(MDFBlock):

def __init__(self, fid, pointer):
# block header
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
self['id'] = self.mdfblockreadCHAR(fid, 4)
self['reserved'] = self.mdfblockreadBYTE(fid, 4)
Expand Down Expand Up @@ -539,7 +539,7 @@ class CABlock(MDFBlock):

def __init__(self, fid, pointer):
# block header
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
self['id'] = self.mdfblockreadCHAR(fid, 4)
self['reserved'] = self.mdfblockreadBYTE(fid, 4)
Expand Down Expand Up @@ -596,7 +596,7 @@ class ATBlock(MDFBlock):

def __init__(self, fid, pointer):
# block header
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
self['id'] = self.mdfblockreadCHAR(fid, 4)
self['reserved'] = self.mdfblockreadBYTE(fid, 4)
Expand Down Expand Up @@ -627,7 +627,7 @@ class EVBlock(MDFBlock):

def __init__(self, fid, pointer):
# block header
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
self['id'] = self.mdfblockreadCHAR(fid, 4)
self['reserved'] = self.mdfblockreadBYTE(fid, 4)
Expand Down Expand Up @@ -682,7 +682,7 @@ class SRBlock(MDFBlock):

def __init__(self, fid, pointer):
# block header
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
self['id'] = self.mdfblockreadCHAR(fid, 4)
self['reserved'] = self.mdfblockreadBYTE(fid, 4)
Expand All @@ -706,7 +706,7 @@ class SIBlock(MDFBlock):

def __init__(self, fid, pointer):
# block header
if pointer != 0 and not pointer is None:
if pointer != 0 and pointer is not None:
fid.seek(pointer)
self['id'] = self.mdfblockreadCHAR(fid, 4)
self['reserved'] = self.mdfblockreadBYTE(fid, 4)
Expand Down Expand Up @@ -956,10 +956,10 @@ def readCGBlock(self, fid, dg, channelNameList=False):
self['VLSD_CG'][self['CGBlock'][dg][VLSDcg]['cg_record_id']] = temp
break

# reorder channel blocks and related blocks(CC, SI, AT, CA) based on byte offset
# this reorder is meant to improve performance while parsing records using core.records.fromfile
# as it will not use cn_byte_offset
# first, calculate new mapping/order
# reorder channel blocks and related blocks(CC, SI, AT, CA) based on byte offset
# this reorder is meant to improve performance while parsing records using core.records.fromfile
# as it will not use cn_byte_offset
# first, calculate new mapping/order
nChannel = len(self['CNBlock'][dg][cg])
Map = zeros(shape=len(self['CNBlock'][dg][cg]), dtype=[('index', 'u4'), ('byte_offset', 'u4')])
for cn in range(nChannel):
Expand Down Expand Up @@ -1186,7 +1186,7 @@ def listChannels4(self, fileName=None):
-----------
list of channel names contained in file
"""
if not fileName is None:
if fileName is not None:
self.fileName = fileName
# Open file
fid = open(self.fileName, 'rb')
Expand Down
77 changes: 75 additions & 2 deletions mdfreader.e4p
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-5.1.dtd">
<!-- eric project file for project mdfreader -->
<!-- Saved: 2015-03-31, 23:46:16 -->
<!-- Saved: 2015-04-10, 01:02:36 -->
<!-- Copyright (C) 2015 Aymeric Rateau, aymeric.rateau@gmail.com -->
<Project version="5.1">
<Language>en</Language>
Expand Down Expand Up @@ -40,7 +40,7 @@
</Others>
<MainScript>mdfconverter.py</MainScript>
<Vcs>
<VcsType>None</VcsType>
<VcsType>Git</VcsType>
<VcsOptions>
<dict>
<key>
Expand Down Expand Up @@ -363,6 +363,79 @@
</value>
</dict>
</value>
<key>
<string>Pep8Checker</string>
</key>
<value>
<dict>
<key>
<string>DocstringType</string>
</key>
<value>
<string>pep257</string>
</value>
<key>
<string>ExcludeFiles</string>
</key>
<value>
<string></string>
</value>
<key>
<string>ExcludeMessages</string>
</key>
<value>
<string>E123,E226,E24,E501</string>
</value>
<key>
<string>FixCodes</string>
</key>
<value>
<string></string>
</value>
<key>
<string>FixIssues</string>
</key>
<value>
<bool>False</bool>
</value>
<key>
<string>HangClosing</string>
</key>
<value>
<bool>False</bool>
</value>
<key>
<string>IncludeMessages</string>
</key>
<value>
<string></string>
</value>
<key>
<string>MaxLineLength</string>
</key>
<value>
<int>79</int>
</value>
<key>
<string>NoFixCodes</string>
</key>
<value>
<string>E501</string>
</value>
<key>
<string>RepeatMessages</string>
</key>
<value>
<bool>False</bool>
</value>
<key>
<string>ShowIgnored</string>
</key>
<value>
<bool>False</bool>
</value>
</dict>
</value>
</dict>
</CheckersParams>
</Checkers>
Expand Down
Loading

0 comments on commit 3da3936

Please sign in to comment.