Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conversion of ImageArray to dask #262

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading