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

Use zarr.empty not np.empty when creating large zarr sinks #1801

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Bug Fixes

- Fix an issue with lazy tiles that have non power of two scaling ([#1797](../../pull/1797))
- Use zarr.empty not np.empty when creating large zarr sinks ([#1801](../../pull/1801))

## 1.31.0

Expand Down
16 changes: 14 additions & 2 deletions sources/zarr/large_image_source_zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,9 @@ def _resizeImage(self, arr, new_shape, new_axes, chunking):
arr,
[(0, s - arr.shape[i]) for i, s in enumerate(new_shape)],
)
new_arr = zarr.empty(new_shape, chunks=chunking, dtype=arr.dtype)
new_arr = zarr.empty(
new_shape, chunks=chunking, dtype=arr.dtype,
write_empty_chunks=False)
new_arr[:] = arr[:]
arr = new_arr
else:
Expand Down Expand Up @@ -765,12 +767,22 @@ def addTile(self, tile, x=0, y=0, mask=None, axes=None, **kwargs):
self._zarr_store.rmdir(path)
chunking = None
if store_path not in current_arrays:
arr = np.empty(tuple(new_dims.values()), dtype=tile.dtype)
chunking = tuple([
self._tileSize if a in ['x', 'y'] else
new_dims.get('s') if a == 's' else 1
for a in axes
])
# If we have to create the array, do so with the desired store
# and chunking so we don't have to immediately rechunk it
arr = zarr.empty(
tuple(new_dims.values()),
dtype=tile.dtype,
chunks=chunking,
store=self._zarr_store,
path=store_path,
write_empty_chunks=False,
)
chunking = None
else:
arr = current_arrays[store_path]
new_shape = tuple(
Expand Down