From 4109fe18a6b326d161504212d811a6603d15e0af Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 18 Nov 2022 12:44:47 -0500 Subject: [PATCH] Don't use dask threads when using nd2 to fetch tiles We have to lock when fetching tiles anyway, and the dask threadpool adds needless overhead. --- CHANGELOG.md | 1 + sources/nd2/large_image_source_nd2/__init__.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4af3d5969..8d7eee2b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/sources/nd2/large_image_source_nd2/__init__.py b/sources/nd2/large_image_source_nd2/__init__.py index f9e11cba8..e3cdb526e 100644 --- a/sources/nd2/large_image_source_nd2/__init__.py +++ b/sources/nd2/large_image_source_nd2/__init__.py @@ -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]). @@ -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)