def acquire_ov(base_dir, selection, sem, stage, ovm, cs, queue, trigger): # Update current xy position: stage.get_xy() queue.put('UPDATE XY') trigger.s.emit() success = True if selection == -1: # acquire all OVs start, end = 0, ovm.get_number_ov() else: start, end = selection, selection + 1 # acquire only one OV # Acquisition loop: for i in range(start, end): queue.put( utils.format_log_entry('3VIEW: Moving stage to OV %d position.' % i)) trigger.s.emit() # Move to OV stage coordinates: stage.move_to_xy(cs.get_ov_centre_s(i)) # Check to see if error ocurred: if stage.get_error_state() > 0: success = False stage.reset_error_state() if success: # update stage position in GUI: queue.put('UPDATE XY') trigger.s.emit() # Set specified OV frame settings: sem.apply_frame_settings(ovm.get_ov_size_selector(i), ovm.get_ov_pixel_size(i), ovm.get_ov_dwell_time(i)) save_path = base_dir + '\\workspace\\OV' + str(i).zfill(3) + '.bmp' queue.put(utils.format_log_entry('SEM: Acquiring OV %d.' % i)) trigger.s.emit() # Indicate the overview being acquired in the viewport queue.put('ACQ IND OV' + str(i)) trigger.s.emit() success = sem.acquire_frame(save_path) # Remove indicator colour queue.put('ACQ IND OV' + str(i)) trigger.s.emit() # Show updated OV: queue.put('MV UPDATE OV' + str(i)) trigger.s.emit() if success: ovm.update_ov_file_list(i, save_path) if not success: break # leave loop if error has occured if success: queue.put('OV SUCCESS') trigger.s.emit() else: queue.put('OV FAILURE') trigger.s.emit()
def _add_to_main_log(self, msg): """Add entry to the log in the main window""" msg = utils.format_log_entry(msg) self.main_controls_trigger.transmit(msg)
def acquire_ov(base_dir, selection, sem, stage, ovm, img_inspector, main_controls_trigger, viewport_trigger): # Update current XY stage position stage.get_xy() success = True if selection == -1: # acquire all OVs start = 0 end = ovm.number_ov else: # acquire only one OV start = selection end = selection + 1 # Acquisition loop for ov_index in range(start, end): if not ovm[ov_index].active: continue main_controls_trigger.transmit( utils.format_log_entry('STAGE: Moving to OV %d position.' % ov_index)) # Move to OV stage coordinates stage.move_to_xy(ovm[ov_index].centre_sx_sy) # Check to see if error ocurred if stage.error_state != Error.none: stage.reset_error_state() sleep(1) # Try again stage.move_to_xy(ovm[ov_index].centre_sx_sy) if stage.error_state != Error.none: stage.reset_error_state() main_controls_trigger.transmit( utils.format_log_entry( 'STAGE: Second attempt to move to OV %d position failed.' % ov_index)) success = False if success: # Update stage position in Main Controls GUI and Viewport main_controls_trigger.transmit('UPDATE XY') sleep(0.1) main_controls_trigger.transmit('DRAW VP') # Use custom focus settings for this OV if available ov_wd = ovm[ov_index].wd_stig_xy[0] if ov_wd > 0: sem.set_wd(ov_wd) stig_x, stig_y = ovm[ov_index].wd_stig_xy[1:3] sem.set_stig_xy(stig_x, stig_y) main_controls_trigger.transmit( utils.format_log_entry( 'SEM: Using specified ' + utils.format_wd_stig(ov_wd, stig_x, stig_y))) # Set specified OV frame settings sem.apply_frame_settings(ovm[ov_index].frame_size_selector, ovm[ov_index].pixel_size, ovm[ov_index].dwell_time) save_path = os.path.join(base_dir, 'workspace', 'OV' + str(ov_index).zfill(3) + '.bmp') main_controls_trigger.transmit( utils.format_log_entry('SEM: Acquiring OV %d.' % ov_index)) # Indicate the overview being acquired in the viewport viewport_trigger.transmit('ACQ IND OV' + str(ov_index)) success = sem.acquire_frame(save_path) # Remove indicator colour viewport_trigger.transmit('ACQ IND OV' + str(ov_index)) _, _, _, load_error, _, grab_incomplete = ( img_inspector.load_and_inspect(save_path)) if load_error or grab_incomplete: # Try again sleep(0.5) main_controls_trigger.transmit( utils.format_log_entry( 'SEM: Second attempt: Acquiring OV %d.' % ov_index)) viewport_trigger.transmit('ACQ IND OV' + str(ov_index)) success = sem.acquire_frame(save_path) viewport_trigger.transmit('ACQ IND OV' + str(ov_index)) sleep(1) _, _, _, load_error, _, grab_incomplete = ( img_inspector.load_and_inspect(save_path)) if load_error or grab_incomplete: success = False if load_error: cause = 'load error' elif grab_incomplete: cause = 'grab incomplete' else: cause = 'acquisition error' main_controls_trigger.transmit( utils.format_log_entry( f'SEM: Second attempt to acquire OV {ov_index} ' f'failed ({cause}).')) if success: ovm[ov_index].vp_file_path = save_path # Show updated OV viewport_trigger.transmit('DRAW VP') if not success: break # leave loop if error has occured if success: viewport_trigger.transmit('REFRESH OV SUCCESS') else: viewport_trigger.transmit('REFRESH OV FAILURE')
def add_to_main_log(self, msg): """Add entry to the log in the main window""" msg = utils.format_log_entry(msg) # Send entry to main window via queue and trigger: self.queue.put(msg) self.trigger.s.emit()