def __init__(self, ctr_client: si_tt.Client, ui='count_monitor', logger_client=None, server_port=None, combined_channel=False, config=None): """ Constructor for CountMonitor script :param ctr_client: instance of hardware client for counter :param gui_client: (optional) instance of client of desired output GUI :param logger_client: (obj) instance of logger client. :param server_port: (int) port number of script server :combined_channel: (bool) If true, show additional trace with summed counts. """ self._ctr = ctr_client self.log = logger_client self.combined_channel = combined_channel self._bin_width = None self._n_bins = None self._ch_list = None self._plot_list = None # List of channels to assign to each plot (e.g. [[1,2], [3,4]]) self._plots_assigned = [ ] # List of plots on the GUI that have been assigned if self.combined_channel: ui = 'count_monitor_combined' else: ui = 'count_monitor' # Instantiate GUI window self.gui = Window(gui_template=ui, host=get_ip(), port=server_port) # Setup stylesheet. self.gui.apply_stylesheet() if self.combined_channel: num_plots = 3 else: num_plots = 2 # Get all GUI widgets self.widgets = get_gui_widgets(self.gui, graph_widget=num_plots, number_label=8, event_button=num_plots, legend_widget=num_plots) # Load config self.config = {} if config is not None: self.config = load_script_config(script='monitor_counts', config=config, logger=self.logger_client) if not 'name' in self.config: self.config.update({'name': f'monitor{np.random.randint(1000)}'})
def __init__(self, nanopos_client: smaract_mcs2.Client, attocube_client: attocube_anc300.Client, gui='positioner_control_mixed', log_client=None, config=None, port=None): """ Instantiates the controller :param nanopos_client: (pylabnet.network.client_server.smaract_mcs2.Client) :param gui: name of .ui file ot use :param log_client: (pylabnet.utils.logging.logger.LogClient) :param config: (str) name of config file, optional :param port: (int) port number for update/script server """ self.pos = nanopos_client self.attocube = attocube_client self.log = LogHandler(logger=log_client) self.gui = Window(gui_template=gui, host=get_ip(), port=port) self.gui.apply_stylesheet() self.widgets = get_gui_widgets(self.gui, **self.WIDGET_DICT) self.save_params = generate_widgets( dict(n_steps=self.NUM_CHANNELS, amplitude=self.NUM_CHANNELS, frequency=self.NUM_CHANNELS, velocity=self.NUM_CHANNELS)) # Additional attributes self.prev_amplitude = [50] * self.NUM_CHANNELS self.prev_frequency = [30] * self.NUM_CHANNELS self.prev_velocity = [100] * self.NUM_CHANNELS self.prev_voltage = [50] * self.NUM_CHANNELS self.voltage_override = False self.config = config self.lock_status = [False] * int(self.NUM_CHANNELS / 3) self.released = [False] * self.NUM_CHANNELS self.gui.config_label.setText(self.config) # Configure all button and parameter updates self._setup_gui() # Setup shortcut to use keyboard to step fiber self.press_right = QShortcut(QKeySequence('Right'), self.gui) self.press_left = QShortcut(QKeySequence('Left'), self.gui) self.press_up = QShortcut(QKeySequence('Up'), self.gui) self.press_down = QShortcut(QKeySequence('Down'), self.gui) self.press_up_z = QShortcut(QKeySequence('PgUp'), self.gui) self.press_down_z = QShortcut(QKeySequence('PgDown'), self.gui) self.widgets['keyboard_change_combo'].currentIndexChanged.connect( self._bind_arrow_keys)
def __init__(self, filterwheel1, filterwheel2, gui='toptica_filterwheels', logger=None, port=None): self.filterwheel1 = filterwheel1 self.filterwheel2 = filterwheel2 self.log = LogHandler(logger) # Setup GUI self.gui = Window(gui_template=gui, host=get_ip(), port=port) # Get Widgets self.widgets = get_gui_widgets(self.gui, comboBox_filter1=1, comboBox_filter2=1, nd_label=1) # Retrieve filter dicts. filters1 = filterwheel1.get_filter_dict() filters2 = filterwheel2.get_filter_dict() # Fill comboboxes. self.widgets['comboBox_filter1'].addItems(filters1.values()) self.widgets['comboBox_filter2'].addItems(filters2.values()) # Get current fitler positions self.current_pos_1 = filterwheel1.get_pos() self.current_pos_2 = filterwheel2.get_pos() # Set comboboxes to current filter positions. self.widgets['comboBox_filter1'].setCurrentIndex( int(self.current_pos_1) - 1) self.widgets['comboBox_filter2'].setCurrentIndex( int(self.current_pos_2) - 1) # Connect change events self.widgets['comboBox_filter1'].currentTextChanged.connect( lambda: self.change_filter(filter_index=1)) self.widgets['comboBox_filter2'].currentTextChanged.connect( lambda: self.change_filter(filter_index=2)) # Update OD reading self.update_od() # Setup stylesheet. self.gui.apply_stylesheet()
def __init__(self, dlc: toptica_dl_pro.Client, gui='toptica_control', logger=None, port=None): """ Initializes toptica specific parameters :param dlc: DLC client for the Toptica laser :param gui: .ui file to use :param logger: LogClient for logging purposes :param port: port number of script server """ self.log = LogHandler(logger) # Setup GUI self.gui = Window(gui_template=gui, host=get_ip(), port=port) self.widgets = get_gui_widgets(gui=self.gui, on_off=2, temperature=2, temperature_actual=2, current=2, current_actual=2, offset=2, amplitude=2, frequency=2, scan=2, update_temp=2, update_current=2, update_params=1) self.dlc = dlc self.offset = 65 self.amplitude = 100 self.scan = [False, False] self.emission = [False, False] # Setup stylesheet. self.gui.apply_stylesheet() self._setup_GUI()
def __init__(self, pm_client, gui='fiber_coupling', logger=None, calibration=None, name=None, port=None): """ Instantiates a monitor for 2-ch power meter with GUI :param pm_clients: (client, list of clients) clients of power meter :param gui_client: client of monitor GUI :param logger: instance of LogClient :calibration: (float) Calibration value for power meter. :name: (str) Humand-readable name of the power meter. """ self.log = LogHandler(logger) self.gui = Window(gui_template=gui, host=get_ip(), port=port) self.gui.apply_stylesheet() self.wavelength = [] self.calibration = calibration self.name = name self.ir_index, self.rr_index = [], [] self.pm = pm_client self.running = False self.num_plots = 3 # Get all GUI widgets self.widgets = get_gui_widgets(self.gui, graph_widget=self.num_plots, number_widget=4, label_widget=2, name_label=1, combo_widget=2) self._initialize_gui()
def __init__(self, wlm_client, logger_client, gui='wavemeter_monitor', ao_clients=None, display_pts=5000, threshold=0.0002, port=None, params=None, three_lasers=False): """ Instantiates WlmMonitor script object for monitoring wavemeter :param wlm_client: (obj) instance of wavemeter client :param gui_client: (obj) instance of GUI client. :param logger_client: (obj) instance of logger client. :param ao_clients: (dict, optional) dictionary of ao client objects with keys to identify. Exmaple: {'ni_usb_1': nidaqmx_usb_client_1, 'ni_usb_2': nidaqmx_usb_client_2, 'ni_pxi_multi': nidaqmx_pxi_client} :param display_pts: (int, optional) number of points to display on plot :param threshold: (float, optional) threshold in THz for lock error signal :param port: (int) port number for update server :param params: (dict) see set_parameters below for details :three_lasers: (bool) If three lasers are in use (instead of 2) """ self.channels = [] if three_lasers: gui = 'wavemeter_monitor_3lasers' self.wlm_client = wlm_client self.ao_clients = ao_clients self.display_pts = display_pts self.threshold = threshold self.log = LogHandler(logger_client) # Instantiate gui self.gui = Window( gui_template=gui, host=get_ip(), port=port, ) # Setup stylesheet. self.gui.apply_stylesheet() if three_lasers: self.widgets = get_gui_widgets(gui=self.gui, freq=3, sp=3, rs=3, lock=3, error_status=3, graph=6, legend=6, clear=6, zero=6, voltage=3, error=3) else: self.widgets = get_gui_widgets(gui=self.gui, freq=2, sp=2, rs=2, lock=2, error_status=2, graph=4, legend=4, clear=4, zero=4, voltage=2, error=2) # Set parameters self.set_parameters(**params) # Configure plots # Get actual legend widgets self.widgets['legend'] = [ get_legend_from_graphics_view(legend) for legend in self.widgets['legend'] ] self.widgets['curve'] = [] self.initialize_channels() for channel in self.channels: self.update_parameters( dict(channel=channel.number, setpoint=channel.data[-1]))
def __init__(self, config, ao_client=None, ai_client=None, hd=None, check_aom=False, logger=None): """Instantiates LaserStabilizer script object for stabilizing the laser :param config: (str) name of config file """ # Instantiate GUI self.gui = Window(gui_template='power_stabilizer', host=get_ip()) self.widgets = get_gui_widgets(self.gui, p_setpoint=1, p_outputVoltage=1, label_power=1, config=1, graph=2, legend=2, hardware_control=1, clear=1, start=1, stop=1) self._ao_client = ao_client self._ai_client = ai_client self._hd = hd self.log = logger self.config = config self.check_aom = check_aom self._load_config_file() #Now initialize control/output voltage to 0, and set up label self._curr_output_voltage = self.widgets['p_outputVoltage'].value( ) #Stores current output voltage that is outputted by the AO self.widgets['p_outputVoltage'].valueChanged.connect( self._set_output_voltage_from_label) # self._ao_client.set_ao_voltage(self._ao_channel, self._curr_output_voltage) #Update the input power label self._last_power_text_update = 2 self.read_power() self._initialize_graphs() #Setting up hardware power control options self.widgets['hardware_control'].enabled = False self._under_hardware_control = False self.widgets['hardware_control'].toggled.connect( self._update_hardware_control_from_gui) #Finally hookup the final buttons self.widgets['start'].clicked.connect( lambda: self.start(update_st_gui=True)) self.widgets['stop'].clicked.connect(self.stop) self.widgets['clear'].clicked.connect( lambda: self._clear_data_plots(display_pts=1000)) #Initially the program starts in the "unlocked" phase self._is_stabilizing = False
def __init__(self, logger=None, channels=['Channel 1'], clients={}, config=None, fast=True): """ Instantiates controller (only 1D data supported so far) :param logger: instance of LogClient :param channels: (list) list of channel names :param config: (str) name of config file :param fast: (bool) whether to operate in fast mode fast mode only updates heat maps at the end of each scan (this speeds things up) """ self.config = load_script_config('scan1d', config, logger=logger) if 'sweep_type' in self.config.keys(): self.sweep_type = self.config['sweep_type'] else: self.sweep_type = 'triangle' super().__init__(logger, channels, sweep_type=self.sweep_type) self.module = None # Instantiate GUI self.gui = Window(gui_template='scan_1d', host=get_ip(), max=True) self.widgets = get_gui_widgets(self.gui, p_min=1, p_max=1, pts=1, config=1, graph=2, legend=2, clients=1, exp=1, exp_preview=1, configure=1, run=1, autosave=1, save_name=1, save=1, reps=1, rep_tracker=1, avg=2) # Configure default parameters self.min = self.widgets['p_min'].value() self.max = self.widgets['p_max'].value() self.pts = self.widgets['pts'].value() self.reps = self.widgets['reps'].value() self.data_fwd = [] self.data_fwd_2nd_reading = [] ### ADDED self.data_bwd = [] self.avg_fwd = [] self.avg_fwd_2nd_reading = [] ### ADDED self.avg_bwd = [] self.fit_popup = None self.p0_fwd = None self.p0_bwd = None self.x_fwd = self._generate_x_axis() if self.sweep_type != 'sawtooth': self.x_bwd = self._generate_x_axis(backward=True) else: self.x_bwd = self._generate_x_axis() self.fast = fast # Configure list of experiments self.widgets['config'].setText(config) self.exp_path = self.config['exp_path'] model = QtWidgets.QFileSystemModel() model.setRootPath(self.exp_path) model.setNameFilterDisables(False) model.setNameFilters(['*.py']) self.widgets['exp'].setModel(model) self.widgets['exp'].setRootIndex(model.index(self.exp_path)) self.widgets['exp'].hideColumn(1) self.widgets['exp'].hideColumn(2) self.widgets['exp'].hideColumn(3) self.widgets['exp'].clicked.connect(self.display_experiment) # Configure list of clients self.clients = clients for client_entry in self.config['servers']: client_type = client_entry['type'] client_config = client_entry['config'] client = find_client(clients=self.clients, settings=client_config, client_type=client_type, client_config=client_config, logger=self.log) if (client == None): client_name_concat = client_type client_item = QtWidgets.QListWidgetItem(client_name_concat) client_item.setForeground(Qt.gray) client_item.setToolTip(str("Disconnected")) self.widgets['clients'].addItem(client_item) else: self.log.info(client) client_name_concat = f"{client_type}_{client_config}" client_item = QtWidgets.QListWidgetItem(client_name_concat) client_item.setToolTip(str(client)) self.widgets['clients'].addItem(client_item) #Checking for any missing clients, and adding them as greyed out on the list of clients # Manually add logger to client self.clients['logger'] = logger # Configure button self.widgets['configure'].clicked.connect(self.configure_experiment) self.widgets['run'].clicked.connect(self.run_pressed) self.widgets['autosave'].toggled.connect(self._update_autosave) self.widgets['save'].pressed.connect( lambda: self.save(filename=self.widgets['save_name'].text(), directory=self.config['save_path'])) self.widgets['reps'].valueChanged.connect(self.set_reps) self.widgets['avg'][0].clicked.connect( lambda: self._clear_show_trace(0)) self.widgets['avg'][1].clicked.connect( lambda: self._clear_show_trace(1)) self.gui.fit.clicked.connect(self.fit_config) # Create legends self.widgets['curve'] = [] for index in range(len(self.widgets['graph'])): self.widgets['legend'][index] = get_legend_from_graphics_view( self.widgets['legend'][index]) # Configure hmaps self.widgets['hmap'] = [] for index in range(2): # Configure Hmap to work the way we want hmap = pg.ImageView(view=pg.PlotItem()) self.gui.graph_layout.insertWidget(2 * index + 1, hmap) hmap.setPredefinedGradient('inferno') hmap.show() hmap.view.setAspectLocked(False) hmap.view.invertY(False) self.widgets['hmap'].append(hmap) # Setup stylesheet. self.gui.apply_stylesheet()