diff --git a/caterva2/hdf5.py b/caterva2/hdf5.py index dfe79d45..b6f515a5 100644 --- a/caterva2/hdf5.py +++ b/caterva2/hdf5.py @@ -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 @@ -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 diff --git a/caterva2/services/srv_utils.py b/caterva2/services/srv_utils.py index 4b4b1c2e..75725ab7 100644 --- a/caterva2/services/srv_utils.py +++ b/caterva2/services/srv_utils.py @@ -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 @@ -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 diff --git a/caterva2/tests/test_hdf5_proxy.py b/caterva2/tests/test_hdf5_proxy.py index 1aa61822..5208c64e 100644 --- a/caterva2/tests/test_hdf5_proxy.py +++ b/caterva2/tests/test_hdf5_proxy.py @@ -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: