def generate_shoebox(self, bbox, centre, intensity, mask=False): from dials.model.data import Shoebox from dials.algorithms.shoebox import MaskCode shoebox = Shoebox() shoebox.bbox = bbox shoebox.allocate() for i in range(len(shoebox.mask)): shoebox.mask[i] = MaskCode.Valid | MaskCode.Foreground shoebox.data = self.gaussian( shoebox.size(), 1.0, [c - o for c, o in zip(centre[::-1], shoebox.offset())], [s / 8.0 for s in shoebox.size()]) if mask: shoebox.mask = self.create_mask( shoebox.size(), [c - o for c, o in zip(centre[::-1], shoebox.offset())], MaskCode.Valid | MaskCode.Foreground) tot = 0 mask_code = MaskCode.Valid | MaskCode.Foreground for i in range(len(shoebox.data)): if shoebox.mask[i] & mask_code == mask_code: tot += shoebox.data[i] if tot > 0: shoebox.data *= intensity / tot return shoebox
def test_offset(): for i in range(10): x0 = random.randint(0, 1000) y0 = random.randint(0, 1000) z0 = random.randint(0, 1000) x1 = random.randint(1, 10) + x0 y1 = random.randint(1, 10) + y0 z1 = random.randint(1, 10) + z0 shoebox = Shoebox((x0, x1, y0, y1, z0, z1)) assert shoebox.xoffset() == x0 assert shoebox.yoffset() == y0 assert shoebox.zoffset() == z0 assert shoebox.offset() == (z0, y0, x0)
def tst_offset(self): from random import randint from dials.model.data import Shoebox for i in range(10): x0 = randint(0, 1000) y0 = randint(0, 1000) z0 = randint(0, 1000) x1 = randint(1, 10) + x0 y1 = randint(1, 10) + y0 z1 = randint(1, 10) + z0 shoebox = Shoebox((x0, x1, y0, y1, z0, z1)) assert (shoebox.xoffset() == x0) assert (shoebox.yoffset() == y0) assert (shoebox.zoffset() == z0) assert (shoebox.offset() == (z0, y0, x0)) # Test passed print 'OK'