-
Notifications
You must be signed in to change notification settings - Fork 59
Manifest arrays use arrayv3metadata #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
2a01bfa
17fd547
e5666ab
5a8cc4c
4c0b616
ac2f787
5503c60
1272051
1f36755
7098803
ce2284c
c9853d5
209dae3
e7205ef
d65e457
190c20f
47f5ddd
5d15608
908bc52
4a8bfdd
d05cec3
ff23eeb
8560f2d
97d0a71
669ce52
b794dab
825142d
6684125
5e82de4
f57b48d
b811959
8c5139b
eb2a86c
15ac7a7
5359762
c808351
bd50167
ed97704
a3c190e
95886b9
a0f72b2
aad511f
b357b04
08e877a
f040459
495d660
a262f0b
bcd68a0
f0ce778
0518488
0712979
c40915d
cdaca53
2415e07
9366d69
d590cfc
6394207
ea9fd56
0ee2b48
86d1de5
fe8305f
0f5b32d
97bc7cd
b5a1dc6
12c6260
4b555b6
c245b0a
23ac776
402af7f
3e2e8ec
92293a6
eccc215
8fa72b2
f747681
ba2e467
68695c9
f22bf96
8af37a0
d4946ab
2c43c61
05cd57a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
| from virtualizarr.readers.common import VirtualBackend | ||
| from virtualizarr.types import ChunkKey | ||
| from virtualizarr.utils import _FsspecFSFromFilepath, check_for_collisions | ||
| from virtualizarr.zarr import ZArray | ||
|
|
||
|
|
||
| class DMRPPVirtualBackend(VirtualBackend): | ||
|
|
@@ -378,6 +377,10 @@ def _parse_variable(self, var_tag: ET.Element) -> Variable: | |
| ------- | ||
| xr.Variable | ||
| """ | ||
| from zarr.core.metadata.v3 import ArrayV3Metadata | ||
|
|
||
| from virtualizarr.zarr import convert_to_codec_pipeline | ||
|
|
||
| # Dimension info | ||
| dims: dict[str, int] = {} | ||
| dimension_tags = self._find_dimension_tags(var_tag) | ||
|
|
@@ -414,16 +417,27 @@ def _parse_variable(self, var_tag: ET.Element) -> Variable: | |
| # Fill value is placed in zarr array's fill_value and variable encoding and removed from attributes | ||
| encoding = {k: attrs.get(k) for k in self._ENCODING_KEYS if k in attrs} | ||
| fill_value = attrs.pop("_FillValue", None) | ||
| # create ManifestArray and ZArray | ||
| zarray = ZArray( | ||
| chunks=chunks_shape, | ||
| dtype=dtype, | ||
| fill_value=fill_value, | ||
| filters=filters, | ||
| order="C", | ||
| # create ManifestArray | ||
| metadata = ArrayV3Metadata( | ||
abarciauskas-bgse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| shape=shape, | ||
| data_type=dtype, | ||
| chunk_grid={ | ||
| "name": "regular", | ||
| "configuration": {"chunk_shape": chunks_shape}, | ||
| }, | ||
| chunk_key_encoding={"name": "default"}, | ||
| fill_value=fill_value, | ||
| codecs=convert_to_codec_pipeline( | ||
| compressors=filters, | ||
| dtype=dtype, | ||
| filters=None, | ||
| serializer="auto", | ||
| ), | ||
| attributes=attrs, | ||
| dimension_names=None, | ||
|
||
| storage_transformers=None, | ||
| ) | ||
| marr = ManifestArray(zarray=zarray, chunkmanifest=chunkmanifest) | ||
| marr = ManifestArray(metadata=metadata, chunkmanifest=chunkmanifest) | ||
| return Variable(dims=dims.keys(), data=marr, attrs=attrs, encoding=encoding) | ||
|
|
||
| def _parse_attribute(self, attr_tag: ET.Element) -> dict[str, Any]: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,6 @@ | |
| from virtualizarr.readers.hdf.filters import cfcodec_from_dataset, codecs_from_dataset | ||
| from virtualizarr.types import ChunkKey | ||
| from virtualizarr.utils import _FsspecFSFromFilepath, check_for_collisions, soft_import | ||
| from virtualizarr.zarr import ZArray | ||
|
|
||
| h5py = soft_import("h5py", "For reading hdf files", strict=False) | ||
|
|
||
|
|
@@ -285,6 +284,9 @@ def _dataset_to_variable( | |
| """ | ||
| # This chunk determination logic mirrors zarr-python's create | ||
| # https://github.com/zarr-developers/zarr-python/blob/main/zarr/creation.py#L62-L66 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this comment because I think the reference is from a previous version of zarr-python - @sharkinsspatial do you know if we can and should include an updated link? |
||
| from zarr.core.metadata.v3 import ArrayV3Metadata | ||
|
|
||
| from virtualizarr.zarr import convert_to_codec_pipeline | ||
|
|
||
| chunks = dataset.chunks if dataset.chunks else dataset.shape | ||
| codecs = codecs_from_dataset(dataset) | ||
|
|
@@ -306,20 +308,27 @@ def _dataset_to_variable( | |
| if isinstance(fill_value, np.generic): | ||
| fill_value = fill_value.item() | ||
| filters = [codec.get_config() for codec in codecs] | ||
| zarray = ZArray( | ||
| chunks=chunks, # type: ignore | ||
| compressor=None, | ||
| dtype=dtype, | ||
| fill_value=fill_value, | ||
| filters=filters, | ||
| order="C", | ||
|
|
||
| metadata = ArrayV3Metadata( | ||
| shape=dataset.shape, | ||
| zarr_format=2, | ||
| data_type=dtype, | ||
| chunk_grid={"name": "regular", "configuration": {"chunk_shape": chunks}}, | ||
| chunk_key_encoding={"name": "default"}, | ||
| fill_value=fill_value, | ||
| codecs=convert_to_codec_pipeline( | ||
| compressors=None, | ||
| dtype=dtype, | ||
| filters=filters, | ||
| serializer="auto", | ||
| ), | ||
| attributes=attrs, | ||
| dimension_names=None, | ||
| storage_transformers=None, | ||
| ) | ||
| dims = HDFVirtualBackend._dataset_dims(dataset, group=group) | ||
| manifest = HDFVirtualBackend._dataset_chunk_manifest(path, dataset) | ||
| if manifest: | ||
| marray = ManifestArray(zarray=zarray, chunkmanifest=manifest) | ||
| marray = ManifestArray(metadata=metadata, chunkmanifest=manifest) | ||
| variable = xr.Variable(data=marray, dims=dims, attrs=attrs) | ||
| else: | ||
| variable = xr.Variable(data=np.empty(dataset.shape), dims=dims, attrs=attrs) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.