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

ImageArray Initialization #261

Closed
wants to merge 3 commits into from
Closed
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
36 changes: 22 additions & 14 deletions iohub/ngff/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,28 @@ def close(self):
class ImageArray(zarr.Array):
"""Container object for image stored as a zarr array (up to 5D)"""

def __init__(self, zarray: zarr.Array):
super().__init__(
store=zarray._store,
path=zarray._path,
read_only=zarray._read_only,
chunk_store=zarray._chunk_store,
synchronizer=zarray._synchronizer,
cache_metadata=zarray._cache_metadata,
cache_attrs=zarray._attrs.cache,
partial_decompress=zarray._partial_decompress,
write_empty_chunks=zarray._write_empty_chunks,
zarr_version=zarray._version,
meta_array=zarray._meta_array,
)
def __init__(self, zarray: zarr.Array = None, **kwargs):
"""Keyword arguments are passed to the zarr.Array constructor.
If a zarr.Array is provided, the constructor will use its attributes
to initialize the ImageArray.
"""
if zarray is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain when this method should be called without a argument? It is an internal wrapper, and if you don't need the wrapper, just doing Position.zgroup["0"] would give you the plain zarr.Array object.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dask may expect exactly zarr.Array and not a wrapped subclass for some of their internal logic. I think it's safer to match their advertised API than hacking our own wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example use case at the top and a short docstring to the __init__ function:

    def __init__(self, zarray: zarr.Array = None, **kwargs):
        """Keyword arguments are passed to the zarr.Array constructor.
        If a zarr.Array is provided, the constructor will use its attributes
        to initialize the ImageArray.
        """

I think this is a common enough use case, such that we should make iohub arrays work with the dask arrays in multiprocessing applications

kwargs.update(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kwargs.update(
# Dynamically prepare kwargs for the base class to support Dask
kwargs.update(

{
"store": zarray._store,
"path": zarray._path,
"read_only": zarray._read_only,
"chunk_store": zarray._chunk_store,
"synchronizer": zarray._synchronizer,
"cache_metadata": zarray._cache_metadata,
"cache_attrs": zarray._attrs.cache,
"partial_decompress": zarray._partial_decompress,
"write_empty_chunks": zarray._write_empty_chunks,
"zarr_version": zarray._version,
"meta_array": zarray._meta_array,
}
)
super().__init__(**kwargs)
self._get_dims()

def _get_dims(self):
Expand Down