def test_estimateTiledAcquisitionTime(self): """Test estimated acquisition time for overview imaging.""" # small area on center scintillator (~3x4 tiles) scintillator5_area = (-0.002, -0.002, 0.002, 0.002) # l, b, r, t self.stream.emitter.dwellTime.value = 1e-6 # s est_time_1 = fastem.estimateTiledAcquisitionTime(self.stream, self.stage, scintillator5_area) # increase dwell time self.stream.emitter.dwellTime.value = 2e-6 # s est_time_2 = fastem.estimateTiledAcquisitionTime(self.stream, self.stage, scintillator5_area) # check that estimated time increases with dwell time self.assertGreater(est_time_2, est_time_1)
def update_acquisition_time(self, _=None): lvl = None # icon status shown if not self._tab_data_model.is_calib_done.value: lvl = logging.WARN txt = "System is not calibrated." elif not self._main_data_model.active_scintillators.value: lvl = logging.WARN txt = "No scintillator loaded (go to Chamber tab)." elif not self._tab_data_model.selected_scintillators.value: lvl = logging.WARN txt = "No scintillator selected for overview acquisition." else: acq_time = 0 # Add up the acquisition time of all the selected scintillators for num in self._tab_data_model.selected_scintillators.value: center = self._tab_data_model.main.scintillator_positions[num] sz = self._tab_data_model.main.scintillator_size coords = (center[0] - sz[0] / 2, center[1] - sz[1] / 2, center[0] + sz[0] / 2, center[1] + sz[1] / 2) acq_time += fastem.estimateTiledAcquisitionTime(self._tab_data_model.streams.value[0], self._main_data_model.stage, coords) acq_time = math.ceil(acq_time) # round a bit pessimistic txt = u"Estimated time is {}." txt = txt.format(units.readable_time(acq_time)) logging.debug("Updating status message %s, with level %s", txt, lvl) self._set_status_message(txt, lvl)
def test_overview_acquisition(self): s = stream.SEMStream( "Single beam", self.sed, self.sed.data, self.ebeam, focuser=self. efocuser, # Not used during acquisition, but done by the GUI hwemtvas={"scale", "dwellTime", "horizontalFoV"}) # This should be used by the acquisition s.dwellTime.value = 1e-6 # s # Use random settings and check they are overridden by the overview acquisition s.scale.value = (2, 2) s.horizontalFoV.value = 20e-6 # m # Known position of the center scintillator scintillator5_area = (-0.007, -0.007, 0.007, 0.007) # l, b, r, t # Small area for DEBUG (3x3) # scintillator5_area = (-0.002, -0.002, 0.002, 0.002) # l, b, r, t est_time = fastem.estimateTiledAcquisitionTime(s, self.stage, scintillator5_area) # don't use for DEBUG example self.assertGreater(est_time, 10) # It should take more than 10s! (expect ~5 min) before_start_t = time.time() f = fastem.acquireTiledArea(s, self.stage, scintillator5_area) time.sleep(1) start_t, end_t = f.get_progress() self.assertGreater(start_t, before_start_t) # don't use for DEBUG example self.assertGreater(end_t, time.time() + 10) # Should report still more than 10s overview_da = f.result() self.assertGreater(overview_da.shape[0], 2000) self.assertGreater(overview_da.shape[1], 2000) # Check the final area fits the requested area, with possibly a little bit of margin bbox = img.getBoundingBox(overview_da) fov = bbox[2] - bbox[0], bbox[3] - bbox[1] logging.debug("Got image of size %s, with FoV %s = %s", overview_da.shape, fov, bbox) self.assertLessEqual(bbox[0], scintillator5_area[0]) # Left self.assertLessEqual(bbox[1], scintillator5_area[1]) # Bottom self.assertGreaterEqual(bbox[2], scintillator5_area[2]) # Right self.assertGreaterEqual(bbox[3], scintillator5_area[3]) # Top
def on_acquisition(self, evt): """ Start the acquisition (really) """ self.update_acquisition_time( ) # make sure we show the right label if the previous acquisition failed self._main_data_model.is_acquiring.value = True self.btn_acquire.Enable(False) self.btn_cancel.Enable(True) self.btn_cancel.Show() self.gauge_acq.Show() self.gauge_acq.Range = len( self._tab_data_model.selected_scintillators.value) self.gauge_acq.Value = 0 # Acquire ROAs for all projects acq_futures = {} for num in self._tab_data_model.selected_scintillators.value: center = self._tab_data_model.main.scintillator_positions[num] sz = self._tab_data_model.main.scintillator_size coords = (center[0] - sz[0] / 2, center[1] - sz[1] / 2, center[0] + sz[0] / 2, center[1] + sz[1] / 2) try: f = fastem.acquireTiledArea( self._tab_data_model.streams.value[0], self._main_data_model.stage, coords) t = fastem.estimateTiledAcquisitionTime( self._tab_data_model.streams.value[0], self._main_data_model.stage, coords) except Exception: logging.exception("Failed to start overview acquisition") # Try acquiring the other continue f.add_done_callback(partial(self.on_acquisition_done, num=num)) acq_futures[f] = t if acq_futures: self.acq_future = model.ProgressiveBatchFuture(acq_futures) self.acq_future.add_done_callback(self.full_acquisition_done) self._fs_connector = ProgressiveFutureConnector( self.acq_future, self.gauge_acq, self.lbl_acqestimate) else: # In case all acquisitions failed to start self._main_data_model.is_acquiring.value = False self._reset_acquisition_gui("Acquisition failed (see log panel).", level=logging.WARNING)