Exemple #1
0
    def get_tiles(self, crop_to=None, full_frames=False):
        stackheight = self.tileshape.nav.size

        num_tiles = self.partfile.fields['num_images'] // stackheight

        tshape = self.tileshape.flatten_nav()
        sig_origin = (0, 0)
        if crop_to is not None and tshape.sig != crop_to.shape.sig:
            tshape = Shape(tuple(tshape.nav) + tuple(crop_to.shape.sig),
                           sig_dims=tshape.sig.dims)
            sig_origin = crop_to.origin[1:]
        data = np.ndarray(tshape, dtype=self.dtype)
        for t in range(num_tiles):
            tile_slice = Slice(
                origin=(t * stackheight + self.slice.origin[0], ) + sig_origin,
                shape=tshape)
            if crop_to is not None:
                intersection = tile_slice.intersection_with(crop_to)
                if intersection.is_null():
                    continue
            self.partfile.read_frames(num=stackheight,
                                      offset=t * stackheight,
                                      out=data,
                                      crop_to=crop_to)
            assert all(
                [item > 0 for item in tile_slice.shift(self.slice).shape])
            assert all(
                [item >= 0 for item in tile_slice.shift(self.slice).origin])

            yield DataTile(data=data, tile_slice=tile_slice)
Exemple #2
0
def test_shift_2():
    s1 = Slice(origin=(2, 2, 0, 0), shape=Shape((1, 1, 2, 2), sig_dims=2))

    s2 = Slice(origin=(1, 1, 0, 0), shape=Shape((1, 1, 4, 4), sig_dims=2))

    shifted = s1.shift(s2)
    assert shifted.origin == (1, 1, 0, 0)