-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP attempt to implement tiff reader using zarr
- Loading branch information
1 parent
ec9748c
commit 29a407e
Showing
3 changed files
with
87 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import io | ||
|
||
from xarray import Variable | ||
import zarr | ||
|
||
from virtualizarr.zarr import ZArray | ||
from virtualizarr.manifests import ChunkManifest, ManifestArray | ||
|
||
|
||
def virtual_variable_from_zarr_array(za: zarr.Array) -> Variable: | ||
""" | ||
Create a virtual xarray.Variable wrapping a ManifestArray from a single zarr.Array. | ||
""" | ||
|
||
# TODO this only works with zarr-python v2 for now | ||
|
||
attrs = dict(za.attrs) | ||
|
||
# extract _ARRAY_DIMENSIONS and remove it from attrs | ||
# TODO handle v3 DIMENSION_NAMES too | ||
dims = attrs.pop("_ARRAY_DIMENSIONS") | ||
|
||
zarray = ZArray( | ||
shape=za.shape, | ||
chunks=za.chunks, | ||
dtype=za.dtype, | ||
fill_value=za.fill_value, | ||
order=za.order, | ||
compressor=za.compressor, | ||
filters=za.filters, | ||
#zarr_format=za.zarr_format, | ||
) | ||
|
||
manifest = chunkmanifest_from_zarr_array(za) | ||
|
||
ma = ManifestArray(chunkmanifest=manifest, zarray=zarray) | ||
|
||
return Variable(data=ma, dims=dims, attrs=attrs) | ||
|
||
|
||
def chunkmanifest_from_zarr_array(za: zarr.Array) -> ChunkManifest: | ||
import ujson | ||
|
||
of2 = io.StringIO() | ||
|
||
# TODO handle remote urls | ||
za.store.write_fsspec(of2)# , url=url) | ||
out = ujson.loads(of2.getvalue()) | ||
|
||
print(out) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters