Esempio n. 1
0
def test_compressed_morton_code():
    cmc = lambda coord: compressed_morton_code(coord, grid_size=(3, 3, 3))

    assert cmc((0, 0, 0)) == 0b000000
    assert cmc((1, 0, 0)) == 0b000001
    assert cmc((2, 0, 0)) == 0b001000
    try:
        cmc((3, 0, 0))
        assert False
    except ValueError:
        pass
    assert cmc((2, 2, 0)) == 0b011000
    assert cmc((2, 2, 1)) == 0b011100

    cmc = lambda coord: compressed_morton_code(coord, grid_size=(2, 3, 1))

    assert cmc((0, 0, 0)) == 0b000000
    assert cmc((1, 0, 0)) == 0b000001
    try:
        cmc((0, 0, 7))
        assert False
    except ValueError:
        pass
    assert cmc((1, 2, 0)) == 0b000101

    assert np.array_equal(cmc([(0, 0, 0), (1, 2, 0)]), [0b000000, 0b000101])

    cmc = lambda coord: compressed_morton_code(coord, grid_size=(4, 4, 1))
    assert cmc((3, 3, 0)) == 0b1111

    cmc = lambda coord: compressed_morton_code(coord, grid_size=(8, 8, 2))
    assert cmc((5, 5, 0)) == 0b1100011
Esempio n. 2
0
def test_sharded_image_bits(scale):
    dataset_size = Vec(*scale["size"])
    chunk_size = Vec(*scale["chunk_sizes"][0])

    spec = create_sharded_image_info(dataset_size=dataset_size,
                                     chunk_size=chunk_size,
                                     encoding=scale["encoding"],
                                     dtype=np.uint8)

    shape = image_shard_shape_from_spec(spec, dataset_size, chunk_size)

    shape = lib.min2(shape, dataset_size)
    dataset_bbox = Bbox.from_vec(dataset_size)
    gpts = list(gridpoints(dataset_bbox, dataset_bbox, chunk_size))
    grid_size = np.ceil(dataset_size / chunk_size).astype(np.int64)

    spec = ShardingSpecification.from_dict(spec)
    reader = ShardReader(None, None, spec)

    morton_codes = compressed_morton_code(gpts, grid_size)
    min_num_shards = prod(dataset_size / shape)
    max_num_shards = prod(np.ceil(dataset_size / shape))

    assert 0 < min_num_shards <= 2**spec.shard_bits
    assert 0 < max_num_shards <= 2**spec.shard_bits

    real_num_shards = len(set(map(reader.get_filename, morton_codes)))

    assert min_num_shards <= real_num_shards <= max_num_shards
def test_compressed_morton_code():
    cmc = lambda coord: compressed_morton_code(coord, grid_size=(3, 3, 3))

    assert cmc((0, 0, 0)) == 0b000000
    assert cmc((1, 0, 0)) == 0b000001
    assert cmc((2, 0, 0)) == 0b001000
    assert cmc((3, 0, 0)) == 0b001001
    assert cmc((2, 2, 0)) == 0b011000
    assert cmc((2, 2, 1)) == 0b011100

    cmc = lambda coord: compressed_morton_code(coord, grid_size=(2, 3, 1))

    assert cmc((0, 0, 0)) == 0b000000
    assert cmc((1, 0, 0)) == 0b000001
    assert cmc((0, 0, 7)) == 0b000100
    assert cmc((2, 3, 1)) == 0b011110
Esempio n. 4
0
def test_compressed_morton_code():
    cmc = lambda coord: compressed_morton_code(coord, grid_size=(3, 3, 3))

    assert cmc((0, 0, 0)) == 0b000000
    assert cmc((1, 0, 0)) == 0b000001
    assert cmc((2, 0, 0)) == 0b001000
    assert cmc((3, 0, 0)) == 0b001001
    assert cmc((2, 2, 0)) == 0b011000
    assert cmc((2, 2, 1)) == 0b011100

    cmc = lambda coord: compressed_morton_code(coord, grid_size=(2, 3, 1))

    assert cmc((0, 0, 0)) == 0b000000
    assert cmc((1, 0, 0)) == 0b000001
    assert cmc((0, 0, 7)) == 0b000100
    assert cmc((2, 3, 1)) == 0b011110

    assert np.array_equal(cmc([(0, 0, 0), (1, 0, 1)]), [0b000000, 0b000101])
Esempio n. 5
0
def test_image_sharding_hash():
    spec = ShardingSpecification(
        type="neuroglancer_uint64_sharded_v1",
        data_encoding="gzip",
        hash="identity",
        minishard_bits=6,
        minishard_index_encoding="gzip",
        preshift_bits=9,
        shard_bits=16,
    )

    point = Vec(144689, 52487, 2829)
    volume_size = Vec(*[248832, 134144, 7063])
    chunk_size = Vec(*[128, 128, 16])

    grid_size = np.ceil(volume_size / chunk_size).astype(np.uint32)
    gridpt = np.ceil(point / chunk_size).astype(np.int32)
    code = compressed_morton_code(gridpt, grid_size)
    loc = spec.compute_shard_location(code)

    assert loc.shard_number == '458d'