VirtualiZarr icon indicating copy to clipboard operation
VirtualiZarr copied to clipboard

Add `.nrefs` method to accessor that returns number of virtual chunk references

Open TomNicholas opened this issue 8 months ago • 0 comments

It would be neat to add a method vds.nrefs() to the accessor, which returns the total number of virtual references in the dataset. It's useful to know how many millions of references you're about to try and write to icechunk (or kerchunk json...)

class VirtualDatasetAccessor
    def nrefs(self: xr.Dataset) -> int:
        """Count the number of virtual references in the dataset"""
        from virtualizarr.manifests import ManifestArray
    
        # this just ignores non-virtual variables
        return sum(
            len(var.data.manifest) for var in vds.variables.values() if isinstance(var.data, ManifestArray)
        )

TomNicholas avatar Apr 26 '25 22:04 TomNicholas