Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to ask if chunk exists? #2507

Open
TomNicholas opened this issue Nov 19, 2024 · 3 comments
Open

Way to ask if chunk exists? #2507

TomNicholas opened this issue Nov 19, 2024 · 3 comments

Comments

@TomNicholas
Copy link
Member

Is there a way to ask zarr if a key is backed by a chunk (as opposed to defaulting to the fill_value)?

The motivation is trying to create virtual references for an existing zarr store, but not knowing which chunks of the chunk grid actually exist - see zarr-developers/VirtualiZarr#271 (comment)

cc @norlandrhagen

@TomAugspurger
Copy link
Contributor

Is the key here a positional indexer into the array, or a chunk indexer, or something else? It's possible that a combination of Array.metadata.encode_chunk_key and store.exists will do what you want:

In [20]: arr = zarr.create(path="a", shape=(3, 4, 5), chunks=(2, 2, 2))

In [21]: arr.metadata.encode_chunk_key((0, 0, 0))
Out[21]: 'c/0/0/0'

In [22]: arr.metadata.encode_chunk_key((1, 2, 3))
Out[22]: 'c/1/2/3'

@TomNicholas
Copy link
Member Author

It's a chunk indexer. We have a store, and want to calculate the byte offsets and ranges for every chunk in the store. Assuming no sharding the offset is always 0, we get the length of each chunk using the new .getsize (because with compression they will could different lengths), but it would also be nice to know which chunks don't actually exist in the store so we don't bother trying to get their sizes or writing those into the generated chunk manifest.

It does sound like store.exists is what we need though, thanks!

@d-v-b
Copy link
Contributor

d-v-b commented Nov 20, 2024

see also Array._iter_chunk_keys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants