Beispiel #1
0
    def on_acquisition(self, evt):
        """
        Start the acquisition (really)
        """
        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._show_status_icons(None)

        self.gauge_acq.Range = self.roa_count
        self.gauge_acq.Value = 0

        # Acquire ROAs for all projects
        fs = {}
        for p in self._tab_data_model.projects.value:
            ppath = os.path.join(self.path, p.name.value)  # <acquisition date>/<project name>
            for roa in p.roas.value:
                f = fastem.acquire(roa, ppath, self._main_data_model.ebeam, self._main_data_model.multibeam,
                                   self._main_data_model.descanner, self._main_data_model.mppc,
                                   self._main_data_model.stage, self._main_data_model.ccd,
                                   self._main_data_model.beamshift, self._main_data_model.lens)
                t = roa.estimate_acquisition_time()
                fs[f] = t

        self.acq_future = model.ProgressiveBatchFuture(fs)
        self._fs_connector = ProgressiveFutureConnector(self.acq_future, self.gauge_acq, self.lbl_acqestimate)
        self.acq_future.add_done_callback(self.on_acquisition_done)
Beispiel #2
0
    def on_calibrate(self, evt):
        """
        Start or cancel the calibrations for all set regions of calibrations (ROC) when the calibration
        button is triggered. A progressive future for all rocs is created.
        :param evt: (GenButtonEvent) Button triggered.
        """
        # check if cancelled
        if self._tab_data.is_calibrating.value:
            logging.debug("Calibration was cancelled.")
            align_fastem._executor.cancel()  # all the rest will be handled by on_alignment_done()
            # FIXME cancelling does not yet display the correct label in the gui
            return

        # calibrate
        self._tab_data.is_calibrating.unsubscribe(self._on_is_acquiring)
        # Briefly unsubscribe as don't need to know about this event (is_acquiring = True):
        # It  would disable the calibration button, but want to be able to still cancel calibration.
        self._tab_data.is_calibrating.value = True  # make sure the acquire/tab buttons are disabled
        self._tab_data.is_calibrating.subscribe(self._on_is_acquiring)

        self._on_calibration_state()  # update the controls in the panel

        futures = {}
        try:
            for roc_num in sorted(self.calibration_regions.value.keys()):
                # check if calibration region (ROC) on scintillator is set (undefined = not set)
                roc = self.calibration_regions.value[roc_num]
                if roc.coordinates.value != stream.UNDEFINED_ROI:

                    # calculate the center position of the ROC (half field right/bottom
                    # compared to top/left corner in view)
                    xmin, ymin, _, _ = roc.coordinates.value
                    field_size = (self._tab_data.main.multibeam.resolution.value[0]
                                  * self._tab_data.main.multibeam.pixelSize.value[0],
                                  self._tab_data.main.multibeam.resolution.value[1]
                                  * self._tab_data.main.multibeam.pixelSize.value[1])
                    roc_center = (xmin + field_size[0] / 2, ymin + field_size[1] / 2)

                    # start calibration
                    f = align.fastem.align(self._main_data_model.ebeam, self._main_data_model.multibeam,
                                           self._main_data_model.descanner, self._main_data_model.mppc,
                                           self._main_data_model.stage, self._main_data_model.ccd,
                                           self._main_data_model.beamshift, self._main_data_model.det_rotator,
                                           calibrations=self.calibrations, stage_pos=roc_center)
                    t = align.fastem.estimate_calibration_time(self.calibrations)
                    # also handles cancelling and exceptions
                    f.add_done_callback(partial(self._on_calibration_done, roc_num=roc_num))
                    futures[f] = t

            calib_future = model.ProgressiveBatchFuture(futures)
            # also handles cancelling and exceptions
            calib_future.add_done_callback(self._on_batch_calibrations_done)
            # connect the future to the progress bar and its label
            self._future_connector = ProgressiveFutureConnector(calib_future, self.gauge, self.label, full=False)
        except Exception as ex:  # In case all calibrations failed to start
            logging.warning("Calibration failed with %s", ex)
            for f in futures.keys():
                f.cancel()  # cancel all sub-futures
            self._main_data_model.is_acquiring.value = False
            self._update_calibration_controls("Calibrations failed.")
Beispiel #3
0
    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)