Esempio n. 1
0
    def set_tiledb_context(context_params):
        """Set the tiledb context.  This should be set before any instances of CxgAdaptor are created"""
        try:
            CxgAdaptor.tiledb_ctx = tiledb.Ctx(context_params)
            tiledb.default_ctx(context_params)

        except tiledb.libtiledb.TileDBError as e:
            if e.message == "Global context already initialized!":
                if tiledb.default_ctx().config().dict() != CxgAdaptor.tiledb_ctx.config().dict():
                    raise ConfigurationError("Cannot change tiledb configuration once it is set")
            else:
                raise ConfigurationError(f"Invalid tiledb context: {str(e)}")
Esempio n. 2
0
def uri(temp_rootdir):
    """
    Create a simple dense test array.
    """
    path = os.path.abspath(os.path.join(temp_rootdir, "test_array"))

    ctx = tiledb.default_ctx()
    rows_dim = tiledb.Dim(ctx=ctx, domain=(1, 25), dtype=np.int64)
    cols_dim = tiledb.Dim(ctx=ctx, domain=(1, 12), dtype=np.int64)
    dom = tiledb.Domain(rows_dim, cols_dim, ctx=ctx)
    att1 = tiledb.Attr(name="a", ctx=ctx, dtype=np.float64)
    att2 = tiledb.Attr(name="b", ctx=ctx, dtype=np.float64)
    schema = tiledb.ArraySchema(ctx=ctx, domain=dom, attrs=(att1, att2))

    tiledb.Array.create(path, schema)

    data = np.reshape(np.arange(300), (25, 12))

    for ts in range(1, 4):
        with tiledb.open(path, mode="w", timestamp=ts) as A:
            A[:] = {"a": data, "b": data}

    yield path

    shutil.rmtree(path)
Esempio n. 3
0
def create_test_array_sparse_25x12_mult(temp_rootdir):
    """
    Create a simple sparse test array.
    """
    path = os.path.abspath(os.path.join(temp_rootdir, "sparse_25x12_mult"))

    ctx = tiledb.default_ctx()
    rows_dim = tiledb.Dim("row", ctx=ctx, domain=(1, 25), dtype=np.int64)
    cols_dim = tiledb.Dim("col", ctx=ctx, domain=(1, 12), dtype=np.int64)
    dom = tiledb.Domain(rows_dim, cols_dim, ctx=ctx)
    att1 = tiledb.Attr(name="a", ctx=ctx, dtype=np.float64)
    att2 = tiledb.Attr(name="b", ctx=ctx, dtype=np.float64)
    schema = tiledb.ArraySchema(ctx=ctx, sparse=True, domain=dom, attrs=(att1, att2))

    tiledb.SparseArray.create(path, schema)

    coords = np.array(list(itertools.product(np.arange(1, 26), np.arange(1, 13))))
    rows = coords[:, 0]
    cols = coords[:, 1]
    data = np.arange(300)

    with tiledb.SparseArray(path, mode="w", timestamp=1) as A:
        A[rows, cols] = {"a": data, "b": data}

    with tiledb.SparseArray(path, mode="w", timestamp=2) as A:
        A[rows, cols] = {"a": data / 2, "b": data * 2}
Esempio n. 4
0
def create_test_array_dense_25x12(temp_rootdir):
    """
    Create a simple dense test array.
    """
    path = os.path.abspath(os.path.join(temp_rootdir, "dense_25x12"))

    ctx = tiledb.default_ctx()
    rows_dim = tiledb.Dim("row", ctx=ctx, domain=(1, 25), dtype=np.int64)
    cols_dim = tiledb.Dim("col", ctx=ctx, domain=(1, 12), dtype=np.int64)
    dom = tiledb.Domain(rows_dim, cols_dim, ctx=ctx)
    att = tiledb.Attr(ctx=ctx, dtype=np.int64)
    schema = tiledb.ArraySchema(ctx=ctx, domain=dom, attrs=(att,))

    tiledb.DenseArray.create(path, schema)

    with tiledb.DenseArray(path, mode="w") as A:
        A[:] = np.reshape(np.arange(300), (25, 12))
Esempio n. 5
0
def create_test_array_sparse_25x12(temp_rootdir):
    """
    Create a simple sparse test array.
    """
    path = os.path.abspath(os.path.join(temp_rootdir, "sparse_25x12"))

    ctx = tiledb.default_ctx()
    rows_dim = tiledb.Dim("row", ctx=ctx, domain=(1, 25), dtype=np.int64)
    cols_dim = tiledb.Dim("col", ctx=ctx, domain=(1, 12), dtype=np.int64)
    dom = tiledb.Domain(rows_dim, cols_dim, ctx=ctx)
    att = tiledb.Attr(ctx=ctx, dtype=np.int64)
    schema = tiledb.ArraySchema(ctx=ctx, sparse=True, domain=dom, attrs=(att,))

    tiledb.SparseArray.create(path, schema)

    with tiledb.SparseArray(path, mode="w") as A:
        coords = np.array(list(itertools.product(np.arange(1, 26), np.arange(1, 13))))
        rows = coords[:, 0]
        cols = coords[:, 1]
        A[rows, cols] = np.arange(300)
Esempio n. 6
0
def create_test_array_dense_25x12_mult(temp_rootdir):
    """
    Create a simple dense test array.
    """
    path = os.path.abspath(os.path.join(temp_rootdir, "dense_25x12_mult"))

    ctx = tiledb.default_ctx()
    rows_dim = tiledb.Dim("row", ctx=ctx, domain=(1, 25), dtype=np.int64)
    cols_dim = tiledb.Dim("col", ctx=ctx, domain=(1, 12), dtype=np.int64)
    dom = tiledb.Domain(rows_dim, cols_dim, ctx=ctx)
    att1 = tiledb.Attr(name="a", ctx=ctx, dtype=np.float64)
    att2 = tiledb.Attr(name="b", ctx=ctx, dtype=np.float64)
    schema = tiledb.ArraySchema(ctx=ctx, domain=dom, attrs=(att1, att2))

    tiledb.DenseArray.create(path, schema)

    data = np.reshape(np.arange(300), (25, 12))

    with tiledb.DenseArray(path, mode="w", timestamp=1) as A:
        A[:] = {"a": data, "b": data}

    with tiledb.DenseArray(path, mode="w", timestamp=2) as A:
        A[:] = {"a": data / 2, "b": data * 2}