From 630b7314c4299685679fb2330106cc3a373a8371 Mon Sep 17 00:00:00 2001 From: James Bourbeau Date: Wed, 19 Apr 2023 20:29:56 -0500 Subject: [PATCH 1/2] Initial content --- recipe/meta.yaml | 1 + tests/workflows/test_image_analysis.py | 30 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/workflows/test_image_analysis.py diff --git a/recipe/meta.yaml b/recipe/meta.yaml index e159beb9d3..08ad39f843 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -54,6 +54,7 @@ requirements: - sqlalchemy ==1.4.46 # FIXME https://github.com/dask/dask/issues/9896 - pynvml ==11.5.0 - bokeh ==2.4.3 # FIXME https://github.com/dask/distributed/issues/7173 + - dask-image ==2023.3.0 test: imports: diff --git a/tests/workflows/test_image_analysis.py b/tests/workflows/test_image_analysis.py new file mode 100644 index 0000000000..6ae01bcb6e --- /dev/null +++ b/tests/workflows/test_image_analysis.py @@ -0,0 +1,30 @@ +import dask +import dask.array as da +import numpy as np +from dask_image import ndfilters, ndmeasure, ndmorph + + +def test_BBBC039(small_client): + images = da.from_zarr( + "s3://coiled-datasets/BBBC039", storage_options={"anon": True} + ) + smoothed = ndfilters.gaussian_filter(images, sigma=[0, 1, 1]) + thresh = ndfilters.threshold_local(smoothed, block_size=images.chunksize) + threshold_images = smoothed > thresh + structuring_element = np.array( + [ + [[0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 1, 0], [1, 1, 1], [0, 1, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0]], + ] + ) + binary_images = ndmorph.binary_closing( + threshold_images, structure=structuring_element + ) + label_images, num_features = ndmeasure.label(binary_images) + index = np.arange(num_features) + # FIXME: Only selecting the first few images due to cluster idle timeout. + # Maybe sending large graph? Need to investigate a bit. + area = ndmeasure.area(images[:3], label_images[:3], index) + mean_intensity = ndmeasure.mean(images[:3], label_images[:3], index) + dask.compute(mean_intensity, area) From 214f7948445767f3b7459dcbb49cac9b9fef9d94 Mon Sep 17 00:00:00 2001 From: James Bourbeau Date: Thu, 4 May 2023 10:42:55 -0500 Subject: [PATCH 2/2] Add context --- tests/workflows/test_image_analysis.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/workflows/test_image_analysis.py b/tests/workflows/test_image_analysis.py index 6ae01bcb6e..8aab7e2dc8 100644 --- a/tests/workflows/test_image_analysis.py +++ b/tests/workflows/test_image_analysis.py @@ -5,12 +5,16 @@ def test_BBBC039(small_client): + # Based off of https://github.com/GenevieveBuckley/dask-image-talk-2020 images = da.from_zarr( "s3://coiled-datasets/BBBC039", storage_options={"anon": True} ) smoothed = ndfilters.gaussian_filter(images, sigma=[0, 1, 1]) thresh = ndfilters.threshold_local(smoothed, block_size=images.chunksize) threshold_images = smoothed > thresh + # Since this image stack appears to be 3-dimensional, + # we sandwich a 2d structuring element in between zeros + # so that each 2d image slice has the binary closing applied independently structuring_element = np.array( [ [[0, 0, 0], [0, 0, 0], [0, 0, 0]], @@ -25,6 +29,9 @@ def test_BBBC039(small_client): index = np.arange(num_features) # FIXME: Only selecting the first few images due to cluster idle timeout. # Maybe sending large graph? Need to investigate a bit. - area = ndmeasure.area(images[:3], label_images[:3], index) - mean_intensity = ndmeasure.mean(images[:3], label_images[:3], index) + num_images = 10 + area = ndmeasure.area(images[:num_images], label_images[:num_images], index) + mean_intensity = ndmeasure.mean( + images[:num_images], label_images[:num_images], index + ) dask.compute(mean_intensity, area)