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

tensorstore may not be necessary #17

Open
ianhi opened this issue Dec 3, 2021 · 2 comments
Open

tensorstore may not be necessary #17

ianhi opened this issue Dec 3, 2021 · 2 comments

Comments

@ianhi
Copy link

ianhi commented Dec 3, 2021

Wanted to share this here as it may be useful and was inspired by your PR (napari/napari#3155)

I found that a user of napari can get a zarr.Array to work in a labels layer by wrapping it like so:

import napari

import zarr
import wrapt
import numpy as np




class zarrWrapper(wrapt.ObjectProxy):
    """Add fancy indexing to zarr."""

    def __getitem__(self, key):
        """Get some data inplace maybe using numpy indexing"""
        try:
            return self.__class__.__getitem__(self, key)
        except IndexError as e:
            try:
                return self.vindex[key]
            except Exception:
                raise e

    def __setitem__(self, key, value):
        """Edit data in-place allowing for fancy indexing"""
        try:
            self.__class__.__setitem__(self, key, value)
        except IndexError as e:
            try:
                self.vindex[key] = value
            except Exception:
                raise e

z_arr = zarrWrapper(zarr.zeros((50, 512, 512), dtype=np.uint16))


viewer = napari.Viewer()
viewer.add_labels(z_arr)
napari.run()
@jni
Copy link
Owner

jni commented Dec 4, 2021

Thanks @ianhi, this is very nice! I will say that (a) try/except is actually quite expensive in Python, so best to avoid it for something interactive like painting, but (b) I actually added fancy indexing to zarr arrays by default recently and this will be in release 2.11, so I'm just waiting for that to happen then we'll drop the tensorstore dependency. 😊

@ianhi
Copy link
Author

ianhi commented Dec 15, 2021

I actually added fancy indexing to zarr arrays by default recently and this will be in release 2.11, so I'm just waiting for that to happen then we'll drop the tensorstore dependency. blush

Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants