zarr.api.asynchronous
zarr.api.asynchronous ¶
__all__
module-attribute
¶
__all__ = [
"array",
"consolidate_metadata",
"copy",
"copy_all",
"copy_store",
"create",
"create_array",
"create_hierarchy",
"empty",
"empty_like",
"from_array",
"full",
"full_like",
"group",
"load",
"ones",
"ones_like",
"open",
"open_array",
"open_consolidated",
"open_group",
"open_like",
"save",
"save_array",
"save_group",
"tree",
"zeros",
"zeros_like",
]
array
async
¶
Create an array filled with data.
Parameters:
-
data(array_like) –The data to fill the array with.
-
**kwargs(Any, default:{}) –Passed through to
create.
Returns:
-
array(array) –The new array.
Source code in zarr/api/asynchronous.py
consolidate_metadata
async
¶
consolidate_metadata(
store: StoreLike,
path: str | None = None,
zarr_format: ZarrFormat | None = None,
) -> AsyncGroup
Consolidate the metadata of all nodes in a hierarchy.
Upon completion, the metadata of the root node in the Zarr hierarchy will be
updated to include all the metadata of child nodes. For Stores that do
not support consolidated metadata, this operation raises a TypeError.
Parameters:
-
store(StoreLike) –The store-like object whose metadata you wish to consolidate. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
path(str, default:None) –A path to a group in the store to consolidate at. Only children below that group will be consolidated.
By default, the root node is used so all the metadata in the store is consolidated.
-
zarr_format((2, 3, None), default:2) –The zarr format of the hierarchy. By default the zarr format is inferred.
Returns:
-
group(AsyncGroup) –The group, with the
consolidated_metadatafield set to include the metadata of each child node. If the Store doesn't support consolidated metadata, this function raises aTypeError. SeeStore.supports_consolidated_metadata.
Source code in zarr/api/asynchronous.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
copy
async
¶
copy_all
async
¶
copy_store
async
¶
create
async
¶
create(
shape: tuple[int, ...] | int,
*,
chunks: tuple[int, ...] | int | bool | None = None,
dtype: ZDTypeLike | None = None,
compressor: CompressorLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
store: StoreLike | None = None,
synchronizer: Any | None = None,
overwrite: bool = False,
path: PathLike | None = None,
chunk_store: StoreLike | None = None,
filters: Iterable[dict[str, JSON] | Numcodec]
| None = None,
cache_metadata: bool | None = None,
cache_attrs: bool | None = None,
read_only: bool | None = None,
object_codec: Codec | None = None,
dimension_separator: Literal[".", "/"] | None = None,
write_empty_chunks: bool | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
chunk_shape: tuple[int, ...] | int | None = None,
chunk_key_encoding: ChunkKeyEncoding
| tuple[Literal["default"], Literal[".", "/"]]
| tuple[Literal["v2"], Literal[".", "/"]]
| None = None,
codecs: Iterable[Codec | dict[str, JSON]] | None = None,
dimension_names: DimensionNamesLike = None,
storage_options: dict[str, Any] | None = None,
config: ArrayConfigLike | None = None,
**kwargs: Any,
) -> AnyAsyncArray
Create an array.
Parameters:
-
shape(int or tuple of ints) –Array shape.
-
chunks(int or tuple of ints, default:None) –Chunk shape. If True, will be guessed from
shapeanddtype. If False, will be set toshape, i.e., single chunk for the whole array. If an int, the chunk size in each dimension will be given by the value ofchunks. Default is True. -
dtype(str or dtype, default:None) –NumPy dtype.
-
compressor(Codec, default:'auto') –Primary compressor to compress chunk data. Zarr format 2 only. Zarr format 3 arrays should use
codecsinstead.If neither
compressornorfiltersare provided, the default compressorzarr.codecs.ZstdCodecis used.If
compressoris set toNone, no compression is used. -
fill_value(Any, default:DEFAULT_FILL_VALUE) –Fill value for the array.
-
order(('C', 'F'), default:'C') –Deprecated in favor of the
configkeyword argument. Pass{'order': <value>}tocreateinstead of using this parameter. Memory layout to be used within each chunk. If not specified, thearray.orderparameter in the global config will be used. -
store(StoreLike or None, default:None) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
synchronizer(object, default:None) –Array synchronizer.
-
overwrite(bool, default:False) –If True, delete all pre-existing data in
storeatpathbefore creating the array. -
path(str, default:None) –Path under which array is stored.
-
chunk_store(StoreLike or None, default:None) –Separate storage for chunks. If not provided,
storewill be used for storage of both chunks and metadata. -
filters(Iterable[Codec] | Literal['auto'], default:None) –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array, and these values must be instances of
zarr.abc.codec.ArrayArrayCodec, or a dict representations ofzarr.abc.codec.ArrayArrayCodec.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the order of your filters is consistent with the behavior of each filter.
The default value of
"auto"instructs Zarr to use a default based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are empty. The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8orzarr.dtype.VariableLengthUTF8. In these cases, the default filters contains a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None. -
cache_metadata(bool, default:None) –If True, array configuration metadata will be cached for the lifetime of the object. If False, array metadata will be reloaded prior to all data access and modification operations (may incur overhead depending on storage and data access pattern).
-
cache_attrs(bool, default:None) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
read_only(bool, default:None) –True if array should be protected against modification.
-
object_codec(Codec, default:None) –A codec to encode object arrays, only needed if dtype=object.
-
dimension_separator(('.', '/'), default:'.') –Separator placed between the dimensions of a chunk. Zarr format 2 only. Zarr format 3 arrays should use
chunk_key_encodinginstead. -
write_empty_chunks(bool, default:None) –Deprecated in favor of the
configkeyword argument. Pass{'write_empty_chunks': <value>}tocreateinstead of using this parameter. If True, all chunks will be stored regardless of their contents. If False, each chunk is compared to the array's fill value prior to storing. If a chunk is uniformly equal to the fill value, then that chunk is not be stored, and the store entry for that chunk's key is deleted. -
zarr_format((2, 3, None), default:2) –The Zarr format to use when creating an array. The default is
None, which instructs Zarr to choose the default Zarr format value defined in the runtime configuration. -
meta_array(array - like, default:None) –Not implemented.
-
attributes(dict[str, JSON], default:None) –A dictionary of user attributes to store with the array.
-
chunk_shape(int or tuple of ints, default:None) –The shape of the Array's chunks (default is None). Zarr format 3 only. Zarr format 2 arrays should use
chunksinstead. -
chunk_key_encoding(ChunkKeyEncoding, default:None) –A specification of how the chunk keys are represented in storage. Zarr format 3 only. Zarr format 2 arrays should use
dimension_separatorinstead. Default is("default", "/"). -
codecs(Sequence of Codecs or dicts, default:None) –An iterable of Codec or dict serializations of Codecs. Zarr V3 only.
The elements of
codecsspecify the transformation from array values to stored bytes. Zarr format 3 only. Zarr format 2 arrays should usefiltersandcompressorinstead.If no codecs are provided, default codecs will be used based on the data type of the array. For most data types, the default codecs are the tuple
(BytesCodec(), ZstdCodec()); data types that require a specialzarr.abc.codec.ArrayBytesCodec, like variable-length strings or bytes, will use thezarr.abc.codec.ArrayBytesCodecrequired for the data type instead ofzarr.codecs.BytesCodec. -
dimension_names(Iterable[str | None] | None = None, default:None) –An iterable of dimension names. Zarr format 3 only.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
config(ArrayConfigLike, default:None) –Runtime configuration of the array. If provided, will override the default values from
zarr.config.array.
Returns:
-
z(array) –The array.
Source code in zarr/api/asynchronous.py
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 | |
create_array
async
¶
create_array(
store: StoreLike,
*,
name: str | None = None,
shape: ShapeLike | None = None,
dtype: ZDTypeLike | None = None,
data: ndarray[Any, dtype[Any]] | None = None,
chunks: ChunksLike | Literal["auto"] = "auto",
shards: ShardsLike | None = None,
filters: FiltersLike = "auto",
compressors: CompressorsLike = "auto",
serializer: SerializerLike = "auto",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
zarr_format: ZarrFormat | None = 3,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: DimensionNamesLike = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
write_data: bool = True,
) -> AnyAsyncArray
Create an array.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
name(str or None, default:None) –The name of the array within the store. If
nameisNone, the array will be located at the root of the store. -
shape(ShapeLike, default:None) –Shape of the array. Must be
Noneifdatais provided. -
dtype(ZDTypeLike | None, default:None) –Data type of the array. Must be
Noneifdatais provided. -
data(ndarray, default:None) –Array-like data to use for initializing the array. If this parameter is provided, the
shapeanddtypeparameters must beNone. -
chunks(tuple[int, ...] | Sequence[Sequence[int]] | Literal['auto'], default:"auto") –Chunk shape of the array. If chunks is "auto", a chunk shape is guessed based on the shape of the array and the dtype. A nested list of per-dimension edge sizes creates a rectilinear grid. Rectilinear chunk grids are experimental and must be explicitly enabled with
zarr.config.set({'array.rectilinear_chunks': True})while the feature is stabilizing. -
shards(tuple[int, ...], default:None) –Shard shape of the array. The default value of
Noneresults in no sharding at all. -
filters(Iterable[Codec] | Literal['auto'], default:'auto') –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array,
and these values must be instances of
zarr.abc.codec.ArrayArrayCodec, or a dict representations ofzarr.abc.codec.ArrayArrayCodec.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the order of your filters is consistent with the behavior of each filter.
The default value of
"auto"instructs Zarr to use a default based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are empty. The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8orzarr.dtype.VariableLengthUTF8. In these cases, the default filters contains a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None. -
compressors(Iterable[Codec], default:'auto') –List of compressors to apply to the array. Compressors are applied in order, and after any filters are applied (if any are specified) and the data is serialized into bytes.
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and returns another bytestream. Multiple compressors may be provided for Zarr format 3. If no
compressorsare provided, a default set of compressors will be used. These defaults can be changed by modifying the value ofarray.v3_default_compressorsinzarr.config. UseNoneto omit default compressors.For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr format 2. If no
compressoris provided, a default compressor will be used. inzarr.config. UseNoneto omit the default compressor. -
serializer(dict[str, JSON] | ArrayBytesCodec, default:'auto') –Array-to-bytes codec to use for encoding the array data. Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion. If no
serializeris provided, a default serializer will be used. These defaults can be changed by modifying the value ofarray.v3_default_serializerinzarr.config. -
fill_value(Any, default:DEFAULT_FILL_VALUE) –Fill value for the array.
-
order(('C', 'F'), default:"C") –The memory order of the array (default is "C"). For Zarr format 2, this parameter sets the memory order of the array. For Zarr format 3, this parameter is deprecated, because memory order is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory order for Zarr format 3 arrays is via the
configparameter, e.g.{'config': 'C'}. If noorderis provided, a default order will be used. This default can be changed by modifying the value ofarray.orderinzarr.config. -
zarr_format((2, 3), default:2) –The zarr format to use when saving.
-
attributes(dict, default:None) –Attributes for the array.
-
chunk_key_encoding(ChunkKeyEncodingLike, default:None) –A specification of how the chunk keys are represented in storage. For Zarr format 3, the default is
{"name": "default", "separator": "/"}}. For Zarr format 2, the default is{"name": "v2", "separator": "."}}. -
dimension_names(Iterable[str], default:None) –The names of the dimensions (default is None). Zarr format 3 only. Zarr format 2 arrays should not use this parameter.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
overwrite(bool, default:False) –Whether to overwrite an array with the same name in the store, if one exists. If
True, all existing paths in the store will be deleted. -
config(ArrayConfigLike, default:None) –Runtime configuration for the array.
-
write_data(bool, default:True) –If a pre-existing array-like object was provided to this function via the
dataparameter thenwrite_datadetermines whether the values in that array-like object should be written to the Zarr array created by this function. Ifwrite_dataisFalse, then the array will be left empty.
Returns:
-
AsyncArray–The array.
Examples:
>>> import asyncio
>>> import zarr
>>> asyncio.run(
... zarr.api.asynchronous.create_array(
... store={},
... shape=(100,100),
... chunks=(10,10),
... dtype="i4",
... fill_value=0
... )
... )
<AsyncArray memory://... shape=(100, 100) dtype=int32>
Source code in zarr/core/array.py
4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 | |
create_group
async
¶
create_group(
*,
store: StoreLike,
path: str | None = None,
overwrite: bool = False,
zarr_format: ZarrFormat | None = None,
attributes: dict[str, Any] | None = None,
storage_options: dict[str, Any] | None = None,
) -> AsyncGroup
Create a group.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
path(str, default:None) –Group path within store.
-
overwrite(bool, default:False) –If True, pre-existing data at
pathwill be deleted before creating the group. -
zarr_format((2, 3, None), default:2) –The zarr format to use when saving. If no
zarr_formatis provided, the default format will be used. This default can be changed by modifying the value ofdefault_zarr_formatinzarr.config. -
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
Returns:
-
AsyncGroup–The new group.
Source code in zarr/api/asynchronous.py
create_hierarchy
async
¶
create_hierarchy(
*,
store: Store,
nodes: dict[
str,
GroupMetadata | ArrayV2Metadata | ArrayV3Metadata,
],
overwrite: bool = False,
) -> AsyncIterator[tuple[str, AsyncGroup | AnyAsyncArray]]
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
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 of GroupMetadata or ArrayMetadata. Note that
all values must have the same zarr_format -- it is an error to mix zarr versions in the
same hierarchy.
Leading "/" characters from keys will be removed.
overwrite : bool
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``. If ``nodes`` defines implicit groups, e.g. ``{`'a/b/c': GroupMetadata}``, and a
group already exists at path ``a``, then this function will leave the group at ``a`` as-is.
Yields:
-
tuple[str, AsyncGroup | AsyncArray]–Yields (path, node) pairs, in the order the nodes were created.
Examples:
>>> async def example():
... from zarr.api.asynchronous import create_hierarchy
... from zarr.core.group import GroupMetadata
... from zarr.storage import MemoryStore
...
... store = MemoryStore()
... nodes = {'a': GroupMetadata(attributes={'name': 'leaf'})}
... return sorted([x async for x in create_hierarchy(store=store, nodes=nodes)])
>>> import asyncio
>>> asyncio.run(example())
[('', <AsyncGroup memory://...>), ('a', <AsyncGroup memory://.../a>)]
Source code in zarr/core/group.py
3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 | |
empty
async
¶
Create an empty array with the specified shape. The contents will be filled with the specified fill value or zeros if no fill value is provided.
Parameters:
-
shape(int or tuple of int) –Shape of the empty array.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
create.
Notes
The contents of an empty Zarr array are not defined. On attempting to retrieve data from an empty Zarr array, any values may be returned, and these are not guaranteed to be stable from one access to the next.
Source code in zarr/api/asynchronous.py
empty_like
async
¶
Create an empty array like a. The contents will be filled with the
array's fill value or zeros if no fill value is provided.
Parameters:
-
a(array - like) –The array to create an empty array like.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
create.
Returns:
-
Array–The new array.
Notes
The contents of an empty Zarr array are not defined. On attempting to retrieve data from an empty Zarr array, any values may be returned, and these are not guaranteed to be stable from one access to the next.
Source code in zarr/api/asynchronous.py
from_array
async
¶
from_array(
store: StoreLike,
*,
data: AnyArray | ArrayLike,
write_data: bool = True,
name: str | None = None,
chunks: ChunksLike | Literal["auto", "keep"] = "keep",
shards: ShardsLike | None | Literal["keep"] = "keep",
filters: FiltersLike | Literal["keep"] = "keep",
compressors: CompressorsLike | Literal["keep"] = "keep",
serializer: SerializerLike | Literal["keep"] = "keep",
fill_value: Any | None = DEFAULT_FILL_VALUE,
order: MemoryOrder | None = None,
zarr_format: ZarrFormat | None = None,
attributes: dict[str, JSON] | None = None,
chunk_key_encoding: ChunkKeyEncodingLike | None = None,
dimension_names: DimensionNamesLike = None,
storage_options: dict[str, Any] | None = None,
overwrite: bool = False,
config: ArrayConfigLike | None = None,
) -> AnyAsyncArray
Create an array from an existing array or array-like.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
data(Array | array - like) –The array to copy.
-
write_data(bool, default:True) –Whether to copy the data from the input array to the new array. If
write_dataisFalse, the new array will be created with the same metadata as the input array, but without any data. -
name(str or None, default:None) –The name of the array within the store. If
nameisNone, the array will be located at the root of the store. -
chunks(tuple[int, ...] or Sequence[Sequence[int]] or 'auto' or 'keep', default:'keep') –Chunk shape of the array. Following values are supported:
- "auto": Automatically determine the chunk shape based on the array's shape and dtype.
- "keep": Retain the chunk grid of the data array if it is a zarr Array.
- tuple[int, ...]: A tuple of integers representing the chunk shape (regular grid).
- Sequence[Sequence[int]]: Per-dimension chunk edge lists (rectilinear grid).
Rectilinear chunk grids are experimental and must be explicitly enabled
with
zarr.config.set({'array.rectilinear_chunks': True})while the feature is stabilizing.
If not specified, defaults to "keep" if data is a zarr Array, otherwise "auto".
-
shards(tuple[int, ...], default:'keep') –Shard shape of the array. Following values are supported:
- "auto": Automatically determine the shard shape based on the array's shape and chunk shape.
- "keep": Retain the shard shape of the data array if it is a zarr Array.
- tuple[int, ...]: A tuple of integers representing the shard shape.
- None: No sharding.
If not specified, defaults to "keep" if data is a zarr Array, otherwise None.
-
filters(Iterable[Codec] | Literal['auto', 'keep'], default:'keep') –Iterable of filters to apply to each chunk of the array, in order, before serializing that chunk to bytes.
For Zarr format 3, a "filter" is a codec that takes an array and returns an array, and these values must be instances of
zarr.abc.codec.ArrayArrayCodec, or a dict representations ofzarr.abc.codec.ArrayArrayCodec.For Zarr format 2, a "filter" can be any numcodecs codec; you should ensure that the order of your filters is consistent with the behavior of each filter.
The default value of
"keep"instructs Zarr to inferfiltersfromdata. If that inference is not possible, Zarr will fall back to the behavior specified by"auto", which is to choose default filters based on the data type of the array and the Zarr format specified. For all data types in Zarr V3, and most data types in Zarr V2, the default filters are the empty tuple(). The only cases where default filters are not empty is when the Zarr format is 2, and the data type is a variable-length data type likezarr.dtype.VariableLengthUTF8orzarr.dtype.VariableLengthUTF8. In these cases, the default filters is a tuple with a single element which is a codec specific to that particular data type.To create an array with no filters, provide an empty iterable or the value
None. -
compressors(Iterable[Codec] or 'auto' or 'keep', default:'keep') –List of compressors to apply to the array. Compressors are applied in order, and after any filters are applied (if any are specified) and the data is serialized into bytes.
For Zarr format 3, a "compressor" is a codec that takes a bytestream, and returns another bytestream. Multiple compressors may be provided for Zarr format 3.
For Zarr format 2, a "compressor" can be any numcodecs codec. Only a single compressor may be provided for Zarr format 2.
Following values are supported:
- Iterable[Codec]: List of compressors to apply to the array.
- "auto": Automatically determine the compressors based on the array's dtype.
- "keep": Retain the compressors of the input array if it is a zarr Array.
If no
compressorsare provided, defaults to "keep" if data is a zarr Array, otherwise "auto". -
serializer(dict[str, JSON] | ArrayBytesCodec or 'auto' or 'keep', default:'keep') –Array-to-bytes codec to use for encoding the array data. Zarr format 3 only. Zarr format 2 arrays use implicit array-to-bytes conversion.
Following values are supported:
- dict[str, JSON]: A dict representation of an
ArrayBytesCodec. - ArrayBytesCodec: An instance of
ArrayBytesCodec. - "auto": a default serializer will be used. These defaults can be changed by modifying the value of
array.v3_default_serializerinzarr.config. - "keep": Retain the serializer of the input array if it is a zarr Array.
- dict[str, JSON]: A dict representation of an
-
fill_value(Any, default:DEFAULT_FILL_VALUE) –Fill value for the array. If not specified, defaults to the fill value of the data array.
-
order(('C', 'F'), default:"C") –The memory order of the array (default is "C"). For Zarr format 2, this parameter sets the memory order of the array. For Zarr format 3, this parameter is deprecated, because memory order is a runtime parameter for Zarr format 3 arrays. The recommended way to specify the memory order for Zarr format 3 arrays is via the
configparameter, e.g.{'config': 'C'}. If not specified, defaults to the memory order of the data array. -
zarr_format((2, 3), default:2) –The zarr format to use when saving. If not specified, defaults to the zarr format of the data array.
-
attributes(dict, default:None) –Attributes for the array. If not specified, defaults to the attributes of the data array.
-
chunk_key_encoding(ChunkKeyEncoding, default:None) –A specification of how the chunk keys are represented in storage. For Zarr format 3, the default is
{"name": "default", "separator": "/"}}. For Zarr format 2, the default is{"name": "v2", "separator": "."}}. If not specified and the data array has the same zarr format as the target array, the chunk key encoding of the data array is used. -
dimension_names(Iterable[str | None] | None, default:None) –The names of the dimensions (default is None). Zarr format 3 only. Zarr format 2 arrays should not use this parameter. If not specified, defaults to the dimension names of the data array.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
overwrite(bool, default:False) –Whether to overwrite an array with the same name in the store, if one exists.
-
config(ArrayConfig or ArrayConfigLike, default:None) –Runtime configuration for the array.
Returns:
-
AsyncArray–The array.
Examples:
Create an array from an existing Array:
>>> import asyncio
>>> import zarr
>>> store = zarr.storage.LocalStore("example.zarr")
>>> arr = zarr.create_array(
... store={},
... shape=(100,100),
... chunks=(10,10),
... dtype="int32",
... fill_value=0,
... )
>>> arr2 = asyncio.run(from_array(store, data=arr, overwrite=True))
>>> arr2
<AsyncArray file://example.zarr shape=(100, 100) dtype=int32>
>>> asyncio.run(store.clear()) # Remove files generated by test
Create an array from an existing NumPy array:
>>> arr3 = asyncio.run(
... from_array({}, data=np.arange(10000, dtype="i4").reshape(100, 100))
... )
>>> arr3
<AsyncArray memory://... shape=(100, 100) dtype=int32>
Create an array from any array-like object:
>>> arr4 = asyncio.run(from_array({}, data=[[1, 2], [3, 4]]))
>>> arr4
<AsyncArray memory://... shape=(2, 2) dtype=int64>
>>> asyncio.run(arr4.getitem(...))
array([[1, 2],
[3, 4]])
Create an array from an existing Array without copying the data:
>>> arr5 = asyncio.run(from_array({}, data=Array(arr4), write_data=False))
>>> arr5
<AsyncArray memory://... shape=(2, 2) dtype=int64>
>>> asyncio.run(arr5.getitem(...))
array([[0, 0],
[0, 0]])
Source code in zarr/core/array.py
4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 | |
full
async
¶
Create an array, with fill_value being used as the default value for
uninitialized portions of the array.
Parameters:
-
shape(int or tuple of int) –Shape of the empty array.
-
fill_value(scalar) –Fill value.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
create.
Returns:
-
Array–The new array.
Source code in zarr/api/asynchronous.py
full_like
async
¶
Create a filled array like a.
Parameters:
-
a(array - like) –The array to create an empty array like.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
zarr.api.asynchronous.create.
Returns:
-
Array–The new array.
Source code in zarr/api/asynchronous.py
group
async
¶
group(
*,
store: StoreLike | None = None,
overwrite: bool = False,
chunk_store: StoreLike | None = None,
cache_attrs: bool | None = None,
synchronizer: Any | None = None,
path: str | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
storage_options: dict[str, Any] | None = None,
) -> AsyncGroup
Create a group.
Parameters:
-
store(StoreLike or None, default:None) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
overwrite(bool, default:False) –If True, delete any pre-existing data in
storeatpathbefore creating the group. -
chunk_store(StoreLike or None, default:None) –Separate storage for chunks. Not implemented.
-
cache_attrs(bool, default:None) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
synchronizer(object, default:None) –Array synchronizer.
-
path(str, default:None) –Group path within store.
-
meta_array(array - like, default:None) –An array instance to use for determining arrays to create and return to users. Use
numpy.empty(())by default. -
zarr_format((2, 3, None), default:2) –The zarr format to use when saving.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
Returns:
-
g(group) –The new group.
Source code in zarr/api/asynchronous.py
load
async
¶
load(
*,
store: StoreLike,
path: str | None = None,
zarr_format: ZarrFormat | None = None,
) -> NDArrayLikeOrScalar | dict[str, NDArrayLikeOrScalar]
Load data from an array or group into memory.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
path(str or None, default:None) –The path within the store from which to load.
Returns:
-
out–If the path contains an array, out will be a numpy array. If the path contains a group, out will be a dict-like object where keys are array names and values are numpy arrays.
See Also
save, open
Notes
If loading data from a group of arrays, data will not be immediately loaded into memory. Rather, arrays will be loaded into memory as they are requested.
Unlike open, which returns a lazy Array or
Group backed by the store, load eagerly reads the data and
returns it as an in-memory array (or a dict of arrays for a group).
The array type is NumPy by default, but follows the configured
buffer prototype (for example, CuPy for GPU use cases).
Use open when you want to read or write data incrementally without loading it
all into memory.
Source code in zarr/api/asynchronous.py
ones
async
¶
Create an array, with one being used as the default value for uninitialized portions of the array.
Parameters:
-
shape(int or tuple of int) –Shape of the empty array.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
zarr.api.asynchronous.create.
Returns:
-
Array–The new array.
Source code in zarr/api/asynchronous.py
ones_like
async
¶
Create an array of ones like a.
Parameters:
-
a(array - like) –The array to create an empty array like.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
zarr.api.asynchronous.create.
Returns:
-
Array–The new array.
Source code in zarr/api/asynchronous.py
open
async
¶
open(
*,
store: StoreLike | None = None,
mode: AccessModeLiteral | None = None,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> AnyAsyncArray | AsyncGroup
Convenience function to open a group or array using file-mode-like semantics.
Parameters:
-
store(StoreLike or None, default:None) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
mode(('r', 'r+', 'a', 'w', 'w-'), default:'r') –Persistence mode: 'r' means read only (must exist); 'r+' means read/write (must exist); 'a' means read/write (create if doesn't exist); 'w' means create (overwrite if exists); 'w-' means create (fail if exists). If the store is read-only, the default is 'r'; otherwise, it is 'a'.
-
zarr_format((2, 3, None), default:2) –The zarr format to use when saving.
-
path(str or None, default:None) –The path within the store to open.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs(Any, default:{}) –Additional parameters are passed through to
zarr.open_arrayorzarr.open_group.
Returns:
See Also
load
Notes
open returns a lazy Array or Group backed by
the store, so data is read and written incrementally. Use load
instead when you want the data eagerly read into an in-memory array (a
NumPy array by default).
Source code in zarr/api/asynchronous.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
open_array
async
¶
open_array(
*,
store: StoreLike | None = None,
zarr_format: ZarrFormat | None = None,
path: PathLike = "",
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> AnyAsyncArray
Open an array using file-mode-like semantics.
Parameters:
-
store(StoreLike, default:None) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
zarr_format((2, 3, None), default:2) –The zarr format to use when saving.
-
path(str, default:'') –Path in store to array.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs(Any, default:{}) –Any keyword arguments to pass to
create.
Returns:
-
AsyncArray–The opened array.
Source code in zarr/api/asynchronous.py
open_consolidated
async
¶
open_consolidated(
*args: Any,
use_consolidated: Literal[True] = True,
**kwargs: Any,
) -> AsyncGroup
Alias for open_group with use_consolidated=True.
Source code in zarr/api/asynchronous.py
open_group
async
¶
open_group(
store: StoreLike | None = None,
*,
mode: AccessModeLiteral = "a",
cache_attrs: bool | None = None,
synchronizer: Any = None,
path: str | None = None,
chunk_store: StoreLike | None = None,
storage_options: dict[str, Any] | None = None,
zarr_format: ZarrFormat | None = None,
meta_array: Any | None = None,
attributes: dict[str, JSON] | None = None,
use_consolidated: bool | str | None = None,
) -> AsyncGroup
Open a group using file-mode-like semantics.
Parameters:
-
store(StoreLike or None, default:None) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
mode(('r', 'r+', 'a', 'w', 'w-'), default:'r') –Persistence mode: 'r' means read only (must exist); 'r+' means read/write (must exist); 'a' means read/write (create if doesn't exist); 'w' means create (overwrite if exists); 'w-' means create (fail if exists).
-
cache_attrs(bool, default:None) –If True (default), user attributes will be cached for attribute read operations. If False, user attributes are reloaded from the store prior to all attribute read operations.
-
synchronizer(object, default:None) –Array synchronizer.
-
path(str, default:None) –Group path within store.
-
chunk_store(StoreLike or None, default:None) –Separate storage for chunks. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
meta_array(array - like, default:None) –An array instance to use for determining arrays to create and return to users. Use
numpy.empty(())by default. -
attributes(dict, default:None) –A dictionary of JSON-serializable values with user-defined attributes.
-
use_consolidated(bool or str, default:None) –Whether to use consolidated metadata.
By default, consolidated metadata is used if it's present in the store (in the
zarr.jsonfor Zarr format 3 and in the.zmetadatafile for Zarr format 2).To explicitly require consolidated metadata, set
use_consolidated=True, which will raise an exception if consolidated metadata is not found.To explicitly not use consolidated metadata, set
use_consolidated=False, which will fall back to using the regular, non consolidated metadata.Zarr format 2 allowed configuring the key storing the consolidated metadata (
.zmetadataby default). Specify the custom key asuse_consolidatedto load consolidated metadata from a non-default key.
Returns:
-
g(group) –The new group.
Source code in zarr/api/asynchronous.py
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | |
open_like
async
¶
Open a persistent array like a.
Parameters:
-
a(Array) –The shape and data-type of a define these same attributes of the returned array.
-
path(str) –The path to the new array.
-
**kwargs(Any, default:{}) –Additional keyword arguments passed to
open_array. Ifmodeis omitted orNone, it defaults to"a". Passmode="r"when opening an existing array from a read-only store.
Returns:
-
AsyncArray–The opened array.
Source code in zarr/api/asynchronous.py
save
async
¶
save(
store: StoreLike,
*args: NDArrayLike,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
**kwargs: Any,
) -> None
Convenience function to save an array or group of arrays to the local file system.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
*args(ndarray, default:()) –NumPy arrays with data to save.
-
zarr_format((2, 3, None), default:2) –The zarr format to use when saving.
-
path(str or None, default:None) –The path within the group where the arrays will be saved.
-
**kwargs(Any, default:{}) –NumPy arrays with data to save.
Source code in zarr/api/asynchronous.py
save_array
async
¶
save_array(
store: StoreLike,
arr: NDArrayLike,
*,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
storage_options: dict[str, Any] | None = None,
**kwargs: Any,
) -> None
Convenience function to save a NumPy array to the local file system, following a similar API to the NumPy save() function.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
arr(ndarray) –NumPy array with data to save.
-
zarr_format((2, 3, None), default:2) –The zarr format to use when saving. The default is
None, which will use the default Zarr format defined in the global configuration object. -
path(str or None, default:None) –The path within the store where the array will be saved.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs(Any, default:{}) –Passed through to
create, e.g., compressor.
Source code in zarr/api/asynchronous.py
save_group
async
¶
save_group(
store: StoreLike,
*args: NDArrayLike,
zarr_format: ZarrFormat | None = None,
path: str | None = None,
storage_options: dict[str, Any] | None = None,
**kwargs: NDArrayLike,
) -> None
Convenience function to save several NumPy arrays to the local file system, following a similar API to the NumPy savez()/savez_compressed() functions.
Parameters:
-
store(StoreLike) –StoreLike object to open. See the storage documentation in the user guide for a description of all valid StoreLike values.
-
*args(ndarray, default:()) –NumPy arrays with data to save.
-
zarr_format((2, 3, None), default:2) –The zarr format to use when saving.
-
path(str or None, default:None) –Path within the store where the group will be saved.
-
storage_options(dict, default:None) –If using an fsspec URL to create the store, these will be passed to the backend implementation. Ignored otherwise.
-
**kwargs(NDArrayLike, default:{}) –NumPy arrays with data to save.
Source code in zarr/api/asynchronous.py
tree
async
¶
tree(
grp: AsyncGroup,
expand: bool | None = None,
level: int | None = None,
) -> Any
Provide a rich display of the hierarchy.
Deprecated
zarr.tree() is deprecated since v3.0.0 and will be removed in a future release.
Use group.tree() instead.
Parameters:
-
grp(Group) –Zarr or h5py group.
-
expand(bool, default:None) –Only relevant for HTML representation. If True, tree will be fully expanded.
-
level(int, default:None) –Maximum depth to descend into hierarchy.
Returns:
-
TreeRepr–A pretty-printable object displaying the hierarchy.
Source code in zarr/api/asynchronous.py
zeros
async
¶
Create an array, with zero being used as the default value for uninitialized portions of the array.
Parameters:
-
shape(int or tuple of int) –Shape of the empty array.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
zarr.api.asynchronous.create.
Returns:
-
Array–The new array.
Source code in zarr/api/asynchronous.py
zeros_like
async
¶
Create an array of zeros like a.
Parameters:
-
a(array - like) –The array to create an empty array like.
-
**kwargs(Any, default:{}) –Keyword arguments passed to
create.
Returns:
-
Array–The new array.