Skip to content

Commit

Permalink
Use np.ceil() for chunk sizes in dask resize()
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Feb 2, 2023
1 parent c4bc26c commit e1fdd12
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ome_zarr/dask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ def resize(
)
)
image_prepared = image.rechunk(better_chunksize)

# If E.g. we resize image from 6675 by 0.5 to 3337, factor is 0.49992509 so each
# chunk of size e.g. 1000 will resize to 499. When assumbled into a new array, the
# array will now be of size 3331 instead of 3337 because each of 6 chunks was
# smaller by 1. When we compute() this, dask will read 6 chunks of 1000 and expect
# last chunk to be 337 but instead it will only be 331.
# So we use ceil() here (and in resize_block) to round 499.925 up to chunk of 500
block_output_shape = tuple(
np.floor(np.array(better_chunksize) * factors).astype(int)
np.ceil(np.array(better_chunksize) * factors).astype(int)
)

# Map overlap
def resize_block(image_block: da.Array, block_info: dict) -> da.Array:
# if the input block is smaller than a 'regular' chunk (e.g. edge of image)
# we need to calculate target size for each chunk...
chunk_output_shape = tuple(
np.floor(np.array(image_block.shape) * factors).astype(int)
np.ceil(np.array(image_block.shape) * factors).astype(int)
)
return skimage.transform.resize(
image_block, chunk_output_shape, *args, **kwargs
Expand Down

0 comments on commit e1fdd12

Please sign in to comment.