Skip to content

Commit

Permalink
Add conversion of ImageArray to dask (#262)
Browse files Browse the repository at this point in the history
* add conversion to dask

* add testing

* expand testing

* add documentation

* rename `ImageArray.dask` to `ImageArray.dask_array`

* add explicit dask[array] requirement, matches ndtiff
  • Loading branch information
ieivanov authored Dec 3, 2024
1 parent 71ec62c commit 8a7618f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions iohub/ngff/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,13 @@ def numpy(self):
`self.numpy()` is equivalent to `self[:]`."""
return self[:]

def dask_array(self):
"""Return as a dask array"""
import dask.array as da

# Note: Designed to work with zarr DirectoryStore
return da.from_zarr(self.store.path, component=self.path)

def downscale(self):
raise NotImplementedError

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ install_requires =
pillow>=9.4.0
blosc2
xarray>=2024.1.1
dask[array]

[options.extras_require]
dev =
Expand Down
21 changes: 21 additions & 0 deletions tests/ngff/test_ngff.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,27 @@ def test_create_zeros(ch_shape_dtype, arr_name):
assert dataset[arr_name].dtype == dtype


@given(
channels_and_random_5d=_channels_and_random_5d(),
arr_name=short_alpha_numeric,
)
@settings(
max_examples=16,
suppress_health_check=[HealthCheck.data_too_large],
)
def test_ome_zarr_to_dask(channels_and_random_5d, arr_name):
"""Test `iohub.ngff.Position.data` to dask"""
channel_names, random_5d = channels_and_random_5d
with _temp_ome_zarr(random_5d, channel_names, "0") as dataset:
assert_array_almost_equal(
dataset.data.dask_array().compute(), random_5d
)
with _temp_ome_zarr(random_5d, channel_names, arr_name) as dataset:
assert_array_almost_equal(
dataset[arr_name].dask_array().compute(), random_5d
)


@given(
channels_and_random_5d=_channels_and_random_5d(),
arr_name=short_alpha_numeric,
Expand Down

0 comments on commit 8a7618f

Please sign in to comment.