def test_block_get_bcube(): bcube = BoundingCube(0, 1, 0, 1, 0, 1, mip=0) start, stop = 10, 11 block = Block(start=start, stop=stop, src_stack=Stack(), dst_stack=Stack(), previous=None) adj_bcube = bcube.reset_coords(zs=start, ze=stop, in_place=False) assert adj_bcube == block.get_bcube(bcube) assert bcube.z != (start, stop)
def break_bcube_into_chunks(self, bcube, chunk_xy, chunk_z, mip, flatten=True, chunk_xy_step=None, chunk_z_step=None, **kwargs): """Default breaking up of a bcube into smaller bcubes (chunks). Returns a list of chunks Args: bcube: BoundingBox for region to be broken into chunks chunk_size: tuple for dimensions of chunk that bbox will be broken into mip: int for MIP level at which chunk_xy is dspecified """ indexed_bcube = self.indexing_scheme(bcube, mip, kwargs) x_range = indexed_bcube.x_range(mip=mip) y_range = indexed_bcube.y_range(mip=mip) z_range = indexed_bcube.z_range() if chunk_xy_step is None: chunk_xy_step = chunk_xy if chunk_z_step is None: chunk_z_step = chunk_z xy_chunks = [] flat_chunks = [] for zs in range(z_range[0], z_range[1], chunk_z_step): xy_chunks.append([]) for xs in range(x_range[0], x_range[1], chunk_xy_step): xy_chunks[-1].append([]) for ys in range(y_range[0], y_range[1], chunk_xy_step): chunk = BoundingCube(xs, xs + chunk_xy, ys, ys + chunk_xy, zs, zs + chunk_z, mip=mip) xy_chunks[-1][-1].append(chunk) flat_chunks.append(chunk) if flatten: return flat_chunks else: return xy_chunks
def __init__(self, data_mip_ranges=None, **kwargs): super().__init__(**kwargs) self.declared_write_mips = [] self.declared_write_bcube = BoundingCube(0, 0, 0, 0, 0, 0, 0)
def test_combine_masks(): src_path = "file:///tmp/cloudvolume/combine_mask_test/src" dst_path = "file:///tmp/cloudvolume/combine_mask_test/mask/dst" make_test_dataset(path=src_path) src_stack = Stack() backend = str_to_backend("cv") layer = backend.create_layer( path=src_path, layer_type="mask", name="M", reference=None, ) src_stack.add_layer(layer) dst_layer = src_stack.create_unattached_sublayer( name="dst", layer_type="mask", custom_folder="file:///tmp/cloudvolume/combine_mask_test", ) exp = { "inputs": [ { "inputs": [ { "weight": 1, "key": "M", "offset": -1 }, { "weight": 1, "key": "M", "offset": 0 }, ], "threshold": 1, }, { "inputs": [ { "weight": 1, "key": "M", "offset": 0 }, { "weight": 1, "key": "M", "offset": 1 }, ], "threshold": 1, }, ], "threshold": 0, } bcube = BoundingCube(0, 1, 0, 1, 0, 16, mip=0) task = CombineMasksTask(src_stack=src_stack, exp=exp, dst_layer=dst_layer, mip=0, bcube=bcube, pad=0) task.execute() D = MiplessCloudVolume(path=dst_path) O = np.zeros((1, 1, 6), dtype=np.uint8) O[:, :, 1] = 1 O[:, :, 2] = 1 assert np.all(D[0][:][:, :, :, 0] == O) delete_layer(dst_path[7:]) delete_layer(src_path[7:])