def test_livePlot(self): _ = pyqtgraph.mkQApp() mock_callback = MockCallback_2d( qtt.measurements.scans.instrumentName('mock')) lp = livePlot(datafunction=mock_callback, sweepInstrument=None, sweepparams=['L', 'R'], sweepranges=[50, 50], show_controls=True) lp.win.setGeometry(1500, 10, 400, 400) lp.startreadout() lp.crosshair(True) lp.stopreadout() lp.updatebg() lp.close() self.assertIsInstance(lp.datafunction_result, np.ndarray) mock_callback.close()
def __init__(self, station, sweepparams, sweepranges, minstrument, nplots=None, Naverage=10, resolution=[96, 96], sample_rate='default', diff_dir=None, verbose=1, dorun=True, show_controls=True, add_ppt=True, crosshair=False, averaging=True, name=None, mouse_click_callback=None): """ Tool for fast acquisition of charge stability diagram The class assumes that the station has a station.digitizer and a station.awg. Args: station (QCoDeS station): reference for the instruments sweepparams (list or dict or str): parameters to sweep mouse_click_callback (None or function): if None then update scan position with callback """ if VideoMode.videomode_class_index == 0: # create instance of QApplication _ = pyqtgraph.mkQApp() VideoMode.videomode_class_index = VideoMode.videomode_class_index + 1 # increment index of VideoMode objects self.videomode_index = VideoMode.videomode_class_index self.station = station self.verbose = verbose self.sweepparams = sweepparams self.sweepranges = sweepranges self.virtual_awg = getattr(station, ' virtual_awg', None) self.minstrumenthandle = minstrument[0] self.channels = minstrument[1] if isinstance(self.channels, int): self.channels = [self.channels] self.Naverage = Parameter('Naverage', get_cmd=self._get_Naverage, set_cmd=self._set_Naverage, vals=Numbers(1, 1023)) self._Naverage_val = Naverage self.resolution = resolution self.sample_rate = sample_rate self.diff_dir = diff_dir self.datalock = threading.Lock() self.datafunction_result = None self.update_sleep = 1e-5 if name is None: name = 'VideoMode %d' % self.videomode_index if isinstance(self.sweepparams, (str, list)): name += ': %s' % str(self.sweepparams) self.name = name # parse instrument minstrumenthandle = qtt.measurements.scans.get_instrument(self.minstrumenthandle, station) if minstrumenthandle.name in ['digitizer', 'm4i']: if sample_rate == 'default': self.sampling_frequency = minstrumenthandle.sample_rate else: minstrumenthandle.sample_rate(sample_rate) self.sampling_frequency = station.digitizer.sample_rate elif minstrumenthandle.name in ['ZIUHFLI', 'ziuhfli']: self.sampling_frequency = minstrumenthandle.scope_samplingrate else: try: minstrumenthandle = qtt.measurements.scans.get_instrument( minstrument, station) self.sampling_frequency = minstrumenthandle.sample_rate except: raise Exception('no fpga or digitizer found') # for addPPT and debugging self.scanparams = {'sweepparams': sweepparams, 'sweepranges': sweepranges, 'minstrument': minstrument, 'resolution': self.resolution, 'sampling_frequency': self.sampling_frequency()} self.idx = 0 self.fps = qtt.pgeometry.fps_t(nn=6) # Setup the GUI if nplots is None: nplots = len(self.channels) self.nplots = nplots self.window_title = "%s: nplots %d" % ( self.name, self.nplots) win = QtWidgets.QWidget() win.setWindowTitle(self.window_title) self.mainwin = win vertLayout = QtWidgets.QVBoxLayout() self.topLayout = None if show_controls: topLayout = QtWidgets.QHBoxLayout() win.start_button = QtWidgets.QPushButton('Start') win.stop_button = QtWidgets.QPushButton('Stop') topLayout.addWidget(win.start_button) topLayout.addWidget(win.stop_button) if add_ppt: win.ppt_button = QtWidgets.QPushButton('Copy to PPT') win.ppt_button.clicked.connect(connect_slot(self.addPPT)) topLayout.addWidget(win.ppt_button) win.averaging_box = QtWidgets.QCheckBox('Averaging') for b in [win.start_button, win.stop_button]: b.setMaximumHeight(24) topLayout.addWidget(win.averaging_box) vertLayout.addLayout(topLayout) self.topLayout = topLayout win.setLayout(vertLayout) self.plotLayout = QtWidgets.QHBoxLayout() vertLayout.addLayout(self.plotLayout) self.lp = [] for ii in range(nplots): lp = livePlot(None, self.station.gates, self.sweepparams, self.sweepranges, show_controls=False, plot_title=str(self.minstrumenthandle) + ' ' + str(self.channels[ii])) self.lp.append(lp) self.plotLayout.addWidget(self.lp[ii].win) if show_controls: self.mainwin.averaging_box.clicked.connect( connect_slot(self.enable_averaging_slot)) self.mainwin.start_button.clicked.connect(connect_slot(self.run)) self.mainwin.stop_button.clicked.connect(connect_slot(self.stop)) self.box = self._create_naverage_box(Naverage=Naverage) self.topLayout.addWidget(self.box) self.setGeometry = self.mainwin.setGeometry self.mainwin.resize(800, 600) self.mainwin.show() self.timer = qtpy.QtCore.QTimer() self.timer.timeout.connect(self.updatebg) self.crosshair(show=crosshair) self.enable_averaging_slot(averaging=averaging) if mouse_click_callback is None: mouse_click_callback = self._update_position for p in self.lp: p.sigMouseClicked.connect(mouse_click_callback) if dorun: self.run()
def _create_gui(self, number_of_plots, show_controls, add_ppt, crosshair, Naverage, averaging): win = QtWidgets.QWidget() win.setWindowTitle(self.window_title) self.mainwin = win vertLayout = QtWidgets.QVBoxLayout() self.topLayout = None if show_controls: topLayout = QtWidgets.QHBoxLayout() win.start_button = QtWidgets.QPushButton('Start') win.stop_button = QtWidgets.QPushButton('Stop') topLayout.addWidget(win.start_button) topLayout.addWidget(win.stop_button) if add_ppt: win.ppt_button = QtWidgets.QPushButton('Copy to PPT') win.ppt_button.clicked.connect(connect_slot(self.addPPT)) topLayout.addWidget(win.ppt_button) win.averaging_box = QtWidgets.QCheckBox('Averaging') for b in [win.start_button, win.stop_button]: b.setMaximumHeight(24) topLayout.addWidget(win.averaging_box) vertLayout.addLayout(topLayout) self.topLayout = topLayout win.setLayout(vertLayout) self.plotLayout = QtWidgets.QHBoxLayout() vertLayout.addLayout(self.plotLayout) self.lp = [] plot_dimension = self.videomode_processor.scan_dimension() for ii in range(number_of_plots): lp = livePlot(self.videomode_processor, self.station.gates, self.sweepparams, self.sweepranges, show_controls=False, plot_title=self.videomode_processor.plot_title(ii), plot_dimension=plot_dimension) self.lp.append(lp) self.plotLayout.addWidget(self.lp[ii].win) if show_controls: self.mainwin.averaging_box.clicked.connect( connect_slot(self.enable_averaging_slot)) self.mainwin.start_button.clicked.connect(connect_slot(self.run)) self.mainwin.stop_button.clicked.connect(connect_slot(self.stop)) self.box = self._create_naverage_box(Naverage=Naverage) self.topLayout.addWidget(self.box) self.setGeometry = self.mainwin.setGeometry self.mainwin.resize(800, 600) self.mainwin.show() self.timer = qtpy.QtCore.QTimer() self.timer.timeout.connect(self.updatebg) self.crosshair(show=crosshair) self.enable_averaging_slot(averaging=averaging)