How to use the tiledb.object_type function in tiledb

To help you get started, we’ve selected a few tiledb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TileDB-Inc / TileDB-Py / examples / quickstart_dense.py View on Github external
data = np.array(([1, 2, 3, 4],
                         [5, 6, 7, 8],
                         [9, 10, 11, 12],
                         [13, 14, 15, 16]))
        A[:] = data


def read_array():
    # Open the array and read from it.
    with tiledb.DenseArray(array_name, mode='r') as A:
        # Slice only rows 1, 2 and cols 2, 3, 4.
        data = A[1:3, 2:5]
        print(data["a"])


if tiledb.object_type(array_name) != "array":
    create_array()
    write_array()

read_array()
github TileDB-Inc / TileDB-Py / examples / quickstart_sparse.py View on Github external
I, J = [1, 2, 2], [1, 4, 3]
        data = np.array(([1, 2, 3]))
        A[I, J] = data


def read_array():
    # Open the array and read from it.
    with tiledb.SparseArray(array_name, mode='r') as A:
        # Slice only rows 1, 2 and cols 2, 3, 4.
        data = A[1:3, 2:5]
        a_vals = data["a"]
        for i, coord in enumerate(data["coords"]):
            print("Cell (%d, %d) has data %d" % (coord[0], coord[1], a_vals[i]))


if tiledb.object_type(array_name) != "array":
    create_array()
    write_array()

read_array()
github TileDB-Inc / TileDB-Py / examples / reading_dense_layouts.py View on Github external
if order != 'G' and a_vals.flags['F_CONTIGUOUS']:
            print("NOTE: The following result array has col-major layout internally")

        if order != 'G':
            for i in range(coords.shape[0]):
                for j in range(coords.shape[1]):
                    print("Cell {} has data {}".format(str(coords[i, j]), str(a_vals[i, j])))
        else:
            # When reading in global order, TileDB always returns a vector (1D array)
            for i in range(coords.shape[0]):
                print("Cell {} has data {}".format(str(coords[i]), str(a_vals[i])))


# Check if the array already exists.
if tiledb.object_type(array_name) != "array":
    create_array()
    write_array()

layout = ""
if len(sys.argv) > 1:
    layout = sys.argv[1]

order = 'C'
if layout == "col":
    order = 'F'
elif layout == "global":
    order = 'G'
else:
    order = 'C'

read_array(order)
github TileDB-Inc / TileDB-Py / examples / quickstart_kv.py View on Github external
with tiledb.KV(kv_name, mode='w') as A:
        A["key_1"] = "1"
        A["key_2"] = "2"
        A["key_3"] = "3"
        A.flush()


def read_array():
    # Open the array and read from it.
    with tiledb.KV(kv_name, mode='r') as A:
        print("key_1: %s" % A["key_1"])
        print("key_2: %s" % A["key_2"])
        print("key_3: %s" % A["key_3"])


if tiledb.object_type(kv_name) != "kv":
    create_array()
    write_array()

read_array()
github TileDB-Inc / TileDB-Py / examples / kv.py View on Github external
def read_array():
    # Open the array and read from it.
    with tiledb.KV(array_name, mode='r') as A:
        print("key_1: %s" % A["key_1"])
        print("key_2: %s" % A["key_2"])
        print("key_3: %s" % A["key_3"])


def iter_kv():
    with tiledb.KV(array_name, mode='r') as A:
        for p in A:
            print("key: '%s', value: '%s'" % (p[0], p[1]))


if tiledb.object_type(array_name) != "kv":
    create_array()
    write_array()

read_array()
iter_kv()
github TileDB-Inc / TileDB-Py / examples / multi_attribute.py View on Github external
def create_array():
    # Check if the array already exists.
    if tiledb.object_type(array_name) == "array":
        return

    # The array will be 4x4 with dimensions "rows" and "cols", with domain [1,4].
    dom = tiledb.Domain(tiledb.Dim(name="rows", domain=(1, 4), tile=4, dtype=np.int32),
                        tiledb.Dim(name="cols", domain=(1, 4), tile=4, dtype=np.int32))

    # Add two attributes "a1" and "a2", so each (i,j) cell can store
    # a character on "a1" and a vector of two floats on "a2".
    schema = tiledb.ArraySchema(domain=dom, sparse=False,
                                attrs=[tiledb.Attr(name="a1", dtype=np.uint8),
                                       tiledb.Attr(name="a2",
                                                   dtype=np.dtype([("", np.float32), ("", np.float32), ("", np.float32)]))])

    # Create the (empty) array on disk.
    tiledb.DenseArray.create(array_name, schema)
github TileDB-Inc / TileDB-Py / examples / libtiledb / tiledb_object_type.py View on Github external
def main():
    ctx = tiledb.Ctx()
    print("{!r}".format(tiledb.object_type(ctx, "my_group")))
    print("{!r}".format(tiledb.object_type(ctx, "my_dense_array")))
    print("{!r}".format(tiledb.object_type(ctx, "my_kv")))
    print("{!r}".format(tiledb.object_type(ctx, "invalid_path")))
github TileDB-Inc / TileDB-Py / examples / libtiledb / tiledb_object_type.py View on Github external
def main():
    ctx = tiledb.Ctx()
    print("{!r}".format(tiledb.object_type(ctx, "my_group")))
    print("{!r}".format(tiledb.object_type(ctx, "my_dense_array")))
    print("{!r}".format(tiledb.object_type(ctx, "my_kv")))
    print("{!r}".format(tiledb.object_type(ctx, "invalid_path")))
github TileDB-Inc / TileDB-Py / examples / reading_sparse_layouts.py View on Github external
# Get non-empty domain
        print("Non-empty domain: {}".format(A.nonempty_domain()))

        # Slice only rows 1, 2 and cols 2, 3, 4.
        # NOTE: The `query` syntax is required to specify an order
        # other than the default row-major
        data = A.query(attrs=["a"], order=order, coords=True)[1:3, 2:5]
        a_vals = data["a"]
        coords = data["coords"]

        for i in range(coords.shape[0]):
            print("Cell {} has data {}".format(str(coords[i]), str(a_vals[i])))


# Check if the array already exists.
if tiledb.object_type(array_name) != "array":
    create_array()
    write_array()

layout = ""
if len(sys.argv) > 1:
    layout = sys.argv[1]

order = 'C'
if layout == "col":
    order = 'F'
elif layout == "global":
    order = 'G'
else:
    order = 'C'

read_array(order)