Example #1
0
async def test_array():
    t = ts.array(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.int64))
    assert t.spec().to_json(include_defaults=False) == {
        "driver": "array",
        "array": [[1, 2, 3], [4, 5, 6]],
        "dtype": "int64",
        "transform": {
            "input_inclusive_min": [0, 0],
            "input_exclusive_max": [2, 3]
        },
    }

    assert t.T.spec().to_json(include_defaults=False) == {
        "driver": "array",
        "array": [[1, 4], [2, 5], [3, 6]],
        "dtype": "int64",
        "transform": {
            "input_inclusive_min": [0, 0],
            "input_exclusive_max": [3, 2],
        },
    }

    assert t[0].spec().to_json(include_defaults=False) == {
        "driver": "array",
        "array": [1, 2, 3],
        "dtype": "int64",
        "transform": {
            "input_inclusive_min": [0],
            "input_exclusive_max": [3]
        },
    }
Example #2
0
async def test_downsample_store_uint32():
  t = ts.array(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint32))

  downsampled = ts.downsample(t, [2, 2], method='mean')

  np.testing.assert_equal(
      np.array([[3, 4]], dtype=np.uint32), await
      downsampled.read())
Example #3
0
async def test_downsample_spec():

  t = ts.array(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32))
  spec = t.spec()
  downsampled_spec = ts.downsample(spec, [1, 2], method='mean')

  downsampled = await ts.open(downsampled_spec)

  np.testing.assert_equal(
      np.array([[1.5, 3], [4.5, 6]], dtype=np.float32), await
      downsampled.read())
async def test_read_adapt():
    """Tests reading where the `read_function` itself reads from a TensorStore."""
    a = ts.array([[1, 2, 3], [4, 5, 6]], dtype=ts.int32)

    async def do_read(domain, array, read_params):
        del read_params
        array[...] = (await a[domain].read()) + 100

    t = ts.virtual_chunked(do_read, dtype=a.dtype, domain=a.domain)

    np.testing.assert_array_equal(
        await t.read(),
        np.array([[101, 102, 103], [104, 105, 106]], dtype=np.int32))
Example #5
0
        ),
        3,
    ),
    (
        Tracks,
        np.column_stack(
            (np.ones(20), np.arange(20), 20 * np.random.random((20, 3)))
        ),
        4,
    ),
]

try:
    import tensorstore as ts

    m = ts.array(np.random.random((10, 15)))
    p = [ts.array(np.random.random(s)) for s in [(40, 20), (20, 10), (10, 5)]]
    layer_test_data.extend([(Image, m, 2), (Image, p, 2)])
except ImportError:
    pass

classes = [Labels, Points, Vectors, Shapes, Surface, Tracks, Image]
names = [cls.__name__.lower() for cls in classes]
layer2addmethod = {
    cls: getattr(Viewer, 'add_' + name) for cls, name in zip(classes, names)
}


# examples of valid tuples that might be passed to viewer._add_layer_from_data
good_layer_data = [
    (np.random.random((10, 10)),),
Example #6
0
def test_normalize_dtype_tensorstore(dtype_str):
    np_arr = np.zeros(5, dtype=dtype_str)
    ts_arr = ts.array(np_arr)  # inherit ts dtype from np dtype
    assert normalize_dtype(ts_arr.dtype) is np_arr.dtype.type
Example #7
0
async def test_cast():
  t = ts.array(np.array([0, 1, 2, 3], dtype=np.int64))
  t_string = t.astype(bytes)
  np.testing.assert_equal(await t_string.read(), [b"0", b"1", b"2", b"3"])
  t_bool = ts.cast(t, bool)
  np.testing.assert_equal(await t_bool.read(), [False, True, True, True])