question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sparse array is not open for reading when writing

See original GitHub issue

This code complains for array not being open for reading (previous step).

The array definition is:

   domain = tiledb.Domain(tiledb.Dim(name="cols", domain=(978307200, 4102358400), 
                                                tile=1000, dtype=np.int64))
    schema = tiledb.ArraySchema(domain=domain, sparse=True,
                        attrs=[tiledb.Attr(name="ndvi", dtype=np.float32),
                               tiledb.Attr(name="kcb",dtype=np.float32),
                               tiledb.Attr(name="nn",dtype=np.float32),
                               tiledb.Attr(name="eto",dtype=np.float32),    
                               tiledb.Attr(name="trigger",dtype=np.dtype('b'))])

`

What I want to do is, for a given timestamp (dimension cols), write a list of attributes (vegatation indexes).

And when computed those values, the code that tries to write today’s recordings is:

   #TiledDB writing
    with tiledb.SparseArray(grupo_parcela, mode='w') as parcelaAttrsW:                      
                        parcelaAttrsW[tsHoy]['trigger'] = trigger
                        parcelaAttrsW[tsHoy]['eto']=etoParcela 
 

So, direct access by indexing for writing seems to need previous read, and thus makes opening ‘w’ fail. Should I construct a numpy array first and then write it to file, should it be something like:

                      parcelaAttrsW[tsHoy]=full array numpy

In my opinion, RW mode is something quite useful that has been requested before:

https://github.com/TileDB-Inc/TileDB-Py/issues/58

Kind regards!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stavrospapadopouloscommented, Jul 25, 2019

Here is a more detailed example when you have two attributes a and b in a sparse array with a single dimension t:

with tiledb.SparseArray(array_name, mode='w') as A:
    # These are the timestamps you would like to write at: 1, 5, 6
    t = [1, 5, 6]
    # These are the values for attribute "a" and "b" at timestamps 1, 5, 6, respectively
    a = np.array(([1, 2, 3]));
    b = np.array(([3, 3, 10]));
    # This is how you write
    A[t] = {"a":a, "b":b}

The above will create the following sparse cells in A (recall, t is the dimension, and a and b are the attributes):

t=1, a=1, b=3
t=5, a=2, b=3
t=6, a=3, b=10

My comment above meant to clarify that whenever you write some cells to the array, you need to provide values for all attributes. In other words, in the above example, A[t] = {"a":a} or A[t] = {"b":b} or A[t] = a or A[t] = b would error out - you need to provide values for both a and b.

1reaction
stavrospapadopouloscommented, Jul 25, 2019

I think there are two different issues here.

  1. Writing multiple attributes to an array. Currently, when writing to an array, you need to provide all attributes as a dictionary of numpy arrays. You can find more details here. Therefore, you need:
parcelaAttrsW[tsHoy] = {"trigger": trigger, "eto": etoParcela, ... <all othe attributes here>}
  1. Read-Write mode. Currently, we support opening an array object either in read or write mode. However, TileDB allows you to open the same array in both read and write mode, but using two different array objects (one with mode ='r' and one with mode='w'). This decision was taken in order to simplify the consistency semantics; when opening an array for reading, TileDB “views” only writes that happened at or before the timestamp the array is getting opened at. If we mix reads and writes in the same object, these semantics can become confusing. We continue to consider the read-write mode though and hope to add it in the future with some clear semantics.

Could you please send us the exact error message you are getting for (1) above, as I think it is confusing and we could improve it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Sparse Arrays — TileDB 1.6.3 documentation
In this tutorial you will learn how to write to sparse arrays. It is highly recommended that you read the tutorials on sparse...
Read more >
Sparse Storage in Fortran: Only Reading and Writing
I have an array with multiple dimensions (the goal is to allow for about 100) and each dimension has a size of about...
Read more >
Read text files as sparse arrays and concatenate in a loop
I would like to read multiple text files and build a sparse array by concatenating row-wise one after the other. The text files...
Read more >
Sparse matrices (scipy.sparse) — SciPy v1.9.3 Manual
When using the array interface, please note that: x * y no longer performs matrix multiplication, but element-wise multiplication (just like with NumPy ......
Read more >
SparseArray - Android Developers
Creates a new SparseArray containing no mappings that will not require any ... a concise but informative representation that is easy for a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found