Skip to content

writeable zarr labels layer #4

@ianhi

Description

@ianhi

may be nice to use at some point. The trick is to use wrapt to overwrite the dunder method.

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions