def update_sample_parking(self): ret = question_message_box( self, 'Sample Parking Update', ('Are you sure you want to update sample parking position?\n' + 'You may need to recalibrate the stage/sample positioning')) if ret: sample_park_x = self.sample_stage.x.read()[ self.sample_stage.x.name]['value'] sample_park_y = self.sample_stage.y.read()[ self.sample_stage.y.name]['value'] self.spinBox_sample_x.setValue(sample_park_x) self.spinBox_sample_y.setValue(sample_park_y) self.settings.setValue('sample_park_x', sample_park_x) self.settings.setValue('sample_park_y', sample_park_y) stage_park_x = self.spinBox_stage_x.value() stage_park_y = self.spinBox_stage_y.value() self.sample_positioner = SamplePositioner( self.RE, self.sample_stage, stage_park_x, stage_park_y, delta_first_holder_x=sample_park_x - stage_park_x, delta_first_holder_y=sample_park_y - stage_park_y)
def reset_queue(self): ret = question_message_box( self, 'Warning', 'Are you sure? Reseeting the queue will clear all plans and stop its execution' ) if ret: self.plan_processor.reset()
def getX(self, event): if event.button == 3: ret = question_message_box( self, 'Setting edge position', 'Would you like to set the edge to {:.0f}?'.format( event.xdata)) if ret: self.edit_E0.setText(str(int(np.round(event.xdata))))
def shutters_open(self): for shutter in [ self.shutter_dictionary[shutter] for shutter in self.shutter_dictionary if self.shutter_dictionary[shutter].shutter_type != 'SP' ]: if shutter.state.get(): ret = question_message_box(self, 'Photon shutter closed', 'Proceed with the shutter closed?') if not ret: print('Aborted!') return False break return True
def bender_scan(self): ret = question_message_box( self, 'Warning', 'For best results make sure that there is no sample in the beam') if ret: # element = self.comboBox_reference_foils.currentText() # edge = self.edge_dict[element] element, edge = self.widget_energy_selector.element_edge # message_box('Select relevant foil', 'Scans will be performed on the foil that is currently in the beam') plan_name = 'bender_scan_plan_bundle' plan_kwargs = {'element': element, 'edge': edge} plan_gui_services = ['error_message_box'] # self.plan_processor.add_plans([{'plan_name' : plan_name, # 'plan_kwargs' : plan_kwargs, # 'plan_gui_services' : plan_gui_services}]) self.plan_processor.add_plan_and_run_if_idle( plan_name, plan_kwargs, plan_gui_services)
def calibrate_offset(self): ret = question_message_box( self, 'Confirmation', 'Are you sure you would like to calibrate it?') if not ret: print('[E0 Calibration] Aborted!') return False new_value = str( self.hhm.angle_offset.value - (xray.energy2encoder(float(self.edit_E0.text( )), self.hhm.pulses_per_deg) - xray.energy2encoder( float(self.edit_ECal.text()), self.hhm.pulses_per_deg)) / self.hhm.pulses_per_deg) if self.set_new_angle_offset(new_value): return print('[E0 Calibration] New value: {}\n[E0 Calibration] Completed!'. format(new_value))
def re_abort(self): hhm_flying = self.hhm.abort_trajectory( ) # it only aborts if there is a trajectory running # print(f'>>>>>>>>>>>>> HHM_FLYING = {hhm_flying}') # print(f'>>>>>>>>>>>>> HHM_FLYING_STATUS = {self.hhm.flying_status}') if not hhm_flying: if self.RE.state != 'idle': # self.push_re_abort.setEnabled(0) self.RE.abort() self.RE.state == 'abort' self.RE.is_aborted = True ret = question_message_box(self, 'Aborting the scan', 'Would you like to clear/reset queue?') self.plan_processor.pause_plan_list() if ret: self.plan_processor.reset() else: self.plan_processor.pause_plan_list() if not self.plan_processor.RE_is_running: self.plan_processor.update_status('idle')
def energy_calibration(self): ret = question_message_box( self, 'Warning', 'For best results make sure that there is no sample in the beam') if ret: # element = self.comboBox_reference_foils.currentText() # edge = self.edge_dict[element] element, edge = self.widget_energy_selector.element_edge # plan_name = 'calibrate_mono_energy_plan' # plan_kwargs = {'element' : element, 'edge' : edge} # plan_gui_services = ['beamline_setup_plot_energy_calibration_data', 'error_message_box'] # self.plan_processor.add_plan_and_run_if_idle(plan_name, plan_kwargs, plan_gui_services=plan_gui_services) plan_name = 'calibrate_mono_energy_plan_bundle' some_gui_services = [ 'beamline_setup_plot_energy_calibration_data', 'error_message_box' ] plan_kwargs = { 'element': element, 'edge': edge, 'plan_gui_services': some_gui_services } self.plan_processor.add_plan_and_run_if_idle( plan_name, plan_kwargs, ['question_message_box'])
def question_message_box_func(self, *args): return question_message_box(self, *args)
def run_scan(self): ignore_shutter = False energy_grid = [] time_grid = [] for shutter in [ self.shutter_dictionary[shutter] for shutter in self.shutter_dictionary if self.shutter_dictionary[shutter].shutter_type != 'SP' ]: if shutter.state.value: ret = question_message_box( self, 'Shutter closed', 'Would you like to run the scan with the shutter closed?') if not ret: print('Aborted!') return False ignore_shutter = True break # Send sampling time to the pizzaboxes: value = int( round( float(self.analog_samp_time) / self.adc_list[0].sample_rate.get() * 100000)) for adc in self.adc_list: adc.averaging_points.put(str(value)) for enc in self.enc_list: enc.filter_dt.put(float(self.enc_samp_time) * 100000) # not needed at QAS this is a detector if self.xia is not None: if self.xia.input_trigger is not None: self.xia.input_trigger.unit_sel.put(1) # ms, not us self.xia.input_trigger.period_sp.put(int(self.xia_samp_time)) name_provided = self.parameter_values[0].text() if name_provided: timenow = datetime.datetime.now() print('\nStarting scan at {}'.format(timenow.strftime("%H:%M:%S"), flush='true')) start_scan_timer = timer() # Get parameters from the widgets and organize them in a dictionary (run_params) run_parameters = return_parameters_from_widget( self.parameter_descriptions, self.parameter_values, self.parameter_types) # Run the scan using the dict created before self.run_mode_uids = [] self.parent_gui.run_mode = 'run' plan_key = self.comboBox_scan_type.currentText() if plan_key == 'Step scan': update_figure( [self.figure.ax2, self.figure.ax1, self.figure.ax3], self.toolbar, self.canvas) energy_grid, time_grid = generate_energy_grid( float(self.e0), float(self.edit_preedge_start.text()), float(self.edit_xanes_start.text()), float(self.edit_xanes_end.text()), float(self.edit_exafs_end.text()), float(self.edit_preedge_spacing.text()), float(self.edit_xanes_spacing.text()), float(self.edit_exafs_spacing.text()), float(self.edit_preedge_dwell.text()), float(self.edit_xanes_dwell.text()), float(self.edit_exafs_dwell.text()), int(self.comboBox_exafs_dwell_kpower.currentText())) #print(energy_grid) plan_func = self.plan_funcs[plan_key] LivePlots = [ XASPlot(self.apb.ch1_mean.name, self.apb.ch2_mean.name, 'Transmission', self.hhm[0].energy.name, log=True, ax=self.figure.ax1, color='b'), XASPlot(self.apb.ch2_mean.name, self.apb.ch3_mean.name, 'Reference', self.hhm[0].energy.name, log=True, ax=self.figure.ax1, color='r'), XASPlot(self.apb.ch4_mean.name, self.apb.ch1_mean.name, 'Fluorescence', self.hhm[0].energy.name, log=False, ax=self.figure.ax1, color='g'), ] print(f'Edge at execution {self.edge}') RE_args = [ plan_func(**run_parameters, ignore_shutter=ignore_shutter, energy_grid=energy_grid, time_grid=time_grid, element=self.element, e0=self.e0, edge=self.edge, ax=self.figure.ax1, stdout=self.parent_gui.emitstream_out) ] if plan_key.lower() == 'step scan': RE_args.append(LivePlots) self.run_mode_uids = self.RE(*RE_args) timenow = datetime.datetime.now() print('Scan complete at {}'.format(timenow.strftime("%H:%M:%S"))) stop_scan_timer = timer() print('Scan duration {} s'.format(stop_scan_timer - start_scan_timer)) if self.rr_token is not None: self.RE.unsubscribe(self.rr_token) else: message_box('Error', 'Please provide the name for the scan')