Example #1
0
    def __init__(self, crystal, Patt, refls, data_image, szx=30, szy=30):
        """
        Some tools for jittering the indexing solution
        to try and come up with a better solution
        THis uses simtbx wrapped into the Patt object
        :param crystal: dxtbx crystal
        :param Patt: an instance of PatternFactory that has been
            primed (Patt.primer has been run)
            Note, primer sets the Amatrix, Fcalcs, energy, and flux
        :param refls: strong spots, we will simulate there vicinity
            and use the simultion overlap as a proxy for indexing
            solution quality
        :param data_image: the raw data image that is used to compute
            overlap
        """
        detector = Patt.detector[Patt.panel_id]
        self.FS = detector.get_fast_axis()
        self.SS = detector.get_slow_axis()
        self.A = sqr(crystal.get_A())
        self.U = sqr(crystal.get_U())
        self.B = sqr(crystal.get_B())
        self.s0 = Patt.beam.get_s0()
        self.ucell_abc = list(crystal.unit_cell().parameters())[:3]
        self.crystal = crystal

        self.Patt = Patt
        self.data = data_image
        self.rois = spot_utils.get_spot_roi(
            refls,
            dxtbx_image_size=detector.get_image_size(),
            szx=szx,
            szy=szy)
        self.spotX, self.spotY, _ = spot_utils.xyz_from_refl(refls)
        self.spot_mask = spot_utils.strong_spot_mask(refls, self.data.shape)
        self.counts = spot_utils.count_roi_overlap(self.rois,
                                                   img_size=self.data.shape)
        if np.any(self.counts > 0):
            self.should_norm = True
        else:
            self.should_norm = False
        pts = [[(i - .5, j - .5), (i - .5, j + .5), (i + .5, j + .5),
                (i + .5, j - .5), (i - .5, j - .5)] for i, j in zip(x, y)]

        for p in pts:
            path = plt.mpl.path.Path(p)
            patch = plt.mpl.patches.PathPatch(path, fc=fc, ec=ec, lw=lw)
            patches.append(patch)

    return patches


Malls = {}
for pid, img in izip(pids, pan_imgs):
    panel = detector[pid]
    rois = spot_utils.get_spot_roi(reflsPP[pid],
                                   dxtbx_image_size=panel.get_image_size(),
                                   szx=szx,
                                   szy=szy)
    counts = spot_utils.count_roi_overlap(rois, img_size=img.shape)

    roi_pp.append(rois)
    counts_pp.append(counts)

    spot_masks = spot_utils.strong_spot_mask(reflsPP[pid],
                                             img_sh,
                                             as_composite=False)

    # composite mask
    Mall = np.any(spot_masks, axis=0)

    yall, xall = np.where(Mall)  # use comp mask to determine the boundary