Skip to content

Commit

Permalink
Merge pull request #1801 from girder/zarr-empty-creation
Browse files Browse the repository at this point in the history
Use zarr.empty not np.empty when creating large zarr sinks
  • Loading branch information
manthey authored Jan 31, 2025
2 parents b354515 + 7bf1eb8 commit ead9182
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit ead9182

Please sign in to comment.