def build_ui(self): # build a main GUI window self.main_window = QMainWindow() self.main_window.setWindowTitle('Analysis tool') self.main_window.show() self.canvas = pg.ScatterPlotWidget() # add a label to the main window splitter = QSplitter(self.main_window) splitter.addWidget(self.canvas) self.main_window.setCentralWidget(splitter) # add a toolbar with an action button to the main window action = QAction('Open result file', self) action.triggered.connect(self.openFile) toolbar = QToolBar() toolbar.addAction(action) self.main_window.addToolBar(toolbar) # self.main_window.addToolBar(Qt.BottomToolBarArea, # NavigationToolbar(self.canvas, self.main_window)) # add a status bar to the main window self.status_openfile = QLabel("No file open.") self.status_data = QLabel("") status_bar = QStatusBar() status_bar.addWidget(self.status_openfile, 1) status_bar.addWidget(self.status_data, 0) self.main_window.setStatusBar(status_bar) self.result = None self.index = 0 self.plotdata = [[], [], []] self.currentData = [[], [], []] self.installEventFilter(self)
data['x_pos'][data['type'] == 'Type-D'] += 2 data['x_pos'][data['type'] == 'Type-E'] += 2 data['y_pos'] = np.random.normal(size=1000) + data['x_pos'] * 0.1 data['y_pos'][data['type'] == 'Type-A'] += 3 data['y_pos'][data['type'] == 'Type-B'] += 3 data['amplitude'] = data['x_pos'] * 1.4 + data['y_pos'] + np.random.normal( size=1000, scale=0.4) data['count'] = (np.random.exponential(size=1000, scale=100) * data['x_pos']).astype(int) data['decay'] = np.random.normal(size=1000, scale=1e-3) + data['amplitude'] * 1e-4 data['decay'][data['type'] == 'Type-A'] /= 2 data['decay'][data['type'] == 'Type-E'] *= 3 # Create ScatterPlotWidget and configure its fields spw = pg.ScatterPlotWidget() spw.setFields([ ('x_pos', { 'units': 'm' }), ('y_pos', { 'units': 'm' }), ('count', {}), ('amplitude', { 'units': 'V' }), ('decay', { 'units': 's' }), ('type', {
def __init__(self, recs): pg.QtCore.QObject.__init__(self) # Load all records into scatter plot widget spw = pg.ScatterPlotWidget() spw.style['symbolPen'] = None spw.resize(1000, 800) spw.show() fields = [ ('has_synapse', { 'mode': 'enum', 'values': [True, False, None] }), ('synapse_type', { 'mode': 'enum', 'values': ['in', 'ex'] }), ('prediction', { 'mode': 'enum', 'values': [True, False, None] }), ('confidence', {}), ('pre_cre_type', { 'mode': 'enum', 'values': list(set(recs['pre_cre_type'])) }), ('post_cre_type', { 'mode': 'enum', 'values': list(set(recs['post_cre_type'])) }), ('pre_pyramidal', { 'mode': 'enum', 'values': list(set(recs['pre_pyramidal'])) }), ('post_pyramidal', { 'mode': 'enum', 'values': list(set(recs['post_pyramidal'])) }), ('pre_target_layer', { 'mode': 'enum' }), ('post_target_layer', { 'mode': 'enum' }), ('ic_n_samples', {}), ('vc_n_samples', {}), ('rig_name', { 'mode': 'enum', 'values': list(set(recs['rig_name'])) }), ('acsf', { 'mode': 'enum', 'values': list(set(recs['acsf'])) }), ('acq_timestamp', {}), ('crosstalk_artifact', { 'units': 'V' }), # ('electrode_distance', {}), ('slice_quality', { 'mode': 'enum', 'values': list(range(1, 6)) }), ] fnames = [f[0] for f in fields] for f in recs.dtype.names: if f in fnames: continue if 'amp' in f: if f[:2] == 'vc': fields.append((f, {'units': 'A'})) else: fields.append((f, {'units': 'V'})) elif 'latency' in f: fields.append((f, {'units': 's'})) else: fields.append((f, {})) spw.setFields(fields) spw.setData(recs) spw.sigScatterPlotClicked.connect(self._conn_clicked) # Set up scatter plot widget defaults spw.setSelectedFields('ic_base_deconv_amp_mean', 'ic_deconv_amp_mean') spw.filter.addNew('has_synapse') ch = spw.filter.addNew('ic_crosstalk_mean') ch['Min'] = -1 ch['Max'] = 60e-6 ch = spw.filter.addNew('rig_name') ch = spw.colorMap.addNew('has_synapse') ch['Values', 'True'] = pg.mkColor('y') ch['Values', 'False'] = pg.mkColor(200, 200, 200, 150) ch['Values', 'None'] = pg.mkColor(200, 100, 100) ch = spw.colorMap.addNew('ic_latency_mean') ch['Operation'] = 'Add' ch['Max'] = 3e-3 cm = pg.ColorMap([0, 1], [[0, 0, 255, 255], [0, 0, 0, 255]]) ch.setValue(cm) self.spw = spw
def init_ui(self): grid = QGridLayout() grid.setSpacing(10) # region Sets up the roi and exit buttons try: self.roi_btn = QPushButton('roi', self) self.roi_btn.setToolTip('Create a new <b>ROI</b> (region of interest) or edit the current one.') self.roi_btn.clicked.connect(self.roi_clicked) self.roi_btn.resize(self.roi_btn.sizeHint()) except Exception as e: print(e) self.exit_btn = QPushButton('Exit', self) self.exit_btn.setToolTip('Exit the program') self.exit_btn.clicked.connect(QApplication.instance().quit) self.exit_btn.resize(self.exit_btn.sizeHint()) grid.addWidget(self.roi_btn, 2, 0) grid.addWidget(self.exit_btn, 2, 1) # endregion # region Sets up the colormap sliders cmx = QLabel('Max') self.cmap_max = QSlider(Qt.Vertical, self) self.cmap_max.setToolTip('Adjusts the upper saturation limit of the colormap') cmm = QLabel('Mid') self.cmap_mid = QSlider(Qt.Vertical, self) self.cmap_mid.setToolTip('Adjusts the mid-point of the colormap') cmn = QLabel('Min') self.cmap_min = QSlider(Qt.Vertical, self) self.cmap_min.setToolTip('Adjusts the lower saturation limit of the colormap') grid.addWidget(cmn, 0, 2) grid.addWidget(self.cmap_min, 1, 2) grid.addWidget(cmm, 0, 3) grid.addWidget(self.cmap_mid, 1, 3) grid.addWidget(cmx, 0, 4) grid.addWidget(self.cmap_max, 1, 4) # endregion # region Sets up the plots self.img = pg.ImageView() self.dmp = pg.ScatterPlotWidget() grid.addWidget(QLabel('Grayscale', self), 0, 0) grid.addWidget(self.img, 1, 0) grid.addWidget(QLabel('Point cloud', self), 0, 1) grid.addWidget(self.dmp, 1, 1) # endregion main = QWidget() main.setLayout(grid) self.setCentralWidget(main) self.setGeometry(300, 300, 500, 400) self.setWindowTitle('Depth Averaging Utility') self.statusBar().showMessage('Ready') self.show()
def __init__(self): self.loaded_pair = None pg.QtGui.QSplitter.__init__(self, pg.QtCore.Qt.Horizontal) self.ctrl_split = pg.QtGui.QSplitter(pg.QtCore.Qt.Vertical) self.addWidget(self.ctrl_split) self.browser = ExperimentBrowser() self.ctrl_split.addWidget(self.browser) self.scatter_plot = pg.ScatterPlotWidget() self.ctrl_split.addWidget(self.scatter_plot.ctrlPanel) self.addWidget(self.scatter_plot.plot) # Select all fields to be displayed fields = { 'pulse_response_id': { 'column': db.PulseResponse.id, 'mode': 'range', 'dtype': int }, 'clamp_mode': { 'column': db.PatchClampRecording.clamp_mode, 'mode': 'enum', 'values': ['ic', 'vc'], 'dtype': object }, 'pulse_number': { 'column': db.StimPulse.pulse_number, 'mode': 'enum', 'values': list(range(1, 13)), 'dtype': int }, 'induction_frequency': { 'column': db.MultiPatchProbe.induction_frequency, 'mode': 'range', 'dtype': float }, 'recovery_delay': { 'column': db.MultiPatchProbe.recovery_delay, 'mode': 'range', 'dtype': float }, 'baseline_current': { 'column': db.PatchClampRecording.baseline_current, 'mode': 'range', 'dtype': float }, 'baseline_potential': { 'column': db.PatchClampRecording.baseline_potential, 'mode': 'range', 'dtype': float }, 'baseline_rms_noise': { 'column': db.PatchClampRecording.baseline_rms_noise, 'mode': 'range', 'dtype': float }, 'recording_qc_pass': { 'column': db.PatchClampRecording.qc_pass, 'mode': 'enum', 'values': [True, False], 'dtype': bool }, } for table, prefix in [(db.PulseResponse, ''), (db.PulseResponseFit, ''), (db.PulseResponseStrength, '')]: for name, col in table.__table__.c.items(): if name.endswith('_id'): continue colname = name if name == 'id': name = table.__table__.name + '_id' else: name = prefix + name if isinstance( col.type, (sqltypes.Integer, sqltypes.Float, database.FloatType)): fields[name] = {'mode': 'range', 'dtype': float} elif isinstance(col.type, sqltypes.String): fields[name] = {'mode': 'enum', 'dtype': object} elif isinstance(col.type, sqltypes.Boolean): fields[name] = { 'mode': 'enum', 'values': [True, False], 'dtype': bool } else: continue fields[name]['column'] = getattr(table, colname) self.fields = fields # set up scatter plot fields sp_fields = [] self.dtype = [] for name, spec in fields.items(): if spec['mode'] == 'enum': sp_fields.append((name, { 'mode': 'enum', 'values': spec['values'] })) else: sp_fields.append((name, {'mode': 'range'})) self.dtype.append((name, spec['dtype'])) self.scatter_plot.setFields(sp_fields) # default filter for IC data cm_filter = self.scatter_plot.filter.addNew('clamp_mode') cm_filter['vc'] = False # default color by nrmse nrmse_color = self.scatter_plot.colorMap.addNew('fit_nrmse') qc_color = self.scatter_plot.colorMap.addNew('ex_qc_pass') qc_color['Values', 'True'] = (255, 255, 255) qc_color['Values', 'False'] = (0, 0, 0) qc_color['Operation'] = 'Multiply' self.view = pg.GraphicsLayoutWidget() self.addWidget(self.view) self.spike_plots = [ self.view.addPlot(row=0, col=0), self.view.addPlot(row=0, col=1) ] self.data_plots = [ self.view.addPlot(row=1, col=0), self.view.addPlot(row=1, col=1) ] self.dec_plots = [ self.view.addPlot(row=2, col=0), self.view.addPlot(row=2, col=1) ] for col in (0, 1): self.spike_plots[col].setXLink(self.data_plots[0]) self.data_plots[col].setXLink(self.data_plots[0]) self.dec_plots[col].setXLink(self.data_plots[0]) self.spike_plots[1].setYLink(self.spike_plots[0]) self.data_plots[1].setYLink(self.data_plots[0]) self.dec_plots[1].setYLink(self.dec_plots[0]) self.resize(1600, 1000) self.browser.itemSelectionChanged.connect(self.browser_item_selected) self.scatter_plot.sigScatterPlotClicked.connect( self.scatter_plot_clicked)