def synthetic_stack( cls, num_round: int = 4, num_ch: int = 4, num_z: int = 12, tile_height: int = 50, tile_width: int = 40, tile_fetcher: TileFetcher = None, ) -> "ImageStack": """generate a synthetic ImageStack Returns ------- ImageStack : imagestack containing a tensor whose default shape is (2, 3, 4, 30, 20) and whose default values are all 1. """ if tile_fetcher is None: tile_fetcher = tile_fetcher_factory( OnesTile, False, (tile_height, tile_width), ) collection = build_image( 1, num_round, num_ch, num_z, tile_fetcher, ) tileset = list(collection.all_tilesets())[0][1] return ImageStack(tileset)
def test_missing_extras(): """ If the extras are not present on some of the tiles, it should still work. """ class OnesTilesWithExtrasMostly(OnesTile): def __init__(self, fov, r, ch, z, extras: dict) -> None: super().__init__((10, 10)) self.fov = fov self._extras = extras @property def extras(self): if self.fov == 0: return None return self._extras tile_fetcher = tile_fetcher_factory(OnesTilesWithExtrasMostly, True, {'random_key': { 'hello': "world", }}) stack = ImageStack.synthetic_stack( num_round=NUM_ROUND, num_ch=NUM_CH, num_z=NUM_Z, tile_fetcher=tile_fetcher, ) table = stack.tile_metadata assert len(table) == NUM_ROUND * NUM_CH * NUM_Z
def test_conflict(): """ Tiles that have extras that conflict with indices should produce an error. """ tile_fetcher = tile_fetcher_factory(OnesTilesWithExtras, False, {Indices.ROUND: { 'hello': "world", }}) stack = ImageStack.synthetic_stack( num_round=NUM_ROUND, num_ch=NUM_CH, num_z=NUM_Z, tile_fetcher=tile_fetcher, ) with pytest.raises(ValueError): stack.tile_metadata
def test_metadata(): """ Normal situation where all the tiles have uniform keys for both indices and extras. """ tile_fetcher = tile_fetcher_factory(OnesTilesWithExtras, False, {'random_key': { 'hello': "world", }}) stack = ImageStack.synthetic_stack( num_round=NUM_ROUND, num_ch=NUM_CH, num_z=NUM_Z, tile_fetcher=tile_fetcher, ) table = stack.tile_metadata assert len(table) == NUM_ROUND * NUM_CH * NUM_Z