Пример #1
0
 def _onSpotImage(self, df, data):
     """
     Receives the Spot image data
     """
     if self.bgsub:
         data = Subtract(data, self.bg_image)
     self._spot_images.append(data)
     self._ccd_done.set()
     logging.debug("Got Spot image!")
Пример #2
0
    def _onCCDImage(self, df, data):
        """
        Receives the CCD data
        """
        try:
            if data.metadata[model.MD_ACQ_DATE] < self._min_acq_time:
                logging.debug("Received a CCD image too early")
                return
        except KeyError:
            pass

        if self.bgsub:
            self._optical_image = Subtract(data, self.bg_image)
        else:
            self._optical_image = data
        self._ccd_done.set()
        logging.debug("Got CCD image!")
Пример #3
0
def SubstractBackground(ccd, det_dataflow=None):
    """
    Performs optical acquisition with background substraction. Particularly
    used in order to eliminate the source background in Delphi.
    ccd (model.DigitalCamera)
    det_dataflow (model.DataFlow): dataflow of se- or bs- detector
    enabled (boolean): if True, apply background substraction
    returns (model.DataArray):
        Image with substracted background
    """
    if det_dataflow is not None:
        bg_image = ccd.data.get(asap=False)
        det_dataflow.subscribe(_discard_data)
        image = ccd.data.get(asap=False)
        ret_data = Subtract(image, bg_image)
        det_dataflow.unsubscribe(_discard_data)
        return ret_data
    else:
        image = ccd.data.get(asap=False)
        return image
Пример #4
0
def AcquireNoBackground(ccd, dfbkg=None):
    """
    Performs optical acquisition with background subtraction if possible.
    Particularly used in order to eliminate the e-beam source background in the
    Delphi.
    ccd (model.DigitalCamera): detector from which to acquire an image
    dfbkg (model.DataFlow or None): dataflow of se- or bs- detector to
    start/stop the source. If None, a standard acquisition is performed (without
    background subtraction)
    returns (model.DataArray):
        Image (with subtracted background if requested)
    """
    if dfbkg is not None:
        bg_image = ccd.data.get(asap=False)
        dfbkg.subscribe(_discard_data)
        image = ccd.data.get(asap=False)
        dfbkg.unsubscribe(_discard_data)
        ret_data = Subtract(image, bg_image)
        return ret_data
    else:
        image = ccd.data.get(asap=False)
        return image
Пример #5
0
def FindEbeamCenter(ccd, detector, escan):
    """
    Locate the center of the SEM image by setting the SEM to spot mode and
    measuring the position of the spot on the CCD. It is mostly targeted at
    doing it fast. In particular it doesn’t do any focusing or multiple
    iterations with feedback loop.
    ccd (model.DigitalCamera):    The ccd
    detector (model.Detector):    The se-detector
    escan (model.Emitter):    The e-beam scanner
    return (tuple of 2 floats): x, y position of the spot relative to the
     center of the CCD.
    raise:
        LookupError: if the spot cannot be found
    """
    logging.debug("Starting ebeam spot detection...")
    # save the hw settings
    prev_exp = ccd.exposureTime.value
    prev_bin = ccd.binning.value
    prev_res = ccd.resolution.value

    try:
        # set the CCD to maximum resolution
        ccd.binning.value = (1, 1)
        ccd.resolution.value = ccd.resolution.range[1]

        # set ebeam to spot mode
        # resolution -> translation: order matters
        escan.resolution.value = (1, 1)

        # put a not too short dwell time to avoid acquisition to keep repeating,
        # and not too long to avoid using too much memory for acquiring one point.
        escan.dwellTime.value = escan.dwellTime.range[1]  # s
        # Subscribe to actually set the spot mode
        detector.data.subscribe(discard_data)

        exp = 0.1  # start value
        prev_img = None
        while exp < 2:  # above 2 s it means something went wrong
            ccd.exposureTime.value = exp

            img = ccd.data.get(asap=False)
            if prev_img is not None:
                img += prev_img  # accumulate, to increase the signal

            try:
                coord = FindSpot(img, sensitivity_limit=10)
            except LookupError:
                # spot was not found, subtract background and try again
                logging.debug("Subtracting background image")
                detector.data.unsubscribe(discard_data)
                bg_image = ccd.data.get(asap=False)
                detector.data.subscribe(discard_data)
                img = Subtract(img, bg_image)
                try:
                    coord = FindSpot(img, sensitivity_limit=10)
                except LookupError:
                    # try again with longer exposure time
                    prev_img = img
                    exp *= 2
                    continue

            # found a spot! => convert position to meters from center
            return _ConvertCoordinates(coord, img)

    finally:
        detector.data.unsubscribe(discard_data)
        ccd.exposureTime.value = prev_exp
        ccd.binning.value = prev_bin
        ccd.resolution.value = prev_res

    raise LookupError("Failed to locate spot after exposure time %g s" % exp)