-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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()Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels