def batch_parse_and_execute(hhm, sample_stage, batch, plans_dict): tm = trajectory_manager(hhm) for ii in range(batch.rowCount()): experiment = batch.item(ii) print(experiment.item_type) repeat = experiment.repeat print(repeat) for jj in range(experiment.rowCount()): sample = experiment.child(jj) print(' ' + sample.name) print(' ' + str(sample.x)) print(' ' + str(sample.y)) yield from mv(sample_stage.x, sample.x, sample_stage.y, sample.y) for kk in range(sample.rowCount()): scan = sample.child(kk) traj_index = scan.trajectory print(' ' + scan.scan_type) plan = plans_dict[scan.scan_type] kwargs = { 'name': sample.name, 'comment': '', 'delay': 0, 'n_cycles': repeat } tm.init(traj_index + 1) yield from plan(**kwargs)
def __init__(self, hhm=None, aux_plan_funcs={}, *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) self.addCanvas() self.element = 'Scandium (21)' self.e0 = '4492' self.edge = 'K' self.widget_energy_selector = widget_energy_selector.UIEnergySelector() self.layout_energy_selector_trajectory.addWidget( self.widget_energy_selector) #communication between the Energy Selector widget and Trajectory Manager self.widget_energy_selector.edit_E0.textChanged.connect(self.update_E0) self.widget_energy_selector.comboBox_edge.currentTextChanged.connect( self.update_edge) self.widget_energy_selector.comboBox_element.currentTextChanged.connect( self.update_element) self.hhm = hhm self.hhm.angle_offset.subscribe(self.update_angle_offset) self.traj_manager = trajectory_manager(hhm) self.comboBox_slot_to_load_trajectory.addItems( ['1', '2', '3', '4', '5', '6', '7', '8']) self.comboBox_slot_to_init_trajectory.addItems( ['1', '2', '3', '4', '5', '6', '7', '8']) self.comboBox_slot_to_init_trajectory.setCurrentIndex( self.traj_manager.current_lut() - 1) try: pass # self.trajectories = self.traj_manager.read_info(silent=True) # self.trajectories = collections.OrderedDict(sorted(self.trajectories.items())) except OSError as err: print('Error loading:', err) self.traj_creator = trajectory(self.hhm) self.trajectory_path = self.hhm.traj_filepath self.push_build_trajectory.clicked.connect(self.build_trajectory) self.push_save_trajectory.clicked.connect(self.save_trajectory) self.push_update_offset.clicked.connect(self.update_offset) self.push_select_traj_file.clicked.connect(self.get_traj_names) self.push_load_trajectory.clicked.connect(self.load_trajectory) self.push_init_trajectory.clicked.connect(self.init_trajectory) self.push_read_traj_info.clicked.connect(self.read_trajectory_info) self.push_plot_traj.clicked.connect(self.plot_traj_file) self.push_plot_traj.setDisabled(True) self.push_save_trajectory.setDisabled(True) self.checkBox_traj_single_dir.stateChanged.connect( self.update_repetitions_spinbox) self.checkBox_traj_single_dir.stateChanged.connect( self.checkBox_traj_revert.setEnabled)
def __init__(self, excel_file='/nsls2/xf08id/Sandbox/ISS-Sample-Spreadsheet.xlsx', skiprows=1, hhm=None): self.excel_file = excel_file self.name = os.path.basename(excel_file) self._skiprows = skiprows self.hhm = hhm self.trajectory_manager = trajectory_manager(self.hhm) self.experiments = [] self.trajectory_folder = '/nsls2/xf08id/trajectory' # Loaded pandas dataframe: self.experiment_table = None # List of all found trajectories from the file: self.trajectories = [] # Unique trajectories derived from trajectories: self.unique_trajectories = [] self.trajectory_filenames = [] self.read_excel()
def __init__(self, plan_funcs, service_plan_funcs, hhm, sample_stage=None, *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) self.plan_funcs = plan_funcs self.service_plan_funcs = service_plan_funcs self.plan_funcs_names = plan_funcs.keys() self.service_plan_funcs_names = service_plan_funcs.keys() self.sample_stage = sample_stage self.batch_mode_uids = [] self.traj_manager = trajectory_manager(hhm) self.treeView_batch = elements.TreeView(self, 'all') self.gridLayout_batch_definition.addWidget(self.treeView_batch, 0, 0) # sample functions self.push_create_batch_experiment.clicked.connect( self.create_batch_experiment) self.model_batch = QtGui.QStandardItemModel(self) self.treeView_batch.header().hide() ''' WIP add horizontal scrollbar self.treeView_batch.header().horizontalScrollBar() ''' self.treeView_batch.setModel(self.model_batch) self.model_samples = QtGui.QStandardItemModel(self) self.push_create_sample.clicked.connect(self.create_new_sample) self.push_delete_sample.clicked.connect(self.delete_sample) self.push_get_sample_position.clicked.connect(self.get_sample_position) self.push_get_sample_position_map_start.clicked.connect( self.get_sample_position) self.push_get_sample_position_map_end.clicked.connect( self.get_sample_position) self.listView_samples.setDragEnabled(True) self.listView_samples.setDragDropMode( QtWidgets.QAbstractItemView.DragOnly) self.model_scans = QtGui.QStandardItemModel(self) self.push_create_scan.clicked.connect(self.create_new_scan) self.push_delete_scan.clicked.connect(self.delete_scan) self.listView_scans.setDragDropMode( QtWidgets.QAbstractItemView.DragOnly) self.push_batch_delete.clicked.connect(self.delete_batch_element) self.push_batch_info.clicked.connect(self.batch_info) self.push_create_measurement.clicked.connect(self.create_measurement) self.push_create_service.clicked.connect(self.create_service) self.push_create_map.clicked.connect(self.create_map) self.comboBox_scans.addItems(self.plan_funcs_names) self.comboBox_service_plan.addItems(self.service_plan_funcs_names) self.comboBox_service_plan.currentIndexChanged.connect( self.populate_service_parameters) self.push_update_traj_list.clicked.connect(self.update_batch_traj) self.last_lut = 0 self.service_parameter_values = [] self.service_parameter_descriptions = [] self.populate_service_parameters(0) self.update_batch_traj()
def adjust_ic_gains( **kwargs): sys.stdout = kwargs.pop('stdout', sys.stdout) if 'detector_names' not in kwargs: detectors = [pba1.adc7, pba2.adc6, pba1.adc1, pba1.adc6] else: detectors = [] for d in kwargs['detector_names']: detectors.append(globals()[d]) #TODO replace with dictionary current_lut = int(hhm.lut_number_rbv.value) traj_manager = trajectory_manager(hhm) info = traj_manager.read_info(silent=True) if 'max' not in info[str(current_lut)] or 'min' not in info[str(current_lut)]: raise Exception( 'Could not find max or min information in the trajectory.' ' Try sending it again to the controller.') e_min = int(info[str(current_lut)]['min']) e_max = int(info[str(current_lut)]['max']) try: yield from bps.mv(shutter_ph_2b, 'Open') except FailedStatus: print('ERROR: Photon shutter failed to open') shutter.open() scan_positions = np.arange(e_max + 50, e_min - 50, -50) plan = bp.list_scan(detectors, hhm.energy, scan_positions) flyers = [] for detector in detectors: if hasattr(detector, 'kickoff'): flyers.append(detector) for jj in range(2): plan = bp.list_scan(detectors, hhm.energy, scan_positions) #print(f'F>>>>>>>>>>> {flyers}\n D>>>>>>>>>>>>>>>>.{detectors}') uid = (yield from bpp.fly_during_wrapper(plan, flyers)) #print(f' >>>>>> UID {uid}') table = db[uid].table() for det in detectors: name = f'{det.name}_volt' current_gain = det.amp.get_gain()[0] if det.polarity == 'neg': trace_extreme = table[name].min() else: trace_extreme = table[name].max() print(f'Extreme value {trace_extreme} for detector {det.channel}') if abs(trace_extreme) > 3.7: print(f'Decreasing gain for detector {det.channel}') yield from det.amp.set_gain_plan(current_gain-1, False) elif abs(trace_extreme) <= 3.7 and abs(trace_extreme) > 0.35: print(f'Correct gain for detector {det.channel}') elif abs(trace_extreme) <= 0.35: print(f'Increasing gain for detector {det.channel}') yield from det.amp.set_gain_plan(current_gain + 1, False) #print(f'F2>>>>>>>>>>> {flyers}\n D2>>>>>>>>>>>>>>>>.{detectors}') yield from bps.sleep(2) shutter.close() print('[Adjust Gain] Complete\n') remove_pb_files(uid)
def batch_parse_and_run(self, hhm, sample_stage, batch, plans_dict): sys.stdout = self.parent_gui.emitstream_out tm = trajectory_manager(hhm) for ii in range(batch.rowCount()): experiment = batch.item(ii) repeat = experiment.repeat for indx in range(repeat): if repeat > 1: exper_index = f'{(indx+1):04d}' else: exper_index = '' for jj in range(experiment.rowCount()): step = experiment.child(jj) if step.item_type == 'sample': sample = step #randomization delta_x, delta_y = self.randomize_position() yield from mv(sample_stage.x, sample.x + delta_x, sample_stage.y, sample.y + delta_y) for kk in range(sample.rowCount()): child_item = sample.child(kk) if child_item.item_type == 'scan': scan = child_item traj_index = scan.trajectory plan = plans_dict[scan.scan_type] sample_name = '{} {} {}'.format( sample.name, scan.name, exper_index) self.label_batch_step.setText(sample_name) kwargs = { 'name': sample_name, 'comment': '', 'delay': 0, 'n_cycles': scan.repeat, 'stdout': self.parent_gui.emitstream_out } if self.hhm.lut_number_rbv.read( )['hhm_lut_number_rbv'][ 'value'] != traj_index + 1: tm.init(traj_index + 1) yield from plan(**kwargs) elif child_item.item_type == 'service': service = child_item kwargs = { 'stdout': self.parent_gui.emitstream_out } yield from service.service_plan( **service.service_params, **kwargs) elif step.item_type == 'scan': scan = step traj_index = scan.trajectory if self.hhm.lut_number_rbv.read( )['hhm_lut_number_rbv']['value'] != traj_index + 1: tm.init(traj_index + 1) for kk in range(step.rowCount()): child_item = scan.child(kk) if child_item.item_type == 'sample': sample = child_item # randomization delta_x, delta_y = self.randomize_position() yield from mv(sample_stage.x, sample.x + delta_x, sample_stage.y, sample.y + delta_y) plan = plans_dict[scan.scan_type] sample_name = '{} {} {}'.format( sample.name, scan.name, exper_index) self.label_batch_step.setText(sample_name) kwargs = { 'name': sample_name, 'comment': '', 'delay': 0, 'n_cycles': scan.repeat, 'stdout': self.parent_gui.emitstream_out } yield from plan(**kwargs) elif child_item == 'service': service = child_item kwargs = { 'stdout': self.parent_gui.emitstream_out } yield from service.service_plan( **service.service_params, **kwargs) elif step.item_type == 'service': kwargs = {'stdout': self.parent_gui.emitstream_out} yield from step.service_plan(**step.service_params, **kwargs) self.label_batch_step.setText('idle')
def batch_parse_and_run(self, hhm, sample_stage, batch, plans_dict): sys.stdout = self.parent_gui.emitstream_out tm = trajectory_manager(hhm) for ii in range(batch.rowCount()): experiment = batch.item(ii) repeat = experiment.repeat for indx in range(repeat): exper_index = '' if repeat > 1: exper_index = f'{(indx+1):04d}' for jj in range(experiment.rowCount()): print(experiment.rowCount()) step = experiment.child(jj) if step.item_type == 'sample': sample = step print(' ' + sample.name) print(' ' + str(sample.x)) print(' ' + str(sample.y)) yield from mv(sample_stage.x, sample.x, sample_stage.y, sample.y) #print(f'moving to {sample.x}, {sample y}') for kk in range(sample.rowCount()): scan = sample.child(kk) traj_index = scan.trajectory print(' ' + scan.scan_type) plan = plans_dict[scan.scan_type] sample_name = '{} {} {}'.format( sample.name, scan.name, exper_index) print(sample_name) kwargs = { 'name': sample_name, 'comment': '', 'delay': 0, 'n_cycles': scan.repeat, 'stdout': self.parent_gui.emitstream_out } tm.init(traj_index + 1) yield from plan(**kwargs) elif step.item_type == 'scan': scan = step traj_index = scan.trajectory print(' ' + scan.scan_type) tm.init(traj_index + 1) for kk in range(step.rowCount()): sample = scan.child(kk) yield from mv(sample_stage.x, sample.x, sample_stage.y, sample.y) plan = plans_dict[scan.scan_type] print(' ' + sample.name) print(' ' + str(sample.x)) print(' ' + str(sample.y)) sample_name = '{} {} {}'.format( sample.name, scan.name, exper_index) print(sample_name) kwargs = { 'name': sample_name, 'comment': '', 'delay': 0, 'n_cycles': repeat, 'stdout': self.parent_gui.emitstream_out } yield from plan(**kwargs) elif step.item_type == 'service': yield from step.service_plan(**step.service_params)
def __init__(self, plan_funcs, service_plan_funcs, motors_dict, hhm, RE, db, sample_stage, parent_gui, *args, **kwargs): super().__init__(*args, **kwargs) self.setupUi(self) #self.addCanvas() self.plan_funcs = plan_funcs self.service_plan_funcs = service_plan_funcs self.plan_funcs_names = plan_funcs.keys() self.service_plan_funcs_names = service_plan_funcs.keys() self.motors_dict = motors_dict self.mot_list = self.motors_dict.keys() self.mot_sorted_list = list(self.mot_list) self.mot_sorted_list.sort() self.hhm = hhm self.traj_manager = trajectory_manager(hhm) self.RE = RE self.db = db self.sample_stage = sample_stage self.parent_gui = parent_gui self.batch_mode_uids = [] self.sample_stage = sample_stage self.widget_batch_manual = widget_batch_manual.UIBatchManual( self.plan_funcs, self.service_plan_funcs, self.hhm, self.motors_dict, sample_stage=self.sample_stage) self.layout_batch_manual.addWidget(self.widget_batch_manual) self.layout_batch_manual self.batch_running = False self.batch_pause = False self.batch_abort = False self.batch_results = {} self.push_run_batch_manual.clicked.connect(self.start_batch) #setting up sample table pushButtons_load = [ self.pushButton_load_sample_def_11, self.pushButton_load_sample_def_12, self.pushButton_load_sample_def_13, self.pushButton_load_sample_def_21, self.pushButton_load_sample_def_22, self.pushButton_load_sample_def_23, self.pushButton_load_sample_def_31, self.pushButton_load_sample_def_32, self.pushButton_load_sample_def_33 ] for button in pushButtons_load: button.clicked.connect(self.load_sample_definition) #%getattr(self, f'pushButton_show_sample_def_{i}') pushButtons_show = [ self.pushButton_show_sample_def_11, self.pushButton_show_sample_def_12, self.pushButton_show_sample_def_13, self.pushButton_show_sample_def_21, self.pushButton_show_sample_def_22, self.pushButton_show_sample_def_23, self.pushButton_show_sample_def_31, self.pushButton_show_sample_def_32, self.pushButton_show_sample_def_33 ] for button in pushButtons_show: button.clicked.connect(self.show_sample_definition) self.coordinates = [ '11', '12', '13', '21', '22', '23', '31', '32', '33' ] for x in self.coordinates: getattr( self, 'pushButton_update_reference_{}'.format(x)).clicked.connect( self.update_reference) self.push_run_spreadsheet_batch.clicked.connect( self.run_spreadsheet_batch) self.tableWidget_sample_def.setColumnCount(7) self.tableWidget_sample_def.setHorizontalHeaderLabels([ "Proposal", "SAF", "Sample name", "Composition", "Element", "Edge", "Energy" ]) widths = [80, 80, 200, 90, 80, 80, 80] for j in range(7): self.tableWidget_sample_def.setColumnWidth(j, widths[j])