コード例 #1
0
ファイル: PX_Signals.py プロジェクト: shuailing1/PyLinX
    def __init__(self, parent, path):
        
        try:
            dataObject = mdflib.mdf(path)
            fileType = PX_Signals.fileType.mdf
             
        
        except Exception as exc:
            
            try:
                dataObject = csvlib.CSVObject(path).data()
                fileType = PX_Signals.fileType.csv
            
            except Exception as exc2:
            
                strExp = str(exc)
                strExp2 = str(exc2)
                strText = u"Unable to open file - " + strExp + " - " + strExp2  
                helper.error(strText)
                return

        name = u"Signal"
        super(PX_Signals, self).__init__(parent, name, bIdSuffix = True, headObject = dataObject)
        self.set("fileType", fileType)
        
        self._BContainer__Attributes[u"pathMdfFile"] = path
        listVirtualAttributes = [u"signals", u"signalsFullData"]
        for key in self._BContainer__Head:
            listVirtualAttributes.append(key)
        self._BContainer__AttributesVirtual.extend(listVirtualAttributes)
コード例 #2
0
ファイル: mdfreaderui5.py プロジェクト: waltherg/mdfreader
def processMDF(fileName, channelist, resampleFlag, resampleValue, convertFlag, convertSelection):
    # Will process file according to defined options
    yop = mdfreader.mdf()
    yop.multiProc = False  # already multiprocessed
    yop.convertAfterRead = True
    yop.read(fileName)  # reads complete file
    yop.keepChannels(channelist)  # removes unnecessary channels
    if resampleFlag:
        yop.resample(resampleValue)
    if convertFlag:
        if convertSelection == 'Matlab':
            yop.exportToMatlab()
        elif convertSelection == 'csv':
            yop.exportToCSV()
        elif convertSelection == 'netcdf':
            yop.exportToNetCDF()
        elif convertSelection == 'hdf5':
            yop.exportToHDF5()
        elif convertSelection == 'excel':
            yop.exportToExcel()
        elif convertSelection == 'excel2010':
            yop.exportToXlsx()
        elif convertSelection == 'mdf3':
            yop.write(fileName + '_new')
    yopPicklable = {}  # picklable dict and not object
    for channel in list(yop.keys()):
        yopPicklable[channel] = yop[channel]
    return [yopPicklable, yop.masterChannelList, yop.fileName]
コード例 #3
0
ファイル: functions_PMM_new.py プロジェクト: mrkure/281020182
def read_mdf_data(file):
    data_file  = mdfreader.mdf(file,noDataLoading=False)
    info       = mdfreader.mdfinfo()    
    channels   = info.listChannels(file)

    dictionary = {}
    [dictionary.update({channel:data_file.getChannel(channel)}) for channel in channels]
        
    X20_validBMP_rate_last60s = round(dictionary['X20_validBMP_rate_last60s']['data'][-1],1)
    X21_validMSP_rate_last60s = round(dictionary['X21_validMSP_rate_last60s']['data'][-1],1)
    
    X56_pMess_avg60s          = round(dictionary['X56_pMess_avg60s']['data'][-1],1)
    X86_pIndi_avg60s          = round(dictionary['X86_pIndi_avg60s']['data'][-1],1)
    X96_pDiff_avg60s          = round(dictionary['X96_pDiff_avg60s']['data'][-1],1)
    
    X66_pBMP_avg60s           = round(dictionary['X66_pBMP_avg60s']['data'][-1],1)
    X76_pMSP_avg60s           = round(dictionary['X76_pMSP_avg60s']['data'][-1],1)
    
    p_diff_MSP                = round(X76_pMSP_avg60s - X56_pMess_avg60s, 3)
    p_diff_BMP                = round(X66_pBMP_avg60s - X56_pMess_avg60s,3)
    
    valid_msp_rate_cor, ar        = calc_MSP_valid_cor(dictionary)
    valid_msp_rate_cor2, ar2      = calc_MSP_valid_cor2(dictionary)
    
    root_dir                  = file.split('\\')[-3]

    pressure                  = int(file.replace('\\', '_').split('.')[0].split('_')[-4])
    temperature               = int(file.replace('\\', '_').split('.')[0].split('_')[-3])
    voltage                   = int(file.replace('\\', '_').split('.')[0].split('_')[-2])
    sample                    = file.replace('\\', '_').split('.')[0].split('_')[-6]
    

    data_frame = pd.DataFrame([[sample, root_dir, pressure, temperature, voltage, X56_pMess_avg60s, X86_pIndi_avg60s, X96_pDiff_avg60s, p_diff_MSP, p_diff_BMP, X20_validBMP_rate_last60s, X21_validMSP_rate_last60s, valid_msp_rate_cor, valid_msp_rate_cor2 ]], \
                    columns = ['sample','root_dir','pressure','temperature', 'voltage', 'pMess',       'pIndi',        'pDiff',       'pDiff_MSP',  'pDiff_BMP', 'valid_BMP_rate',          'valid_MSP_rate', 'valid_msp_rate_cor', 'valid_msp_rate_cor2' ])
    return  data_frame
コード例 #4
0
ファイル: functions_PMM_new.py プロジェクト: mrkure/281020182
def read_mdf(path):
    data_file  = mdfreader.mdf(path,noDataLoading=False)
    info       = mdfreader.mdfinfo()
    channels   = info.listChannels(path) # returns only the list of channels    info=mdfreader.mdfinfo()   
    dictionary = {}
    [dictionary.update({channel:data_file.getChannel(channel)}) for channel in channels]
    return dictionary
コード例 #5
0
def parseMDF(filename):
    if(os.path.exists(filename)):
        mdf=mdfreader.mdf(filename,channelList=['Epm_nEng','InjCtl_qSetUnBal','Rail_pSetPoint'])
        mdf.convertToPandas(0.1)
        mdf['master_group'].to_csv(filename[:-4]+".csv")
        print("done!")
    else:
        print("Sorry, please check the filename. Usage: Python " +__file__ + " filename.mdf")
コード例 #6
0
    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'])
        List = []
        for channelName in list(data.keys()):
            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']))
        return List
コード例 #7
0
 def parseMDF(self,filename):
     if(os.path.exists(filename)):
         mdf=mdfreader.mdf(filename,channelList=['Epm_nEng','InjCtl_qSetUnBal'])
         mdf.convertToPandas(0.1)
         df=mdf['master_group']
         try:
             r=float(Fraction(self.ratio.text()))
             df['Epm_nEng']=df['Epm_nEng'].apply(lambda x : round(x/r))
             df.columns=['Speed','q']
             df.to_csv(filename+".csv",index = False)
             QMessageBox.information(self,'Finished.','OK.')
         except PermissionError:
             QMessageBox.warning(self,'Warning', 'The file is opened, please close it and try again.')
     else:
         QMessageBox.warning(self,'Warning','Cannot file the file you specified!') 
コード例 #8
0
ファイル: plotting.py プロジェクト: rafacpitta/Plotting-Tool
def read_files():

    filenames = []
    files = []

    for i in os.listdir('Files'):
        if i.endswith('.mdf') or i.endswith('.dat'):
            filenames.append(i)

    os.chdir('Files')
    for i in filenames:
        f = mdf.mdf(i)
        files.append(f)
    os.chdir('..')

    return files, filenames
コード例 #9
0
    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'])
        List = []
        for channelName in list(data.keys()):
            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']))
        return List
コード例 #10
0
def get_channels_summary(file, save=0):
    data_file = mdfreader.mdf(path, noDataLoading=False)
    info = mdfreader.mdfinfo()
    channels = info.listChannels(path)
    channels = info.listChannels(
        path)  # returns only the list of channels    info=mdfreader.mdfinfo()
    frames = []
    values = []
    keys = []
    dictionary = {}
    [
        dictionary.update({channel: data_file.getChannel(channel)})
        for channel in channels
    ]
    for dic in dictionary:
        inner = dictionary[dic]
        try:
            for x, y in inner.items():

                if y is None:
                    values.append('None')
                elif isinstance(y, str):
                    values.append(y)
                elif np.isscalar(y):
                    values.append(1)
                elif np.isscalar(y) == False:
                    values.append(len(y))
                else:
                    values.append(y)
                keys.append(x)

            frame = pd.DataFrame([values], columns=keys)
            frame = pd.DataFrame([[dic] + values], columns=['Variable'] + keys)

            frames.append(frame)
            keys = []
            values = []
        except:
            print(dic, ' failed')
    result_frame = pd.concat(frames, ignore_index=True)
    if save:
        file = file.split('.')[0] + '.xlsx'
        writer = pd.ExcelWriter(file, engine='xlsxwriter')
        result_frame.to_excel(writer, 'Sheet1', index=False)
        writer.save()
    return result_frame
コード例 #11
0
def read_files():
    import os
    import mdfreader as mdf

    filenames = []
    files = []

    for i in os.listdir('Files'):
        if i.endswith('.mdf'):
            filenames.append(i)

    os.chdir('Files')
    for i in filenames:
        f = mdf.mdf(i, convertAfterRead=False)
        files.append(f)
    os.chdir('..')

    return files, filenames
コード例 #12
0
ファイル: PX_ObjectHandler.py プロジェクト: shuailing1/PyLinX
 def __exit_mdf(self):        
     mdfObject = mdfreader.mdf()
     
     listVarsToSave = [u"time_1"]
     listVarsToSave.extend(self.__recorder_VariablesToRecordProcessed)
     for var in listVarsToSave :          
         mdfObject.add_channel(0, str(var),\
                    self.__dataDict[var][u"data"],\
                    master_channel   = str("time_1"), \
                    master_type      = self.__dataDict[var][u"masterType"],\
                    unit             = str(self.__dataDict[var][u"unit"]),\
                    description      = str(self.__dataDict[var][u"description"]),\
                    conversion       = None)
 
     dt = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
     filename = str(os.path.join(self.__recorder_SaveFolder,self.__recorder_BaseFileName + u"_" + dt + u".dat"))
     mdfObject.write(filename)        
     
コード例 #13
0
    def __exit_mdf(self):
        mdfObject = mdfreader.mdf()

        listVarsToSave = [u"time_1"]
        listVarsToSave.extend(self.__recorder_VariablesToRecordProcessed)
        for var in listVarsToSave:
            mdfObject.add_channel(0, str(var),\
                       self.__dataDict[var][u"data"],\
                       master_channel   = str("time_1"), \
                       master_type      = self.__dataDict[var][u"masterType"],\
                       unit             = str(self.__dataDict[var][u"unit"]),\
                       description      = str(self.__dataDict[var][u"description"]),\
                       conversion       = None)

        dt = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
        filename = str(
            os.path.join(self.__recorder_SaveFolder,
                         self.__recorder_BaseFileName + u"_" + dt + u".dat"))
        mdfObject.write(filename)
コード例 #14
0
ファイル: mdfreaderui5.py プロジェクト: waltherg/mdfreader
 def __init__(self, parent=None):
     """
     Constructor
     """
     QMainWindow.__init__(self, parent)
     self.setupUi(self)
     self.fileNames = []  # files to convert
     self.mdfClass = mdfreader.mdf()  # instance of mdf
     self.mdfinfoClass = mdfreader.mdfinfo()  # instance of mdfinfo
     self.convertSelection = 'Matlab'  # by default Matlab conversion is selected
     self.MergeFiles = False  # by default
     self.labFileName = []  # .lab file name
     self.defaultPath = None  # default path to open for browsing files
     self.actionPlotSelectedChannel = QAction("Plot", self.SelectedChannelList)  # context menu to allow plot of channel
     self.SelectedChannelList.addAction(self.actionPlotSelectedChannel)
     self.actionPlotSelectedChannel.triggered.connect(self.plotSelected)
     self.actionPlotChannel = QAction("Plot", self.channelList)  # context menu to allow plot of channel
     self.channelList.addAction(self.actionPlotChannel)
     self.actionPlotChannel.triggered.connect(self.plot)
     self.actionFileRemove = QAction("Delete", self.FileList)  # context menu to remove selected file from list
     self.FileList.addAction(self.actionFileRemove)
     self.actionFileRemove.triggered.connect(self.FileRemove)
コード例 #15
0
    def __init__(self, parent, path):
        
        dataObject = mdfreader.mdf(path)
        fileType = PX_Signals.fileType.mdf
        
#         try:
#             print "path", path
#             dataObject = mdfreader.mdf(path)
#             fileType = PX_Signals.fileType.mdf
#              
#         
#         except Exception as exc:
#             
#             try:
#                 dataObject = csvlib.CSVObject(path).data()
#                 fileType = PX_Signals.fileType.csv
#             
#             except Exception as exc2:
#             
#                 strExp = str(exc)
#                 strExp2 = str(exc2)
#                 strText = u"Unable to open file - " + strExp + " - " + strExp2  
#                 helper.error(strText)
#                 return

        name = u"Signal"
        super(PX_Signals, self).__init__(parent, name, bIdSuffix = True, headObject = dataObject)
        self.set("fileType", fileType)
        
        self._BContainer__Attributes[u"pathMdfFile"] = path
        for key in self._BContainer__Head:
            # Interesting Python-Syntax: Wrong:             
            # lambdaExpression = lambda key: self.get_signal(key)            
            lambdaExpression = lambda value = key: self.get_signal(value)  
            self._dictGetCallbacks.addCallback(key, lambdaExpression)
        self.__projectController = parent.getRoot(PyLinXCtl.PyLinXProjectController.PyLinXProjectController)      
        
        self.__projectController.mainWindow.emit(QtCore.SIGNAL(u"dataChanged__signals"))
コード例 #16
0
    def load(self, fname, resample = 0.00, cfilter = ['.*'], clist = None, 
             filterFunctionName=True, noDataLoading=True) :


        
        #if os.path.exists( fname ):
        self.filename = fname        
        self.filename = os.path.split(fname)[1],
        self.folder = os.path.split(fname)[0],
        self.date = time.strftime('%Y-%m-%d %H:%M:%S',
                                   time.localtime(os.path.getctime(fname)))

        try:
            self.__mdf__ = mdf( fname, cfilter, clist, noDataLoading=noDataLoading )
        except:
            import re
            with gzip.open(os.path.join(fname), 'rb') as pickle_file:
                self.__mdf__ = dill.load(pickle_file)
                keys_to_del = []
                for key in self.__mdf__.keys():
                    to_del = True
                    for kf in np.atleast_1d(cfilter):
                        if ((re.findall(kf, key) != []) or (key[:4] == 'time')):
                            to_del = False


                    if to_del:    
                        keys_to_del.append(key)

                for key in keys_to_del:
                    del self.__mdf__[key]


        if resample > 0.0:
            self.resample( resample )

        self._load(filterFunctionName)
コード例 #17
0
    def __init__(self, parent, path):

        try:
            dataObject = mdflib.mdf(path)
            fileType = PX_Signals.fileType.mdf

        except Exception as exc:

            try:
                dataObject = csvlib.CSVObject(path).data()
                fileType = PX_Signals.fileType.csv

            except Exception as exc2:

                strExp = str(exc)
                strExp2 = str(exc2)
                strText = u"Unable to open file - " + strExp + " - " + strExp2
                helper.error(strText)
                return

        name = u"Signal"
        super(PX_Signals, self).__init__(parent,
                                         name,
                                         bIdSuffix=True,
                                         headObject=dataObject)
        self.set("fileType", fileType)

        self._BContainer__Attributes[u"pathMdfFile"] = path
        for key in self._BContainer__Head:
            self._dictGetCallbacks.addCallback(key,
                                               lambda: self.get_signal(key))
        self.__projectController = parent.getRoot(
            PyLinXCtl.PyLinXProjectController.PyLinXProjectController)

        self.__projectController.mainWindow.emit(
            QtCore.SIGNAL(u"dataChanged_signals"))
コード例 #18
0
pedal = [0] * qtde
pvs = [0] * qtde
trend = [0] * qtde
a_trendstr = [0] * qtde
b_trendstr = [0] * qtde
y_trend = [0] * qtde
percentual = [0] * qtde
temp = 0
cnt = 0

pedal_str = 'PTC_PDL_PCT'
pvs_str = 'DELPVS'

for i in arquivos:
    pedal[cnt] = mdf.mdf(i, convertAfterRead=False).getChannelData(pedal_str)
    pvs[cnt] = mdf.mdf(i, convertAfterRead=False).getChannelData(pvs_str)
    cnt += 1

for i in xrange(cnt):
    plt.plot(pvs[i], pedal[i], 'bo', ms='0.7')
    plt.show()
    plt.xlabel(pvs_str + '(V)')
    plt.ylabel(pedal_str + '(%)')
    trend[i] = linregress(pvs[i], pedal[i])
    y_trend[i] = trend[i].intercept + trend[i].slope * pedal[i]
    a_trendstr[i] = repr(trend[i].slope)
    b_trendstr[i] = repr(trend[i].intercept)
    temp = 100 * (float(b_trendstr[i]))
    print '\ny = (' + a_trendstr[i] + ') * x + (' + b_trendstr[
        i] + ')\tfor ' + arquivos[i]
コード例 #19
0
ファイル: __main__.py プロジェクト: waltherg/mdfreader
from __future__ import print_function

import sys
print(sys.argv[1:][0], file=sys.stderr)
import mdfreader
mdfreader.mdf(sys.argv[1:][0])
コード例 #20
0
ファイル: __main__.py プロジェクト: daixtrose/mdfreader
import sys
print(sys.argv[1:][0])
import mdfreader
mdfreader.mdf(sys.argv[1:][0])