zarr.create_hierarchy
zarr.create_hierarchy ¶
create_hierarchy(
*,
store: Store,
nodes: dict[
str,
GroupMetadata | ArrayV2Metadata | ArrayV3Metadata,
],
overwrite: bool = False,
) -> Iterator[tuple[str, Group | AnyArray]]
Create a complete zarr hierarchy from a collection of metadata objects.
This function will parse its input to ensure that the hierarchy is complete. Any implicit groups
will be inserted as needed. For example, an input like
{'a/b': GroupMetadata} will be parsed to
{'': GroupMetadata, 'a': GroupMetadata, 'b': Groupmetadata}
After input parsing, this function then creates all the nodes in the hierarchy concurrently.
Arrays and Groups are yielded in the order they are created. This order is not stable and should not be relied on.
Parameters:
-
store(Store) –The storage backend to use.
-
nodes(dict[str, GroupMetadata | ArrayV3Metadata | ArrayV2Metadata]) –A dictionary defining the hierarchy. The keys are the paths of the nodes in the hierarchy, relative to the root of the
Store. The root of the store can be specified with the empty string''. The values are instances ofGroupMetadataorArrayMetadata. Note that all values must have the samezarr_format-- it is an error to mix zarr versions in the same hierarchy.Leading "/" characters from keys will be removed.
-
overwrite(bool, default:False) –Whether to overwrite existing nodes. Defaults to
False, in which case an error is raised instead of overwriting an existing array or group.This function will not erase an existing group unless that group is explicitly named in
nodes. Ifnodesdefines implicit groups, e.g.{`'a/b/c': GroupMetadata}, and a group already exists at patha, then this function will leave the group ataas-is.
Yields:
-
tuple[str, Group | Array]–This function yields (path, node) pairs, in the order the nodes were created.
Examples:
from zarr import create_hierarchy
from zarr.storage import MemoryStore
from zarr.core.group import GroupMetadata
store = MemoryStore()
nodes = {'a': GroupMetadata(attributes={'name': 'leaf'})}
nodes_created = dict(create_hierarchy(store=store, nodes=nodes))
print(nodes)
# {'a': GroupMetadata(attributes={'name': 'leaf'}, zarr_format=3, consolidated_metadata=None, node_type='group')}