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
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
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
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)
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) 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 += '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) 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' if 'project' in Comment: f += 'Project Name: ' + Comment['project'] + '\n' if 'subject' in Comment: f += 'Subject: ' + Comment[ 'subject'] + '\n' + 'Channel List:\n' for channelName in info.listChannels(): f += ' ' + channelName + '\n' return f, True
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) 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 += '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) 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' if 'project' in Comment: f += 'Project Name: ' + Comment['project'] + '\n' if 'subject' in Comment: f += 'Subject: ' + Comment['subject'] + '\n' + 'Channel List:\n' for channelName in info.listChannels(): f += ' ' + channelName + '\n' return f, True