def _load_annotation_table(self, *args, filename=None): """Load annotations.""" # Get file name : if filename is None: filename = dialog_load( self, "Import annotations", '', "CSV file (*.csv);;Text file (*.txt);;" "All files (*.*)") # Clean annotations : self._AnnotateTable.setRowCount(0) start, end, annot = annotations_to_array(filename) # Fill table : self._AnnotateTable.setRowCount(len(start)) # File the table : for k, (s, e, a) in enumerate(zip(start, end, annot)): # Starting index : self._AnnotateTable.setItem(k, 0, QtWidgets.QTableWidgetItem(str(s))) # Ending index : self._AnnotateTable.setItem(k, 1, QtWidgets.QTableWidgetItem(str(e))) # Text : self._AnnotateTable.setItem(k, 2, QtWidgets.QTableWidgetItem(str(a))) # Set the current tab to the annotation tab : self.QuickSettings.setCurrentIndex(5) # Set markers : middle = (start.astype(np.float32) + end.astype(np.float32)) / 2 self._annot_mark = middle self._fcn_slider_move()
def _load_annotation_table(self, *args, filename=None): """Load annotations.""" # Get file name : if filename is None: filename = dialog_load(self, "Import annotations", '', "CSV file (*.csv);;Text file (*.txt);;" "All files (*.*)") # Clean annotations : self._AnnotateTable.setRowCount(0) start, end, annot = annotations_to_array(filename) # Fill table : self._AnnotateTable.setRowCount(len(start)) # File the table : for k, (s, e, a) in enumerate(zip(start, end, annot)): # Starting index : self._AnnotateTable.setItem( k, 0, QtWidgets.QTableWidgetItem(str(s))) # Ending index : self._AnnotateTable.setItem( k, 1, QtWidgets.QTableWidgetItem(str(e))) # Text : self._AnnotateTable.setItem( k, 2, QtWidgets.QTableWidgetItem(str(a))) # Set the current tab to the annotation tab : self.QuickSettings.setCurrentIndex(5) # Set markers : middle = (start.astype(np.float32) + end.astype(np.float32)) / 2 self._annot_mark = middle self._fcn_slider_move()
def _load_detect_select(self, *args, filename=None): """Load a specific detection.""" # Get file name : if filename is None: filename = dialog_load( self, "Import table", '', "CSV file (*.csv);;Text file (*.txt);;" "All files (*.*)") if filename: # Get channel / method from file name : (chan, meth) = filename.split('_')[-1].split('.')[0].split('-') # Load the file : (st, end) = np.genfromtxt(filename, delimiter=',', encoding='utf-8')[3::, 0:2].T # Sort by starting index : idxsort = np.argsort(st) st, end = st[idxsort], end[idxsort] # Concatenate (starting, ending) index : index = np.c_[st, end] # Convert into index : index = np.round(index * self._sf).astype(int) # Set index : self._detect[(chan, meth)]['index'] = index # Plot update : self._fcn_slider_move() self._loc_line_report() self._check_detect_menu()
def _load_detect_select(self, *args, filename=None): """Load a specific detection.""" # Get file name : if filename is None: filename = dialog_load(self, "Import table", '', "CSV file (*.csv);;Text file (*.txt);;" "All files (*.*)") if filename: # Get channel / method from file name : (chan, meth) = filename.split('_')[-1].split('.')[0].split('-') # Load the file : (st, end) = np.genfromtxt(filename, delimiter=',', encoding='utf-8')[3::, 0:2].T # Sort by starting index : idxsort = np.argsort(st) st, end = st[idxsort], end[idxsort] # Concatenate (starting, ending) index : index = np.c_[st, end] # Convert into index : index = np.round(index * self._sf).astype(int) # Set index : self._detect[(chan, meth)]['index'] = index # Plot update : self._fcn_slider_move() self._loc_line_report() self._check_detect_menu()
def _load_detect_all(self, *args, filename=None): """Load all detections.""" # Dialog window for detection file : if filename is None: filename = dialog_load(self, "Import detections", '', "NumPy (*.npy);;All files (*.*)") self._detect.dict = np.ndarray.tolist(np.load(filename)) # Made canvas visbles : for k in self._detect: if self._detect[k]['index'].size: # Get channel number : idx = self._channels.index(k[0]) self._canvas_set_visible(idx, True) self._chan.visible[idx] = True # Plot update : self._fcn_slider_move() self._loc_line_report() self._check_detect_menu()
def _load_detect_all(self, *args, filename=None): """Load all detections.""" # Dialog window for detection file : if filename is None: filename = dialog_load(self, "Import detections", '', "NumPy (*.npy);;All files (*.*)") self._detect.dict = np.ndarray.tolist(np.load(filename)) # Made canvas visbles : for k in self._detect: if self._detect[k]['index'].size: # Get channel number : idx = self._channels.index(k[0]) self._canvas_set_visible(idx, True) self._chan.visible[idx] = True # Plot update : self._fcn_slider_move() self._loc_line_report() self._check_detect_menu()
def _fcn_load_annotations(self, *args, filename=None): """Load annotations.""" # Get file name : if filename is None: filename = dialog_load(self, "Import annotations", '', "CSV file (*.csv);;Text file (*.txt);;" "All files (*.*)") # Clean annotations : self._annot_table.setRowCount(0) # Load the file : if isinstance(filename, str): # 'file.txt' # Get starting/ending/annotation : time, amp, signal, text = np.genfromtxt(filename, delimiter='_', dtype=str).T coords = np.c_[time, amp].astype(float) # Fill table : self._signal.clean_annotations() self._annot_table.setRowCount(0) # File the table : for k in range(len(signal)): self._annotate_event(signal[k], coords[k, :], text=text[k])
def _load_hypno(self, *args, filename=None): """Load a hypnogram.""" # Define default filename for the hypnogram : if not isinstance(self._file, str): hyp_file = 'hypno' else: hyp_file = os.path.basename(self._file) + '_hypno' # Get filename : if filename is None: filename = dialog_load(self, 'Load hypnogram File', hyp_file, "Text file (*.txt);;CSV file (*.csv);;" "Elan file (*.hyp);;Excel file (*.xlsx);;" "All files (*.*)") if filename: # Load the hypnogram : self._hypno, _ = read_hypno(filename, time=self._time) self._hypno = oversample_hypno(self._hypno, self._N)[::self._dsf] self._hyp.set_data(self._sf, self._hypno, self._time) # Update info table : self._fcn_info_update() # Update scoring table : self._fcn_hypno_to_score() self._fcn_score_to_hypno()
def _fcn_load_annotations(self, *args, filename=None): """Load annotations.""" # Get file name : if filename is None: filename = dialog_load( self, "Import annotations", '', "CSV file (*.csv);;Text file (*.txt);;" "All files (*.*)") # Clean annotations : self._annot_table.setRowCount(0) # Load the file : if isinstance(filename, str): # 'file.txt' # Get starting/ending/annotation : time, amp, signal, text = np.genfromtxt(filename, delimiter='_', dtype=str).T coords = np.c_[time, amp].astype(float) # Fill table : self._signal.clean_annotations() self._annot_table.setRowCount(0) # File the table : for k in range(len(signal)): self._annotate_event(signal[k], coords[k, :], text=text[k])
def _load_hypno(self, *args, filename=None): """Load a hypnogram.""" # Define default filename for the hypnogram : if not isinstance(self._file, str): hyp_file = 'hypno' else: hyp_file = os.path.basename(self._file) + '_hypno' # Get filename : if filename is None: filename = dialog_load( self, 'Load hypnogram File', hyp_file, "Text file (*.txt);;CSV file (*.csv);;" "Elan file (*.hyp);;Excel file (*.xlsx);;" "All files (*.*)") if filename: # Load the hypnogram : self._hypno, _ = read_hypno(filename, time=self._time) self._hypno = oversample_hypno(self._hypno, self._N)[::self._dsf] self._hyp.set_data(self._sf, self._hypno, self._time) # Update info table : self._fcn_info_update() # Update scoring table : self._fcn_hypno_to_score() self._fcn_score_to_hypno()
def _load_config(self, *args, filename=None): """Load a config file (.json) containing several display parameters.""" import json if not filename: filename = dialog_load( self, 'Load config File', 'config', "JSON file (*.json);;Text files (*.txt);;" "All files (*.*)") if filename: with open(filename) as f: # Load the configuration file : config = json.load(f) def _try(string, self=self, config=config): """Execute the string. This function insure backward compatibility for loading the configuration file. """ try: exec(string) except: pass # Channels for i, k in enumerate(self._chanChecks): self._chanChecks[i].setChecked( config['Channel_Visible'][i]) self._ymaxSpin[i].setValue(config['Channel_Amplitude'][i]) # Amplitudes : # _try("self._PanAllAmpMin.setValue(config['AllAmpMin'])") # _try("self._PanAllAmpMax.setValue(config['AllAmpMax'])") _try("self._PanAmpSym.setChecked(config['SymAmp'])") _try("self._PanAmpAuto.setChecked(config['AutoAmp'])") # Spectrogram _try("self.menuDispSpec.setChecked(config['Spec_Visible'])") _try("self._PanSpecMethod.setCurrentIndex(" "config['Spec_Method'])") _try("self._PanSpecNfft.setValue(config['Spec_Length'])") _try("self._PanSpecStep.setValue(config['Spec_Overlap'])") _try("self._PanSpecCmap.setCurrentIndex(config['Spec_Cmap'])") _try("self._PanSpecCmapInv.setChecked(config['Spec_CmapInv'])") _try("self._PanSpecChan.setCurrentIndex(config['Spec_Chan'])") _try("self._PanSpecFstart.setValue(config['Spec_Fstart'])") _try("self._PanSpecFend.setValue(config['Spec_Fend'])") _try("self._PanSpecCon.setValue(config['Spec_Con'])") _try("self._PanSpecInterp.setCurrentIndex(" "config['Spec_Interp'])") # Hypnogram/time axis/navigation/topo/indic/zoom : _try("self.menuDispHypno.setChecked(config['Hyp_Visible'])") _try("self.menuDispTimeax.setChecked(config['Time_Visible'])") _try("self.menuDispTopo.setChecked(config['Topo_Visible'])") _try("self.menuDispNavbar.setChecked(config['Nav_Visible'])") _try("self.menuDispIndic.setChecked(config['Indic_Visible'])") _try("self._PanHypnoLw.setValue(config['Hyp_Lw'])") _try("self._PanHypnoColor.setChecked(config['Hyp_Color'])") # Navigation bar properties : _try("self._SlVal.setValue(config['Slider'])") _try("self._SigSlStep.setValue(config['Step'])") _try("self._SigWin.setValue(config['Display_Window'])") _try("self._ScorWin.setValue(config['Scoring_Window'])") _try("self._SlGoto.setValue(config['Goto'])") _try("self._slMagnify.setChecked(config['Magnify'])") _try("self._slAbsTime.setChecked(config['AbsTime'])") _try("self._slGrid.setChecked(config['Grid'])") _try("self._ScorWinVisible.setChecked(" "config['Display_Scoring_Window'])") _try("self._slRules.setCurrentIndex(config['Unit'])") # Update display self._fcn_chan_viz() self._fcn_chan_amplitude() self._fcn_spec_set_data() self._disptog_spec() self._disptog_hyp() self._disptog_timeax() self._disptog_topo() self._disptog_indic() self._disptog_zoom() self._fcn_grid_toggle() self._fcn_scorwin_indicator_toggle() self._fcn_update_amp_info() self._fcn_chan_auto_amp() self._fcn_chan_sym_amp() self._fcn_set_hypno_lw() self._fcn_set_hypno_color()
def _fcn_load_config(self, _, filename=None): """Load the configuration.""" if not filename: filename = dialog_load(self, 'Load config File', 'config', "Text file (*.txt);;All files (*.*)") if filename: config = load_config_json(filename) def _try(string, self=self, config=config): """Execute the string. This function insure backward compatibility for loading the configuration file. """ try: exec(string) except: warn("Cannot execute for loading the config : " + string) # ----------------- VISIBLE OBJECTS ----------------- # Settings : _try("self.menuDispQuickSettings.setChecked(" "config['SettingViz'])") _try("self._fcn_menu_disp_set()") # Engram : _try("self.menuDispEngram.setChecked(config['EngramViz'])") _try("self._fcn_menu_disp_engram()") # Sources _try("self.menuDispSources.setChecked(config['SourcesViz'])") _try("self._fcn_menu_disp_sources()") # Connect : _try("self.menuDispConnect.setChecked(config['ConnectViz'])") _try("self._fcn_menu_disp_connect()") # ROI : _try("self.menuDispROI.setChecked(config['ROIViz'])") _try("self._fcn_menu_disp_roi()") # Cbar : _try("self.menuDispCbar.setChecked(config['CbarViz'])") _try("self._fcn_menu_disp_cbar()") # ----------------- CAMERA ----------------- _try("self.view.wc.camera.set_state(config['CamState'])") _try("self.cbqt.cbviz._wc.camera.rect=config['CamCbState']") # ----------------- BRAIN ----------------- # Surroundings : _try("self._engram_translucent.setChecked(config['EngramTransp'])") _try("self._engramPickHemi.setCurrentIndex(config[" "'EngramHemi'])") _try("self._engramTemplate.setCurrentIndex(config[" "'EngramTemplate'])") _try("self._engram_control()") _try("self._light_reflection()") # ROIs : _try("self._roiTransp.setChecked(config['RoiTransp'])") _try("self._roiDiv.setCurrentIndex(config['RoiAnat'])") _try("self._roiSmooth.setValue(config['RoiSmooth'])") _try("self._roiToAdd.clear()") _try("self._fcn_build_roi_list()") _try("self._fcn_set_selected_rois(config['RoiStruct'])") _try("self._fcn_update_list()") # Cross-sections : _try("self._csSagit.setValue(config['CsSagit'])") _try("self._csCoron.setValue(config['CsCoron'])") _try("self._csAxial.setValue(config['CsAxial'])") _try("self._csDiv.setCurrentIndex(config['CsDiv'])") _try("self._csCmap.setCurrentIndex(config['CsCmap'])") _try("self._csTransp.setChecked(config['CsTransp'])") _try("self._csSplit.setChecked(config['CsSplit'])") _try("self.grpSec.setChecked(config['CsGrp'])") _try("self._fcn_crossec_change()") _try("self._fcn_crossec_split()") # Volume : _try("self._volDiv.setCurrentIndex(config['VolDiv'])") _try("self._volRendering.setCurrentIndex(config['VolRendering'])") _try("self._volCmap.setCurrentIndex(config['VolCmap'])") _try("self._volIsoTh.setValue(config['VolTh'])") _try("self.grpVol.setChecked(config['VolGrp'])") _try("self._fcn_vol_change()") # ----------------- SOURCES ----------------- # Sources object : _try("self._sourcesPickdisp.setCurrentIndex(config[" "'SourcesDisp'])") _try("self._fcn_sources_display()") _try("self.s_Symbol.setCurrentIndex(config['SourcesSym'])") _try("self.s_EdgeColor.setText(str(config['SourcesEcol']))") _try("self.s_EdgeWidth.setValue(config['SourcesEw'])") _try("self._fcn_sources_look()") _try("self.s_radiusMin.setValue(config['SourcesRm'])") _try("self.s_radiusMax.setValue(config['SourcesRM'])") _try("self.s_Scaling.setChecked(config['SourcesScale'])") _try("self._fcn_sources_radius()") # Source's text : _try("self.grpText.setChecked(config['StextShow'])") _try("self.q_stextsize.setValue(config['StextSz'])") _try("self.q_stextcolor.setText(str(config['StextCol']))") _try("self.x_text.setValue(config['StextXYZ'][0])") _try("self.y_text.setValue(config['StextXYZ'][1])") _try("self.z_text.setValue(config['StextXYZ'][2])") # Source's projection settings : _try("self._uitRadius.setValue(config['SprojRad'])") _try("self._uitPickProj.setCurrentIndex(config['SprojType'])") _try("self._uitProjectOn.setCurrentIndex(config['SprojOn'])") _try("self._uitContribute.setChecked(config['SprojCon'])") # Source's time-series : _try("self._tsWidth.setValue(config['StsWidth'])") _try("self._tsAmp.setValue(config['StsAmp'])") _try("self._tsLw.setValue(config['StsLw'])") _try("self._tsDx.setValue(config['StsDxyz'][0])") _try("self._tsDy.setValue(config['StsDxyz'][1])") _try("self._tsDz.setValue(config['StsDxyz'][2])") _try("self._tsColor.setText(str(config['StsColor']))") _try("self._fcn_ts_update()") # ----------------- CONNECTIVITY ----------------- _try("self.uiConnect_colorby.setCurrentIndex(config[" "'ConnectCby'])") _try("self._connectStaDynTransp.setCurrentIndex(config[" "'ConnectAlp'])") _try("self.uiConnect_dynMin.setValue(config['ConnectMin'])") _try("self.uiConnect_dynMax.setValue(config['ConnectMax'])") _try("self._densityRadius.setValue(config['ConnectRad'])") _try("self.uiConnect_lw.setValue(config['ConnectLw'])") _try("self._conBlEnable.setChecked(config['ConnectBun'])") _try("self._conBlRadius.setValue(config['ConnectBunRad'])") _try("self._conBlDxyz.setValue(config['ConnectBunDxyz'])") # ----------------- GUI SETTINGS ----------------- # Background color : rgb = config['BcgColor'] _try("self.bgd_red.setValue(" + str(rgb[0]) + ")") _try("self.bgd_green.setValue(" + str(rgb[1]) + ")") _try("self.bgd_blue.setValue(" + str(rgb[2]) + ")") _try("self._fcn_bgd_color()") # Tab : _try("self.QuickSettings.setCurrentIndex(config[" "'CurrentTab'])") # ----------------- CBAR ----------------- # Cbar visual : _try("self.cbqt.cbobjs.from_dict(config['Cbar'])") _try("self.cbqt._disconnect()") _try("self.cbqt._initialize()") _try("self.cbqt._connect()") _try("self.cbqt.link('Projection', self._fcn_link_proj, " "self._fcn_minmax_proj)") _try("self.cbqt.link('Connectivity', self._fcn_link_connect, " "self._fcn_minmax_connect)")
def _load_config(self, *args, filename=None): """Load a config file (.json) containing several display parameters.""" import json if not filename: filename = dialog_load(self, 'Load config File', 'config', "JSON file (*.json);;Text files (*.txt);;" "All files (*.*)") if filename: with open(filename) as f: # Load the configuration file : config = json.load(f) def _try(string, self=self, config=config): """Execute the string. This function insure backward compatibility for loading the configuration file. """ try: exec(string) except: pass # Channels for i, k in enumerate(self._chanChecks): self._chanChecks[i].setChecked( config['Channel_Visible'][i]) self._ymaxSpin[i].setValue(config['Channel_Amplitude'][i]) # Amplitudes : # _try("self._PanAllAmpMin.setValue(config['AllAmpMin'])") # _try("self._PanAllAmpMax.setValue(config['AllAmpMax'])") _try("self._PanAmpSym.setChecked(config['SymAmp'])") _try("self._PanAmpAuto.setChecked(config['AutoAmp'])") # Spectrogram _try("self.menuDispSpec.setChecked(config['Spec_Visible'])") _try("self._PanSpecMethod.setCurrentIndex(" "config['Spec_Method'])") _try("self._PanSpecNfft.setValue(config['Spec_Length'])") _try("self._PanSpecStep.setValue(config['Spec_Overlap'])") _try("self._PanSpecCmap.setCurrentIndex(config['Spec_Cmap'])") _try("self._PanSpecCmapInv.setChecked(config['Spec_CmapInv'])") _try("self._PanSpecChan.setCurrentIndex(config['Spec_Chan'])") _try("self._PanSpecFstart.setValue(config['Spec_Fstart'])") _try("self._PanSpecFend.setValue(config['Spec_Fend'])") _try("self._PanSpecCon.setValue(config['Spec_Con'])") _try("self._PanSpecInterp.setCurrentIndex(" "config['Spec_Interp'])") # Hypnogram/time axis/navigation/topo/indic/zoom : _try("self.menuDispHypno.setChecked(config['Hyp_Visible'])") _try("self.menuDispTimeax.setChecked(config['Time_Visible'])") _try("self.menuDispTopo.setChecked(config['Topo_Visible'])") _try("self.menuDispNavbar.setChecked(config['Nav_Visible'])") _try("self.menuDispIndic.setChecked(config['Indic_Visible'])") _try("self._PanHypnoLw.setValue(config['Hyp_Lw'])") _try("self._PanHypnoColor.setChecked(config['Hyp_Color'])") # Navigation bar properties : _try("self._SlVal.setValue(config['Slider'])") _try("self._SigSlStep.setValue(config['Step'])") _try("self._SigWin.setValue(config['Window'])") _try("self._SlGoto.setValue(config['Goto'])") _try("self._slMagnify.setChecked(config['Magnify'])") _try("self._slAbsTime.setChecked(config['AbsTime'])") _try("self._slGrid.setChecked(config['Grid'])") _try("self._slRules.setCurrentIndex(config['Unit'])") # Update display self._fcn_chan_viz() self._fcn_chan_amplitude() self._fcn_spec_set_data() self._disptog_spec() self._disptog_hyp() self._disptog_timeax() self._disptog_topo() self._disptog_indic() self._disptog_zoom() self._fcn_grid_toggle() self._fcn_update_amp_info() self._fcn_chan_auto_amp() self._fcn_chan_sym_amp() self._fcn_set_hypno_lw() self._fcn_set_hypno_color()