Skip to content

Commit

Permalink
misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Mar 19, 2024
1 parent 95fbf3c commit 4db0704
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lindi/LindiClient/LindiAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ def __init__(self, *, _object: Union[zarr.Group, zarr.Array]):
self._object = _object

def get(self, key, default=None):
return self._object.attrs.get(key, default)
try:
return self[key]
except KeyError:
return default

def __getitem__(self, key):
val = self._object.attrs[key]
Expand Down
21 changes: 19 additions & 2 deletions lindi/LindiClient/LindiClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def __init__(
_zarr_group: zarr.Group,
) -> None:
self._zarr_group = _zarr_group
super().__init__(_zarr_group=self._zarr_group)
super().__init__(_zarr_group=self._zarr_group, _client=self)

@property
def filename(self):
return ''

@staticmethod
def from_zarr_store(zarr_store: Union[Store, FSMap]) -> "LindiClient":
Expand Down Expand Up @@ -51,9 +55,22 @@ def from_zarr_group(zarr_group: zarr.Group) -> "LindiClient":

@staticmethod
def from_reference_file_system(data: dict) -> "LindiClient":
fs = ReferenceFileSystem(data).get_mapper(root="/")
fs = ReferenceFileSystem(data).get_mapper(root="")
return LindiClient.from_zarr_store(fs)

def get(self, key, default=None, getlink: bool = False):
try:
ret = self[key]
except KeyError:
ret = default
if getlink:
return ret
else:
if isinstance(ret, LindiReference):
return self[ret]
else:
return ret

def __getitem__(self, key): # type: ignore
if isinstance(key, str):
if key.startswith('/'):
Expand Down
11 changes: 10 additions & 1 deletion lindi/LindiClient/LindiDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@


class LindiDataset:
def __init__(self, *, _zarr_array: zarr.Array):
def __init__(self, *, _zarr_array: zarr.Array, _client):
self._zarr_array = _zarr_array
self._is_scalar = self._zarr_array.attrs.get("_SCALAR", False)
self._client = _client

# See if we have the _COMPOUND_DTYPE attribute, which signifies that
# this is a compound dtype
Expand All @@ -25,6 +26,14 @@ def __init__(self, *, _zarr_array: zarr.Array):

self._external_hdf5_clients: Dict[str, h5py.File] = {}

@property
def file(self):
return self._client

@property
def id(self):
return None

@property
def name(self):
return self._zarr_array.name
Expand Down
15 changes: 12 additions & 3 deletions lindi/LindiClient/LindiGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@


class LindiGroup:
def __init__(self, *, _zarr_group: zarr.Group):
def __init__(self, *, _zarr_group: zarr.Group, _client):
self._zarr_group = _zarr_group
self._client = _client

@property
def file(self):
return self._client

@property
def id(self):
return None

@property
def attrs(self):
Expand Down Expand Up @@ -33,9 +42,9 @@ def __getitem__(self, key):
if key in self._zarr_group.keys():
x = self._zarr_group[key]
if isinstance(x, zarr.Group):
return LindiGroup(_zarr_group=x)
return LindiGroup(_zarr_group=x, _client=self._client)
elif isinstance(x, zarr.Array):
return LindiDataset(_zarr_array=x)
return LindiDataset(_zarr_array=x, _client=self._client)
else:
raise Exception(f"Unknown type: {type(x)}")
else:
Expand Down

0 comments on commit 4db0704

Please sign in to comment.