Skip to content

Commit

Permalink
Don't use dask threads when using nd2 to fetch tiles
Browse files Browse the repository at this point in the history
We have to lock when fetching tiles anyway, and the dask threadpool adds
needless overhead.
  • Loading branch information
manthey committed Nov 18, 2022
1 parent a87b813 commit 4109fe1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Improvements
- Better control dtype on multi sources ([#993](../../pull/993))
- Don't use dask threads when using nd2 to fetch tiles ([#994](../../pull/994))

### Bug Fixes
- Use open.read rather than download to access files in Girder ([#989](../../pull/989))
Expand Down
5 changes: 3 additions & 2 deletions sources/nd2/large_image_source_nd2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, path, **kwargs):
raise TileSourceFileNotFoundError(self._largeImagePath) from None
raise TileSourceError('File cannot be opened via nd2reader.')
# We use dask to allow lazy reading of large images
self._nd2array = self._nd2.to_dask(copy=False)
self._nd2array = self._nd2.to_dask(copy=False, wrapper=False) # ##DWM::
arrayOrder = list(self._nd2.sizes)
# Reorder this so that it is XY (P), T, Z, C, Y, X, S (or at least end
# in Y, X[, S]).
Expand Down Expand Up @@ -260,7 +260,8 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs):
tileframe = tileframe[fp // fc]
fp = fp % fc
with self._tileLock:
tile = tileframe[y0:y1:step, x0:x1:step].compute().copy()
# Have dask use single-threaded since we are using a lock anyway.
tile = tileframe[y0:y1:step, x0:x1:step].compute(scheduler='single-threaded').copy()
return self._outputTile(tile, TILE_FORMAT_NUMPY, x, y, z,
pilImageAllowed, numpyAllowed, **kwargs)

Expand Down

0 comments on commit 4109fe1

Please sign in to comment.