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

Add easy way to iterate through every chunk of an array #2454

Open
dstansby opened this issue Oct 30, 2024 · 5 comments
Open

Add easy way to iterate through every chunk of an array #2454

dstansby opened this issue Oct 30, 2024 · 5 comments

Comments

@dstansby
Copy link
Contributor

dstansby commented Oct 30, 2024

I am finding myself wanting to apply an operation (e.g., thresholding) on every chunk in an array. It would therefore be nice if there was an easy way to iterate through each chunk of the array.

Something like:

for i, chunk in enumerate(zarr_arr.all_chunks):
    zarr.all_chunks[i] = np.clip(chunk, min, max)

This is sort of similar to block indexing, but iterating over Array.blocks only iterates over the first axis of blocks, and gives you back all the chunks along the other axes.

@d-v-b
Copy link
Contributor

d-v-b commented Oct 30, 2024

something like this?

def _iter_chunk_regions(
?

@dstansby
Copy link
Contributor Author

Hard to tell just looking at the code, but from the docstring I think that sounds about right 😄

@dcherian
Copy link
Contributor

Can we remake .blocks.__iter__ to be more like np.nditer instead?

@dstansby
Copy link
Contributor Author

I think that would be quite a big braking API change, so probably worth creating a freshly named property or method?

@d-v-b
Copy link
Contributor

d-v-b commented Oct 31, 2024

i'm not a big fan of .blocks to be honest, i don't think it's a very intuitive API for something as simple as "access data chunk by chunk". i'm not saying we should remove it, but we should take the 2 -> 3 transition as an opportunity to think about whether there's a better way to do things

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