def createDictionary(self): fileName = QtGui.QFileDialog.getSaveFileName(self , 'Save dictionary to a file' , expanduser('~')+'/dictionary' , 'Matlab file (*.mat);;Python pickle (*.p);;Comma sep. values (*.csv);;Excel file (*.xlsx)') if len(fileName) == 0: return self.displayInformation('Saving dictionary...' , flag='new') fileName = str(fileName) self.setDictionaryConfig() self.setAlgorithmConfig() config = generateFinalConfig(self.dictionaryConfig , self.dataMatrixes[self.filePath][1] , self.dataMatrixes[self.filePath][2]) time = np.arange(0,self.dataMatrixes[self.filePath][1]['numberOfSamples']) dictionary = generateDictionary(time , config) if fileName[-4:] == '.mat': dic = {col_name : dictionary[col_name].values for col_name in dictionary.columns.values} savemat(fileName , dic) elif fileName[-2:] == '.p': dictionary.to_pickle(fileName) elif fileName[-4:] == '.csv': dictionary.to_csv(fileName) elif fileName[-5:] == '.xlsx': dictionary.to_excel(fileName, sheet_name='dictionary') self.displayInformation('Dictionary saved.' , flag='new')
def saveConfig(self): fileName = QtGui.QFileDialog.getSaveFileName(self , 'Save configuration file' , expanduser('~')+'/config' , 'Python pickle (*.p);;Text file (*.txt);;') if len(fileName) == 0: return self.displayInformation('Saving configuration...' , flag='new') fileName = str(fileName) self.setDictionaryConfig() self.setAlgorithmConfig() config = generateFinalConfig(self.dictionaryConfig , self.dataMatrixes[self.filePath][1] , self.dataMatrixes[self.filePath][2]) if fileName[-4:] == '.txt': with open(fileName , 'w') as f: for key in config.keys(): if isinstance(config[key] , unicode): stringToWrite = key + ' ' + config[key] + '\n' else: stringToWrite = key + ' ' + str(config[key]) + '\n' f.write(stringToWrite.encode('UTF8')) elif fileName[-2:] == '.p': with open(fileName , 'wb') as f: dump(config , f) self.displayInformation('Configuration saved.' , flag='new')
def run(self): self.sig_prb_file_setMax.emit(len(self.files2run)) ind_file = 0 self.sig_prb_file_update.emit(ind_file) self.sig_lbl_file_update.emit('Files - (' + str(ind_file) + ' / ' + str(len(self.files2run)) + ')') for file2run in self.files2run: dataMatrix = self.input[file2run][0] dataInfo = self.input[file2run][1] algorithmConfig = self.input[file2run][2] config = generateFinalConfig(self.dictionaryConfig, dataInfo, algorithmConfig) book = np.empty(shape=(len(config['trials2calc']), len(config['channels2calc'])), dtype=pd.core.frame.DataFrame) self.sig_prb_channel_setMax.emit(len(config['channels2calc'])) self.sig_prb_trial_setMax.emit(len(config['trials2calc'])) ind_channel = 0 self.sig_prb_channel_update.emit(ind_channel) self.sig_lbl_channel_update.emit( 'Channels - (' + str(ind_channel) + ' / ' + str(len(config['channels2calc'])) + ')') for channel in config['channels2calc']: ind_trial = 0 self.sig_prb_trial_update.emit(ind_trial) self.sig_lbl_trial_update.emit( 'Trials - (' + str(ind_trial) + ' / ' + str(len(config['trials2calc'])) + ')') for trial in config['trials2calc']: book[ind_trial, ind_channel] = calculateMP( self.dictionary, np.squeeze(dataMatrix[trial - 1, channel - 1, :]), config) ind_trial += 1 self.sig_prb_trial_update.emit(ind_trial) self.sig_lbl_trial_update.emit( 'Trials - (' + str(ind_trial) + ' / ' + str(len(config['trials2calc'])) + ')') if self.cancelClicked == 1: return ind_channel += 1 self.sig_prb_channel_update.emit(ind_channel) self.sig_lbl_channel_update.emit( 'Channels - (' + str(ind_channel) + ' / ' + str(len(config['channels2calc'])) + ')') ind_file += 1 self.sig_prb_file_update.emit(ind_file) self.sig_lbl_file_update.emit('Files - (' + str(ind_file) + ' / ' + str(len(self.files2run)) + ')') self.sig_singleBookDone.emit(book, config, file2run)
def run(self): self.sig_prb_file_setMax.emit(len(self.files2run)) ind_file = 0 self.sig_prb_file_update.emit(ind_file) self.sig_lbl_file_update.emit('Files - (' + str(ind_file) + ' / ' + str(len(self.files2run)) + ')') for file2run in self.files2run: dataMatrix = self.input[file2run][0] dataInfo = self.input[file2run][1] algorithmConfig = self.input[file2run][2] config = generateFinalConfig(self.dictionaryConfig , dataInfo , algorithmConfig) book = np.empty(shape=(len(config['trials2calc']),len(config['channels2calc'])) , dtype = pd.core.frame.DataFrame) self.sig_prb_channel_setMax.emit(len(config['channels2calc'])) self.sig_prb_trial_setMax.emit(len(config['trials2calc'])) ind_channel = 0 self.sig_prb_channel_update.emit(ind_channel) self.sig_lbl_channel_update.emit('Channels - (' + str(ind_channel) + ' / ' + str(len(config['channels2calc'])) + ')') for channel in config['channels2calc']: ind_trial = 0 self.sig_prb_trial_update.emit(ind_trial) self.sig_lbl_trial_update.emit('Trials - (' + str(ind_trial) + ' / ' + str(len(config['trials2calc'])) + ')') for trial in config['trials2calc']: book[ind_trial , ind_channel] = calculateMP(self.dictionary , np.squeeze(dataMatrix[trial-1,channel-1,:]) , config) ind_trial += 1 self.sig_prb_trial_update.emit(ind_trial) self.sig_lbl_trial_update.emit('Trials - (' + str(ind_trial) + ' / ' + str(len(config['trials2calc'])) + ')') if self.cancelClicked == 1: return ind_channel += 1 self.sig_prb_channel_update.emit(ind_channel) self.sig_lbl_channel_update.emit('Channels - (' + str(ind_channel) + ' / ' + str(len(config['channels2calc'])) + ')') ind_file += 1 self.sig_prb_file_update.emit(ind_file) self.sig_lbl_file_update.emit('Files - (' + str(ind_file) + ' / ' + str(len(self.files2run)) + ')') self.sig_singleBookDone.emit(book , config , file2run)