Exemple #1
0
    def find_spots(self, min_spot_size=2, max_spot_size=100):
        from dials.algorithms.spot_finding.threshold import XDSThresholdStrategy
        from dials.model.data import PixelList
        from dials.model.data import PixelListLabeller

        image = self.raw_data
        mask = self.imageset.get_mask(0)[0]

        threshold_image = XDSThresholdStrategy()

        threshold_mask = threshold_image(image, mask)
        plist = PixelList(0, image, threshold_mask)

        pixel_labeller = PixelListLabeller()
        pixel_labeller.add(plist)

        creator = flex.PixelListShoeboxCreator(pixel_labeller, 0, 0, True,
                                               min_spot_size, max_spot_size,
                                               False)
        shoeboxes = creator.result()

        # turns out we need to manually filter the list to get a sensible answer
        size = creator.spot_size()
        big = size > max_spot_size
        small = size < min_spot_size
        bad = big | small
        shoeboxes = shoeboxes.select(~bad)

        centroid = shoeboxes.centroid_valid()
        intensity = shoeboxes.summed_intensity()
        observed = flex.observation(shoeboxes.panels(), centroid, intensity)

        reflections = flex.reflection_table(observed, shoeboxes)
        return reflections
def find_spots(image, mask, min_spot_size=1, max_spot_size=1000):
    from dials.algorithms.spot_finding.threshold import XDSThresholdStrategy
    from dials.model.data import PixelList
    from dials.model.data import PixelListLabeller

    threshold_image = XDSThresholdStrategy()

    threshold_mask = threshold_image(image, mask)
    plist = PixelList(0, image, threshold_mask)

    pixel_labeller = PixelListLabeller()

    pixel_labeller.add(plist)

    creator = flex.PixelListShoeboxCreator(
        pixel_labeller,
        0,  # panel
        0,  # zrange
        True,  # twod
        min_spot_size,  # min_pixels
        max_spot_size,  # max_pixels
        False,
    )
    shoeboxes = creator.result()

    centroid = shoeboxes.centroid_valid()
    intensity = shoeboxes.summed_intensity()
    observed = flex.observation(shoeboxes.panels(), centroid, intensity)

    return flex.reflection_table(observed, shoeboxes)
Exemple #3
0
    def find_spots(self, min_spot_size=2, max_spot_size=100):
        """
        Find the strong spots on the image

        """
        from dials.algorithms.spot_finding.threshold import DispersionThresholdStrategy
        from dials.model.data import PixelList
        from dials.model.data import PixelListLabeller
        from dials.array_family import flex

        print("")
        print("-" * 80)
        print(" Finding strong spots")
        print("-" * 80)
        print("")

        # Instantiate the threshold function
        threshold = DispersionThresholdStrategy()

        # Get the raw data and image mask
        image = self.experiment.imageset.get_raw_data(0)[0]
        mask = self.experiment.imageset.get_mask(0)[0]

        # Threshold the image and create the pixel labeller
        threshold_mask = threshold(image, mask)
        pixel_labeller = PixelListLabeller()
        pixel_labeller.add(PixelList(0, image, threshold_mask))

        # Create the shoebox list from the pixel list
        creator = flex.PixelListShoeboxCreator(
            pixel_labeller,
            0,  # Panel number
            0,  # Z start
            True,  # 2D
            self.params.spot_finding.min_spot_size,  # Min Pixels
            self.params.spot_finding.max_spot_size,  # Max Pixels
            False,
        )  # Find hot pixels
        shoeboxes = creator.result()

        # Filter the list to remove large and small spots
        size = creator.spot_size()
        large = size > self.params.spot_finding.max_spot_size
        small = size < self.params.spot_finding.min_spot_size
        bad = large | small
        shoeboxes = shoeboxes.select(~bad)
        print("Discarding %d spots with < %d pixels" %
              (small.count(True), self.params.spot_finding.min_spot_size))
        print("Discarding %d spots with > %d pixels" %
              (large.count(True), self.params.spot_finding.max_spot_size))

        # Extract the strong spot information
        centroid = shoeboxes.centroid_valid()
        intensity = shoeboxes.summed_intensity()
        observed = flex.observation(shoeboxes.panels(), centroid, intensity)

        # Create the reflection list
        self.reflections = flex.reflection_table(observed, shoeboxes)
        print("Using %d strong spots" % len(self.reflections))
Exemple #4
0
    def __call__(self, imageset, pixel_labeller):
        """
        Convert the pixel list to shoeboxes
        """
        from dxtbx.imageset import ImageSequence

        # Extract the pixel lists into a list of reflections
        shoeboxes = flex.shoebox()
        spotsizes = flex.size_t()
        hotpixels = tuple(flex.size_t() for i in range(len(imageset.get_detector())))
        if isinstance(imageset, ImageSequence):
            scan = imageset.get_scan()
            if scan.is_still():
                twod = True
            else:
                twod = False
        else:
            twod = True
        for i, (p, hp) in enumerate(zip(pixel_labeller, hotpixels)):
            if p.num_pixels() > 0:
                creator = flex.PixelListShoeboxCreator(
                    p,
                    i,  # panel
                    0,  # zrange
                    twod,  # twod
                    self.min_spot_size,  # min_pixels
                    self.max_spot_size,  # max_pixels
                    self.write_hot_pixel_mask,
                )
                shoeboxes.extend(creator.result())
                spotsizes.extend(creator.spot_size())
                hp.extend(creator.hot_pixels())
        logger.info("")
        logger.info("Extracted {} spots".format(len(shoeboxes)))

        # Get the unallocated spots and print some info
        selection = shoeboxes.is_allocated()
        shoeboxes = shoeboxes.select(selection)
        ntoosmall = (spotsizes < self.min_spot_size).count(True)
        ntoolarge = (spotsizes > self.max_spot_size).count(True)
        assert ntoosmall + ntoolarge == selection.count(False)
        logger.info(
            "Removed %d spots with size < %d pixels" % (ntoosmall, self.min_spot_size)
        )
        logger.info(
            "Removed %d spots with size > %d pixels" % (ntoolarge, self.max_spot_size)
        )

        # Return the shoeboxes
        return shoeboxes, hotpixels
Exemple #5
0
def pixel_list_to_shoeboxes(
    imageset: ImageSet,
    pixel_labeller: Iterable[PixelListLabeller],
    min_spot_size: int,
    max_spot_size: int,
    write_hot_pixel_mask: bool,
) -> Tuple[flex.shoebox, Tuple[flex.size_t, ...]]:
    """Convert a pixel list to shoeboxes"""
    # Extract the pixel lists into a list of reflections
    shoeboxes = flex.shoebox()
    spotsizes = flex.size_t()
    hotpixels = tuple(flex.size_t()
                      for i in range(len(imageset.get_detector())))
    if isinstance(imageset, ImageSequence):
        twod = imageset.get_scan().is_still()
    else:
        twod = True
    for i, (p, hp) in enumerate(zip(pixel_labeller, hotpixels)):
        if p.num_pixels() > 0:
            creator = flex.PixelListShoeboxCreator(
                p,
                i,  # panel
                0,  # zrange
                twod,  # twod
                min_spot_size,  # min_pixels
                max_spot_size,  # max_pixels
                write_hot_pixel_mask,
            )
            shoeboxes.extend(creator.result())
            spotsizes.extend(creator.spot_size())
            hp.extend(creator.hot_pixels())
    logger.info("\nExtracted %d spots", len(shoeboxes))

    # Get the unallocated spots and print some info
    selection = shoeboxes.is_allocated()
    shoeboxes = shoeboxes.select(selection)
    ntoosmall = (spotsizes < min_spot_size).count(True)
    ntoolarge = (spotsizes > max_spot_size).count(True)
    assert ntoosmall + ntoolarge == selection.count(False)
    logger.info("Removed %d spots with size < %d pixels", ntoosmall,
                min_spot_size)
    logger.info("Removed %d spots with size > %d pixels", ntoolarge,
                max_spot_size)

    # Return the shoeboxes
    return shoeboxes, hotpixels
Exemple #6
0
def find_spots(image):
    from dials.algorithms.spot_finding.threshold import DispersionThresholdStrategy
    from dials.model.data import PixelList
    from dials.model.data import PixelListLabeller

    thresholder = DispersionThresholdStrategy(gain=1)
    mask = image.as_1d() >= 0  # flex.bool(image.size(), True)
    mask.reshape(flex.grid(*image.focus()))

    threshold_mask = thresholder(image, mask=mask)
    plist = PixelList(0, image, threshold_mask)

    pixel_labeller = PixelListLabeller()
    pixel_labeller.add(plist)

    creator = flex.PixelListShoeboxCreator(pixel_labeller, 0, 0, True, 2, 100,
                                           False)
    shoeboxes = creator.result()
    return shoeboxes
Exemple #7
0
def image_to_shoeboxes(image):
    """For a given image, find spots 2 - 100 pixels im size, assuming a gain
    of 1, return the list of spot shoeboxes. Also assumes valid intensities in
    range 0...N."""

    thresholder = DispersionThresholdStrategy(gain=1)

    mask = image.as_1d() >= 0
    mask.reshape(flex.grid(*image.focus()))

    threshold_mask = thresholder(image, mask=mask)
    plist = PixelList(0, image, threshold_mask)

    pixel_labeller = PixelListLabeller()
    pixel_labeller.add(plist)

    creator = flex.PixelListShoeboxCreator(pixel_labeller, 0, 0, True, 2, 100,
                                           False)
    shoeboxes = creator.result()
    return shoeboxes
Exemple #8
0
def find(greyscale_flex, params, mask=None):
    '''Find stars on input greyscale flex image.'''

    from dials.algorithms.spot_finding.threshold import \
        DispersionThresholdStrategy
    from dials.model.data import PixelList
    from dials.model.data import PixelListLabeller
    from dials.array_family import flex

    thresholder = DispersionThresholdStrategy(gain=params.gain)
    if not mask:
        mask = flex.bool(greyscale_flex.size(), True)
    mask.reshape(flex.grid(*greyscale_flex.focus()))

    threshold_mask = thresholder(greyscale_flex, mask=mask)
    plist = PixelList(0, greyscale_flex, threshold_mask)

    pixel_labeller = PixelListLabeller()
    pixel_labeller.add(plist)

    creator = flex.PixelListShoeboxCreator(pixel_labeller, 0, 0, True,
                                           params.min_size, params.max_size,
                                           False)
    shoeboxes = creator.result()

    # remove nonsense
    size = creator.spot_size()
    big = size > params.max_size
    small = size < params.min_size
    bad = big | small
    shoeboxes = shoeboxes.select(~bad)

    centroid = shoeboxes.centroid_valid()
    intensity = shoeboxes.summed_intensity()
    observed = flex.observation(shoeboxes.panels(), centroid, intensity)

    stars = flex.reflection_table(observed, shoeboxes)
    return stars