Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion caterva2/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def shape(self) -> tuple[int, ...]:
return self.b2arr.shape

@property
def ndim(self) -> tuple[int, ...]:
def ndim(self) -> int:
return self.b2arr.ndim

@property
Expand Down Expand Up @@ -414,6 +414,18 @@ def schunk(self):
# This is basically needed to certificate that it is an NDArray in the LazyArray machinery
return self.b2arr.schunk

@property
def cbytes(self) -> int:
return self.dset.id.get_storage_size()

@property
def cratio(self) -> float:
return 0 if self.cbytes == 0 else self.nbytes / self.cbytes

@property
def nbytes(self) -> int:
return self.b2arr.nbytes

@property
def fields(self) -> Mapping[str, numpy.dtype]:
return self.b2arr.fields
Expand Down
6 changes: 5 additions & 1 deletion caterva2/services/srv_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from sqlalchemy.future import select

# Project
from caterva2 import models
from caterva2 import hdf5, models
from caterva2.services import db, schemas, settings, users


Expand Down Expand Up @@ -122,6 +122,10 @@ def read_metadata(obj):
cparams = get_model_from_obj(array.schunk.cparams, models.CParams)
cparams = reformat_cparams(cparams)
schunk = get_model_from_obj(array.schunk, models.SChunk, cparams=cparams)
if "_ftype" in schunk.vlmeta and schunk.vlmeta["_ftype"] == "hdf5":
array = hdf5.HDF5Proxy(array)
schunk.cratio = array.cratio # overwrite cratio (which will be 0) with HDF5Proxy value
schunk.cbytes = array.cbytes
return get_model_from_obj(array, models.Metadata, schunk=schunk, mtime=mtime)
elif isinstance(obj, blosc2.schunk.SChunk):
schunk = obj
Expand Down
4 changes: 4 additions & 0 deletions caterva2/tests/test_hdf5_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def test_unfold_download(examples_dir, tmp_path, auth_client):
continue
assert b2f.dtype == h5ds.dtype
assert b2f.shape == (h5ds.shape or ())
b2nd_pointer = auth_client.get(remote_path)
if b2f.shape != (): # skip empty datasets
assert b2f.cbytes == b2nd_pointer.meta["schunk"]["cbytes"]
assert b2f.cratio == b2nd_pointer.meta["schunk"]["cratio"]
if b2f.shape == ():
continue
if h5ds.chunks:
Expand Down