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
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 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 | |
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 the order if your filters is consistent with the behavior of each filter.
The default value of
"auto"instructs Zarr to use a default used 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
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 881 882 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 | |
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 the order if your filters is consistent with the behavior of each filter.
The default value of
"auto"instructs Zarr to use a default used 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 my 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 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 zarr
>>> store = zarr.storage.MemoryStore(mode='w')
>>> async_arr = await zarr.api.asynchronous.create_array(
>>> store=store,
>>> shape=(100,100),
>>> chunks=(10,10),
>>> dtype='i4',
>>> fill_value=0)
<AsyncArray memory://140349042942400 shape=(100, 100) dtype=int32>
Source code in zarr/core/array.py
4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 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 | |
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]–This function yields (path, node) pairs, in the order the nodes were created.
Examples:
>>> from zarr.api.asynchronous import create_hierarchy
>>> from zarr.storage import MemoryStore
>>> from zarr.core.group import GroupMetadata
>>> import asyncio
>>> store = MemoryStore()
>>> nodes = {'a': GroupMetadata(attributes={'name': 'leaf'})}
>>> async def run():
... print(dict([x async for x in create_hierarchy(store=store, nodes=nodes)]))
>>> asyncio.run(run())
# {'a': <AsyncGroup memory://140345143770112/a>, '': <AsyncGroup memory://140345143770112>}
Source code in zarr/core/group.py
2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 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 | |
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 the order if 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 my 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 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 zarr
>>> store = zarr.storage.MemoryStore()
>>> store2 = zarr.storage.LocalStore('example.zarr')
>>> arr = zarr.create_array(
>>> store=store,
>>> shape=(100,100),
>>> chunks=(10,10),
>>> dtype='int32',
>>> fill_value=0)
>>> arr2 = await zarr.api.asynchronous.from_array(store2, data=arr)
<AsyncArray file://example.zarr shape=(100, 100) dtype=int32>
Create an array from an existing NumPy array::
>>> arr3 = await zarr.api.asynchronous.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=np.arange(10000, dtype='i4').reshape(100, 100),
>>> )
<AsyncArray memory://123286956732800 shape=(100, 100) dtype=int32>
Create an array from any array-like object::
>>> arr4 = await zarr.api.asynchronous.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=[[1, 2], [3, 4]],
>>> )
<AsyncArray memory://123286959761024 shape=(2, 2) dtype=int64>
>>> await arr4.getitem(...)
array([[1, 2],[3, 4]])
Create an array from an existing Array without copying the data::
>>> arr5 = await zarr.api.asynchronous.from_array(
>>> zarr.storage.MemoryStore(),
>>> data=Array(arr4),
>>> write_data=False,
>>> )
<AsyncArray memory://140678602965568 shape=(2, 2) dtype=int64>
>>> await arr5.getitem(...)
array([[0, 0],[0, 0]])
Source code in zarr/core/array.py
4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 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 | |
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
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.
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:
Source code in zarr/api/asynchronous.py
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
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 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 | |
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:{}) –Any keyword arguments to pass to the array constructor.
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.